Tuesday, 22 September 2015

LCD Programming using 4 data lines in ARM7(LPC2129/38)



#include<lpc21xx.h>
void cmd(int);
void cmd1(int);
void data(char);
void delay();
void print(const char *p)
{
while(*p)
data(*p++);
}
int main()
{
IO1DIR=0XFFFFFFFF;
cmd(0x30);
cmd(0x30);
cmd(0x30);
cmd(0x20);
cmd1(0x28);
cmd1(0x01);
cmd1(0x06);
cmd1(0x0e);
cmd1(0x80);
print("hello world");
while(1);
}
void cmd(int b)
{
unsigned int s;
s=b&0xf0;
IO1SET=s<<16;
IO1CLR=0X000F0000;
IO1SET|=0X00080000;
delay();
IO1CLR=0X00080000;
IO1CLR=0XFFFFFFFF;
}

void cmd1(int a)
{
unsigned int s;
s=a&0xf0;
IO1SET=s<<16;
IO1CLR=0X000F0000;
IO1SET|=0X00080000;
delay();
IO1CLR=0X00080000;
IO1CLR=0XFFFFFFFF;


s=a&0x0f;
IO1SET=s<<20;
IO1CLR=0X000F0000;
IO1SET|=0X00080000;
delay();
IO1CLR=0X00080000;
delay();
IO1CLR=0XFFFFFFFF;
}
void data(char a)
{

char s;
s=a&0xf0;
IO1SET=s<<16;
IO1CLR=0X000F0000;
IO1SET|=0X000A0000;
delay();
IO1CLR=0X00080000;
IO1CLR=0XFFFFFFFF;


s=a&0x0f;
IO1SET=s<<20;
IO1CLR=0X000F0000;
IO1SET|=0X000A0000;
delay();
IO1CLR=0X00080000;
delay();
IO1CLR=0XFFFFFFFF;
}
void delay()
{
int i;
for(i=0;i<10000;i++);
}

No comments:

Post a Comment