karthik chandra
Newbie level 5
im calculating delay for 1sec using timer 0, but im getting delay of 500ms
im using 12Mhz external crystal
im using 12Mhz external crystal
Code:
#include "lpc17xx.h"
void delayMs(uint32_t delayInMs)
{
LPC_TIM0->TCR = 0x02; /* reset timer */
LPC_TIM0->PR = 0x00; /* set prescaler to zero */
LPC_TIM0->MR0 = delayInMs * (9000000 / 1000-1);
LPC_TIM0->IR = 0xff; /* reset all interrupts */
LPC_TIM0->MCR = 0x04; /* stop timer on match */
LPC_TIM0->TCR = 0x01; /* start timer */
/* wait until delay time has elapsed */
while (LPC_TIM0->TCR & 0x01);
}
int main(void)
{
SystemInit();
LPC_GPIO0->FIODIR |= 0x00000010;
while(1)
{
LPC_GPIO0->FIOSET |= 0x00000010;
delayMs(1000);
LPC_GPIO0->FIOCLR |= 0x00000010;
delayMs(1000);
}
}