We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi Everyone. I had done code for timer0 in LPC2148 to increment a no. for every sec. But while executing it increments for every 10 sec. I dont know what went wrong. Someone pls help. Thanx in advance. Clock Freq: 12Mhz.
#include<lpc214x.h> #include"lcd.h" #define PCLK 12000000 void init(void); void lcd_init(void); void gpio_init(void); void timer0_init(void); void timer0_int_init(void); __irq void Timer0(void); unsigned int x, cnt; int main() { init(); lcd_init(); gpio_init(); timer0_int_init(); read(0x80); lcd_dis("TIMER0 TEST PRGM", 16); timer0_init(); while(1) { read(0xc0); hex_dec2(x); } } void gpio_init() { PINSEL0 = 0x00000000; PINSEL1 = 0x00000000; IODIR0 = 0xFFFFFFFF; } void timer0_init() { PCONP |= (1<<1);// Enable Power control for Timer0 T0CTCR= 0x00; // Set Timer mode T0PR = 0x2EDF; // Set Prescale to 11999 to get 1msec delay T0TCR = 0x02; // Reset Timer0 T0MR0 = 0x3E8; // Match reg value for 1sec delay T0MCR = 0x03; // Enable interrupt and resets TC when match occurs T0TCR = 0x01; // Enable Timer0 } void init(void) { PLL0CFG = 0x00; // MSEL = 1,PSEL = 1 PLL0FEED = 0xAA; // Feed process PLL0FEED = 0x55; PLL0CON = 0x01; PLL0FEED = 0xAA; // Feed process PLL0FEED = 0x55; while(!(PLL0STAT & 0x400)); // Wait until PLL Locked PLL0CON = 0x3; // Connect the PLL as the clock source PLL0FEED = 0xAA; // Feed process PLL0FEED = 0x55; MAMCR = 0x2; // Enabling MAM and setting number of clocks used for Flash memory fetch (4 cclks in this case) MAMTIM = 0x4; VPBDIV = 0x01; // PCLK = CCLK } void timer0_int_init(void) { VICVectAddr0 = (unsigned)Timer0; VICVectCntl0 = 0x20|4; VICIntEnable |= (1<<4); } __irq void Timer0(void) { T0IR=0x01; VICVectAddr=0x0; x++; }