C++ 正在创建MBed库,错误“;需要一个标识符“;
这是我的密码。当我试图编译它时,出现了一个错误“需要一个标识符”,我相信这与我如何格式化Timer2初始化有关 我需要修改什么才能编译这段代码 非常感谢 如果需要,我可以添加头文件C++ 正在创建MBed库,错误“;需要一个标识符“;,c++,c,mbed,C++,C,Mbed,这是我的密码。当我试图编译它时,出现了一个错误“需要一个标识符”,我相信这与我如何格式化Timer2初始化有关 我需要修改什么才能编译这段代码 非常感谢 如果需要,我可以添加头文件 #include "Timer2.h" #include "LPC17xx.h" unsigned int _presc; Timer2::Timer2(unsigned long pres, ClockType cs) : { power(1); prescale(pres); sel
#include "Timer2.h"
#include "LPC17xx.h"
unsigned int _presc;
Timer2::Timer2(unsigned long pres, ClockType cs) :
{
power(1);
prescale(pres);
selectClock(cs);
}
Timer2::~Timer2()
{
power(0);
}
void Timer2::prescale(unsigned int p)
{
_presc = p-1;
LPC_TIM2->PR = _presc;
}
unsigned long Timer2::getPrescale()
{
return _presc;
}
void Timer2::capture0(ChangeType change, bool interrupt)
{
LPC_PINCON->PINSEL0 |= (0x3<<8); //setup CAP2:0 on pin P0.4 DIP 30
if ( change == rising) {
LPC_TIM2->CCR |= 0x1;
LPC_TIM2->CCR |= 0x0<<1;
} else if ( change == falling) {
LPC_TIM2->CCR |= 0x0;
LPC_TIM2->CCR |= 0x1<<1;
} else if( change == changing) {
LPC_TIM2->CCR |= 0x1;
LPC_TIM2->CCR |= 0x1<<1;
}
if (interrupt == true) {
LPC_TIM2->CCR |= 0x1<<2;
}
}
void Timer2::capture1(ChangeType change, bool interrupt)
{
LPC_PINCON->PINSEL0 |= (0x3<<10); //setup CAP2:1 on pin P0.5 DIP 29
if ( change == rising) {
LPC_TIM2->CCR |= 0x1<<3;
LPC_TIM2->CCR |= 0x0<<4;
} else if ( change == falling) {
LPC_TIM2->CCR |= 0x0<<3;
LPC_TIM2->CCR |= 0x1<<4;
} else if( change == changing) {
LPC_TIM2->CCR |= 0x1<<3;
LPC_TIM2->CCR |= 0x1<<4;
}
if (interrupt == true) {
LPC_TIM2->CCR |= 0x1<<5;
}
}
void Timer2::capture0Stop()
{
LPC_PINCON->PINSEL0 |= (0x0<<8); //stop CAP2:0
LPC_PINCON->PINSEL0 |= (0x0<<7);
}
void Timer2::capture1Stop()
{
LPC_PINCON->PINSEL0 |= (0x0<<10); //stop CAP2:1
LPC_PINCON->PINSEL0 |= (0x0<<9);
}
unsigned long Timer2::time_us()
{
return _presc * LPC_TIM2->TC /96.0;
}
void Timer2::start()
{
LPC_TIM2->TCR |= 0x0<<1;
LPC_TIM2->TCR |= 0x1<<0;
}
void Timer2::stop()
{
LPC_TIM2->TCR |= 0x0<<1;
LPC_TIM2->TCR |= 0x0<<0;
}
void Timer2::reset()
{
LPC_TIM2->TCR |= 0x1<<1;
}
void Timer2::match0(unsigned long value, bool stop, bool interrupt, bool reset, MatchAction action = nothing)
{
if (action == nothing) {
LPC_PINCON->PINSEL0 |= (0x0<<12); //Select pin p0.6 (p8)
LPC_PINCON->PINSEL0 |= (0x0<<11); //Select pin p0.6 (p8)
} else if (action == set0) {
LPC_PINCON->PINSEL0 |= (0x3<<12); //Select pin p0.6 (p8)
LPC_TIM2->EMR |= 0x2<<5; //Set pin low
} else if (action == set1) {
LPC_PINCON->PINSEL0 |= (0x3<<12); //Select pin p0.6 (p8)
LPC_TIM2->EMR |= 0x1<<5; //Set pin high
} else if (action == toggle) {
LPC_PINCON->PINSEL0 |= (0x3<<12); //Select pin p0.6 (p8)
LPC_TIM2->EMR |= 0x3<<5; //Toggle pin
}
LPC_PINCON->PINSEL0 |= (0x3<<12); //Select pin p0.6 (p8)
LPC_TIM2->MR0 = value;
LPC_TIM2->MCR |= 0x0<<0;
LPC_TIM2->MCR |= 0x0<<1;
LPC_TIM2->MCR |= 0x0<<2;
if (interrupt == true) {
LPC_TIM2->MCR |= 0x1<<0;
}
if (reset == true) {
LPC_TIM2->MCR |= 0x1<<1;
}
if (stop == true) {
LPC_TIM2->MCR |= 0x1<<2;
}
}
void Timer2::match1(unsigned long value, bool stop, bool interrupt, bool reset, MatchAction action = nothing)
{
if (action == nothing) {
LPC_PINCON->PINSEL0 |= (0x0<<14); //Select pin p0.7 (p7)
LPC_PINCON->PINSEL0 |= (0x0<<13); //Select pin p0.7 (p7)
} else if (action == set0) {
LPC_PINCON->PINSEL0 |= (0x3<<14); //Select pin p0.7 (p7)
LPC_TIM2->EMR |= 0x2<<7; //Set pin low
} else if (action == set1) {
LPC_PINCON->PINSEL0 |= (0x3<<14); //Select pin p0.7 (p7)
LPC_TIM2->EMR |= 0x1<<7; //Set pin high
} else if (action == toggle) {
LPC_PINCON->PINSEL0 |= (0x3<<14); //Select pin p0.7 (p7)
LPC_TIM2->EMR |= 0x3<<7; //Toggle pin
}
LPC_TIM2->MR1 = value;
LPC_TIM2->MCR |= 0x0<<3;
LPC_TIM2->MCR |= 0x0<<4;
LPC_TIM2->MCR |= 0x0<<5;
if (interrupt == true) {
LPC_TIM2->MCR |= 0x1<<3;
}
if (reset == true) {
LPC_TIM2->MCR |= 0x1<<4;
}
if (stop == true) {
LPC_TIM2->MCR |= 0x1<<5;
}
}
void Timer2::match2(unsigned long value, bool stop, bool interrupt, bool reset, MatchAction action = nothing)
{
if (action == nothing) {
LPC_PINCON->PINSEL0 |= (0x0<<16); //Select pin p0.8 (p6)
LPC_PINCON->PINSEL0 |= (0x0<<15); //Select pin p0.8 (p6)
} else if (action == set0) {
LPC_PINCON->PINSEL0 |= (0x3<<16); //Select pin p0.8 (p6)
LPC_TIM2->EMR |= 0x2<<9; //Set pin low
} else if (action == set1) {
LPC_PINCON->PINSEL0 |= (0x3<<16); //Select pin p0.8 (p6)
LPC_TIM2->EMR |= 0x1<<9; //Set pin high
} else if (action == toggle) {
LPC_PINCON->PINSEL0 |= (0x3<<16); //Select pin p0.8 (p6)
LPC_TIM2->EMR |= 0x4<<9; //Toggle pin
}
LPC_TIM2->MR2 = value;
LPC_TIM2->MCR |= 0x0<<6;
LPC_TIM2->MCR |= 0x0<<7;
LPC_TIM2->MCR |= 0x0<<8;
if (interrupt == true) {
LPC_TIM2->MCR |= 0x1<<6;
}
if (reset == true) {
LPC_TIM2->MCR |= 0x1<<7;
}
if (stop == true) {
LPC_TIM2->MCR |= 0x1<<8;
}
}
void Timer2::match3(unsigned long value, bool stop, bool interrupt, bool reset, MatchAction action = nothing)
{
if (action == nothing) {
LPC_PINCON->PINSEL0 |= (0x0<<18); //Select pin p0.9 (p5)
LPC_PINCON->PINSEL0 |= (0x0<<17); //Select pin p0.9 (p5)
} else if (action == set0) {
LPC_PINCON->PINSEL0 |= (0x3<<18); //Select pin p0.9 (p5)
LPC_TIM2->EMR |= 0x2<<11; //Set pin low
} else if (action == set1) {
LPC_PINCON->PINSEL0 |= (0x3<<18); //Select pin p0.9 (p5)
LPC_TIM2->EMR |= 0x1<<11; //Set pin high
} else if (action == toggle) {
LPC_PINCON->PINSEL0 |= (0x3<<18); //Select pin p0.9 (p5)
LPC_TIM2->EMR |= 0x3<<11; //Toggle pin
}
LPC_TIM2->MR3 = value;
LPC_TIM2->MCR |= 0x0<<9;
LPC_TIM2->MCR |= 0x0<<10;
LPC_TIM2->MCR |= 0x0<<11;
if (interrupt == true) {
LPC_TIM2->MCR |= 0x1<<9;
}
if (reset == true) {
LPC_TIM2->MCR |= 0x1<<10;
}
if (stop == true) {
LPC_TIM2->MCR |= 0x1<<11;
}
}
void Timer2::clockReset(unsigned long time, PinName match = p5)
{
unsigned long t = time * 96.0;
if (match == p5) {
match3(t,0,1,1);
} else if (match == p6) {
match2(t,0,1,1);
} else if (match == p7) {
match1(t,0,1,1);
} else if (match == p8) {
match0(t,0,1,1);
}
}
void Timer2::selectClock(ClockType clock)
{
if (clock == Clock) {
LPC_SC->PCLKSEL1 |=0x1<<12; //PCLK_peripheral set to Clock
LPC_SC->PCLKSEL1 |=0x0<<13;
} else if (clock == HalfClock) {
LPC_SC->PCLKSEL1 |=0x0<<12; //PCLK_peripheral set to Clock/2
LPC_SC->PCLKSEL1 |=0x1<<13;
} else if (clock == QuarterClock) {
LPC_SC->PCLKSEL1 |=0x0<<12; //PCLK_peripheral set to Clock/4
LPC_SC->PCLKSEL1 |=0x0<<13;
} else if (clock == EighthClock) {
LPC_SC->PCLKSEL1 |=0x1<<12; //PCLK_peripheral set to Clock/8
LPC_SC->PCLKSEL1 |=0x1<<13;
}
}
void Timer2::power(bool on)
{
if (on == true) {
LPC_SC->PCONP |=0x1<22; //timer2 power on
} else {
LPC_SC->PCONP |=0x0<22; //timer2 power off}
}
}
#包括“Timer2.h”
#包括“LPC17xx.h”
无符号整数预编码;
Timer2::Timer2(无符号长脉冲,时钟类型cs):
{
电源(1);
预分级(pres);
选择时钟(cs);
}
Timer2::~Timer2()
{
功率(0);
}
void Timer2::预缩放(无符号整数p)
{
_PREC=p-1;
LPC\u TIM2->PR=\u PREC;
}
未签名的长时间R2::getPrescale()
{
返回_presc;
}
无效时间2::capture0(更改类型更改,布尔中断)
{
LPC_PINCON->PINSEL0 |=(0x3CCR |=0x0CCR |=0x1CCR |=0x1您的Timer2构造函数有一个rogue:
,当您有初始化列表时(即调用基类构造函数或设置类成员的值时)使用该构造函数。由于列表中没有标识符,因此出现错误。请删除冒号,它应该可以工作。是的,这就是问题所在。它正在编译。谢谢