Wednesday, December 24, 2014

Led Blinking

Program : For infinite alternate blinking of led.

/*---------program by Shreya Rajput-----*/
#include <LPC214X.H>
void delay(int x);
int main()
{
IO0DIR = 0XFFFFFFFF;  //setting all the pins as output
while(1)    //infinite loop
{
IO0SET |=(1<<3);   //setting pin P0.3 high
delay(5000);
IO0CLR |=(1<<3);   //setting pin P0.3 low
delay(5000);
}
return 0;
}
void delay(int x)  //delay function
{
unsigned k,c;
for(k=x;k>0;k--)    //in arm with for you cannot leave statement empty
{
for(c=0;c<x;c++);
}
}




This is a simple led blinking program for single pin.Similarly, use can use for more than one pin.
See, delay is must. As speed of processors are so fast that you won't be able notice the blinking

NOTE: For infite loop ,you can also use  for(;;) instead of while(1)

Friday, December 19, 2014

basic gpio program

This is simple program to turn on 8 leds conntected to port0 pins 0 to7 ,using LPC2148 chip




#define <lpc214x.h>
void delay(int x);
int main ()
{
IO0DIR = 0X0FF;  //to use p0.0-p0.7 as o/p pins
while(1)
{
IO0SET = 0X0FF; //to set port0 pin0 to pin7 high
delay(1000);
IO0CLR = 0X0FF; //clear the given pins
delay(1000);
}
return 0;
}
void delay(int x)
{
int a,c;
for(a=0;a>0;a--)
{
for(c=0;c<x;c++);
}
}



See since, arm is 32 bit . PORT 0 has 32 bits.
NOTE: We cannot use all the pins of port0. Pin no. 24,26 and 28 are unavailable for the use. Pin 31 can be used only as 'output'.

To set P0.0-P0.7 as output pins we can set
IO(port)DIR = 0X000000FF;
or
IO(port)DIR= 0X0FF .
These two mean the same.
further to use only 1 pin as out put we use left shif e.g IO0DIR |=(1<<0) // here p0.0 is set as output.

Same can be done for IO(port)SET and IO(port)CLR. These to pins are to set high and low or 1 and 0 respectively.

You can design delay as per your convenience.
I have used this delay,as it will run two loops ,resulting in longer delay.
NOTE: Do not  leave a for loop empty, not even for delay function. Keil won't read it.