#include<lpc21xx.h>
//delay function in msec
void delay(unsigned int msec)
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
// Function to send command to LCD
void lcdcmd(unsigned char data)
{
data<<=17; // P1.17 to P1.24 as Data Pins
IOPIN1 = data; // Read current status of Pins
IOSET1 = data;
IOCLR0 = 0x00000010; // P0.4 as RS
IOCLR0 = 0x00000020; // P0.5 as RW
IOSET0 = 0x00000040; // P0.6 as E
delay(1);
IOCLR0 = 0x00000040; // P0.6 as E
return;
}
// Function to send data to LCD
void lcddata(unsigned char data)
{
data<<=17; // P1.17 to P1.24 as Data Pins
IOPIN1 = data; // Read current status of Pins
IOSET1 = data;
IOSET0 = 0x00000010; // P0.4 as RS
IOCLR0 = 0x00000020; // P0.5 as RW
IOSET0 = 0x00000040; // P0.6 as E
delay(1);
IOCLR0 = 0x00000040; // P0.6 as E
return;
}
//send string to LCD
void lcddatastring(unsigned char *str)
{
int i=0;
while(str!='\0')
{
lcddata(str);
i++;
delay(1);
}
return;
}
void lcdinit()
{
lcdcmd(0x00380000); // 2-line 5x7 matrix
delay(2);
lcdcmd(0x000C0000); // Display ON, Cursor Blink
delay(2);
lcdcmd(0x00010000); // Clear Screen
delay(2);
lcdcmd(0x00810000); // Cursor to first position of the first line
delay(2);
}
int main(void)
{
IODIR0&=0xFFFFFFFF; // Port-0 as Output Pins
IODIR1&=0xFFFF0000; // Port-1 17-32 as Output Pins
lcdinit();
lcddatastring("Trial Program");
while(1);
}