Wednesday, 25 December 2013

LCD interfacing program in C for ARM (LPC 2XXX)

#include<LPC21XX.h>
#define RS (1<<0)
#define RW (1<<1)
#define EN (1<<2)
void display(unsigned char i);
void cmd(unsigned char j);
void lcd_string(unsigned char *p);
void delay(unsigned char k);
int main()
{
     PINSEL0=0x00000000;
IODIR0|=0X00000FFF;
  cmd(0x38);
  cmd(0x01);
  cmd(0x06);
  cmd(0x0E);
  cmd(0x84);
  lcd_string("JAYPEE");
cmd(0xc2);
lcd_string("UNIVERSITY");
  while(1);
  }

 void cmd(unsigned char j)
 {
IOCLR0|=0X00000FFF;
    IOSET0|=(j<<4);
IOCLR0|=RS;
IOCLR0|=RW;
IOSET0|=EN;
delay(100);
IOCLR0|=EN;
}
void lcd_string(unsigned char *p)
{
while(*p!=0)
{

display(*p);
p++;
}
}
void display(unsigned char i)
{
IOCLR0|=0X00000FFF;
IOSET0|=(i<<4);
IOSET0|=RS;
IOCLR0|=RW;
IOSET0|=EN;
delay(100);
IOCLR0|=EN;
}
void delay(unsigned char k)
{
int l,m;
for(l=0;l<k;l++)
{
for(m=0;m<1000;m++);
}
}

No comments:

Post a Comment