volatile uint32_t inputFreq, inputFreq2;
char Variablestr [10]; //when the variable is between 0 and 1024 make sure this number is 4 or higher!
char Variablestr2 [10];
void EnableCounter(void)
{
LPC_SC->PCONP |= 1 << 2; //Power up TimerCounter1
LPC_TIM1->TCR |= 1 << 0; // Counter mode
LPC_TIM1->CTCR |= 3; // Count on both edges
LPC_TIM1->CTCR |= 1 << 2; // CAP1.1 is the input pin for which the input signal needs to be connected.
LPC_PINCON->PINSEL3 |= ((1 << 7)| (1 << 6)); // Make P1.19 as CAP1.1
LPC_TIM1->TCR = 0x1; // Enable counter
}
void EnableTimer(void)
{
LPC_SC->PCONP |= 1 < 1; //timer0 power on
LPC_TIM0->MR0 = 12499999; //1sec
LPC_TIM0->MCR = 3; //interrupt and reset control
//3 = Interrupt & reset timer0 on match
//1 = Interrupt only, no reset of timer0
NVIC_EnableIRQ(TIMER0_IRQn); //enable timer0 interrupt
LPC_TIM0->TCR = 1; //enable Timer0
lcdDrawText(20,60,"start_timer",LCDRed);
}
void TIMER0_IRQHandler (void)
{
if((LPC_TIM0->IR & 0x01) == 0x01) // if MR0 interrupt
{
LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag
inputFreq = LPC_TIM1->TC; // Read the counter value
inputFreq2 = LPC_TIM0->TC;
lcdClear(LCDBlack);
snprintf(Variablestr, 10,"%d",inputFreq);
lcdDrawText(100,250,Variablestr,LCDWhite);
snprintf(Variablestr2, 10,"%d",inputFreq2);
lcdDrawText(100,200,Variablestr2,LCDYellow);
LPC_TIM1->TCR |= 1 << 1 ; // Reset the counter
}
}
int main (void)
{
EnableCounter();
EnableTimer();
while (1)
{
}
}
|
while(1)
{
asm("wfi");/* wait until any interrupt occurred, in some cases the above mentioned timer */
...
/* your lcd code here */
} |