[ARM] lpc2148 timer pgm is not working

Status
Not open for further replies.

rajslr

Newbie level 1
Joined
May 20, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
5
hi frnds....... here i am posting my code to generate 1s delay using timer 0 in lpc2148.


link to learn 8051

Fosc=12Mhz
CCLK=60Mhz
PCLK=60Mhz


but this code is not generating desired delay

so correct my code.... thank u :thumbsup:

Code:
#include<lpc214x.h>

void timer_init();
void delay(unsigned int a);
void pll();

int main()
{
IODIR0|=0XFFFFFFFF;			 //port 0 is output
pll();
timer_init();

while(1)
{
IOSET0|=0xFFFFFFFF;
delay(1000);			 //1s delay
IOCLR0|=0XFFFFFFFF;
delay(1000);			 //1s delay
}
}

void delay(unsigned int a)
{
unsigned int s;
T0TCR=0X01;				 //enable timer
for(s=0;s<a;s++)
{
while(T0TC!=T0MR0);		 //wait until tc matches to match reg0
}
T0TCR=0X00;				 //stop the timer
}

void pll()				//Fosc=12Mhz,CCLK=60Mhz,PCLK=60MHz
{
PLL0CON=0x01;
PLL0CFG=0x24;
PLL0FEED=0xaa;
PLL0FEED=0x55;
while(!(PLL0STAT&(1<<10)));
PLL0CON=0x03;
PLL0FEED=0xaa;
PLL0FEED=0x55;
VPBDIV=0x01;
}

void timer_init()
{
T0CTCR=0X00;			 //act as a timer
T0PR=0;					 //prescale reg value is 0
T0MR0=59999;			 //match reg0 value is 59999 i.e. { [(60Mhz) * (1 milli sec)]-1 }
T0MCR=0x02;				 //match on reset tc
T0TCR=0X02;				 //reset tc and pc
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…