Hi all I'm a newbie in LPC2148 programming.I'm doing a simple blink and wait programming
with the waiting phase between each blink to be 1sec.But inspite of my all efforts the
result is not coming as expected.I'm posting below my code.Plz help me someone.The code is
well documented..i hope there will be no problem in understanding it.Thanks in
advance---
/* My primary aim is to blink the LEDs connected to pin1.16-pin1.23 in a pattern
00000000,00000001,00000010...
and so on with an interval of 1sec between each blinking.Thus measuring 60seconds i.e,
1min.*/
#include "LPC214x.H"
/* Fosc = external supplied crystal frequency
Fcclk = Processor clock or o/p of PLL0
Pclk = The VPB clock frquency.The o/p of the VPB driver
Fcco = the frequency of the PLL current controlled oscillator */
void init_clock()
{
PLL0CON=0x0; // the PLL is nt connected as the clock source for the processor
PLL0FEED=0xAA;
PLL0FEED=0x55;
VPBDIV=0x01; // the VPB clock is same as that of the processor clock.
MAMCR = 0x00; // Any MAM function is disabled.
}
/* This is the delay block where the timer0 register are configuered to count upto a
certain
value so that 1sec delay is produced.After each such case the timer block is
deactivated
and agin when the delay() function will be called 0it will be activated and configuered
to
produce 1sec delay.
the prescaler register is set to have the value 9999(=0x270F),so that the TC register
is
increased after every 10000 clock cycles.So it should count upto 1200(=0x4B0) for
1sec delay since the supply is 12MHz i.e., 12,000,000 clocks per second.Hence I have
put
the value 1200MHz(=0x4B0) in MR0,which is compared with the TC and as soon as the
match
happens the Timer counter is being reset..and along with the timer block is
deactivated.
*/
void delay()
{
unsigned long check_value = 0x000004B0;
T0PR = 0x0000270F;
T0MR0 = 0x000004B0 ;
T0TCR = 0x01; // the timer0 is activated
while(T0TC != T0MR0);
T0MCR = 0x00000002; // Timer Counter will be in reset condition if the match between the
MR0 and TC happens.
T0TCR = 0x02; /* when the match happens the Timer0 is resetted and deactivated and it
is
again activated while the next delay is called */
}
void main(void)
{
unsigned long count,dword=0x00000000;
unsigned char min_hand=0;
init_clock();
PINSEL1 &= 0x00000000; // all the pins of port1 are selected as GPIO
IODIR1 = 0x00FF0000; // the pin 16 to 23 are configuered as the output pins.
IOCLR1 = 0xFFFFFFFF;
while(1)
{
min_hand++;
dword++;
count = dword;
IOSET1 |= (dword<<16);
dword = count;
delay();
if(min_hand > 60)
{
min_hand=0;
delay();
}
IOCLR1 = 0xFFFFFFFF;
delay();
}
}
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )