LPC21xx programming in Keil

Thread Starter

rushabh0013

Joined Jan 27, 2010
2
hello friends.. it seems there is no thread related to ARM7 (LPC21xx) related programming... so i have created one... m learning ARM7 and thought others will be interested...

I want to generate 1sec delay using timer0.
I have written code in C in Keil for LPC2138 but it doesnt generate exact delay. If anyone find out my mistakes it will be grateful...here is the code..

/*------------------------------------------------------------
Program for Multiplexed 7Segment using Timers with ARM LPC2138
Fosc=14.7658Mhz
Common Cathode 7 Seg is used.
--------------------------------------------------------------*/

#include <LPC213x.h>
#define delay 1

void wait(unsigned int a)
{

unsigned int d;
for(d=0;d<a;d++);
{
VPBDIV=0x00000001; //select peripheral clock as (1/4)th of main clock
PCONP=0x00000002; //turn on timer0
//T0TCR=0x00000002;
T0PR=0x000036B0; // set prescale register counter, PC will count up to this count for one clock
T0TCR=0x00000001; // start timer0
T0MR0=0x000003E8; //match register value
//Delay is calculated by multiplying mr0 and (pr+1) value
while(T0TC != T0MR0); //Wait until counter 0 gets to 1000
T0TCR = 0x00000003; // reset timer control register to 00
}

}



int main(void) // in ARM main should be int or it will show error
{
unsigned int sw;

IODIR1=0x00ff0000;

while(1)
{
sw=IO1PIN;
if(sw == 0xBF000000)
{
for(;;)
{
IOSET1=0x003f0000;
wait(delay);
IOCLR1=0x003f0000;

IOSET1=0x00060000;
wait(delay);
IOCLR1=0x00060000;

IOSET1=0x005b0000;
wait(delay);
IOCLR1=0x005b0000;

IOSET1=0x004f0000;
wait(delay);
IOCLR1=0x004f0000;

IOSET1=0x00660000;
wait(delay);
IOCLR1=0x00660000;

IOSET1=0x006d0000;
wait(delay);
IOCLR1=0x006d0000;

IOSET1=0x007d0000;
wait(delay);
IOCLR1=0x007d0000;

IOSET1=0x00070000;
wait(delay);
IOCLR1=0x00070000;

IOSET1=0x007f0000;
wait(delay);
IOCLR1=0x007f0000;

IOSET1=0x006f0000;
wait(delay);
IOCLR1=0x006f0000;
}
}
}

}


thanks,
rushabh
 

maxpower097

Joined Feb 20, 2009
816
I'm looking for info on Keil LPC uC's too. Haven't found too much on them but generic stuff. Plus all the keil examples seem to run on some sort of OS.
 
Top