0
여기 내 코드입니다. 컴파일 할 때 "예상 된 식별자"오류가 있습니다. Timer2 초기화를 어떻게 포맷했는지와 관련이 있다고 생각합니다.MBed 라이브러리 만들기, "식별자가 필요합니다"
이 코드를 컴파일하려면 무엇을 변경해야합니까?
감사합니다.
필요한 경우 헤더 파일을 추가 할 수 있습니다.
#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}
}
}
예. 문제가 있습니다. 지금 컴파일 중입니다. 감사 – ayeomans