Interfacing LCD with ARM
16×2 LCD is widely used in various embedded applications. The reason for this is its easy operation and it can display a large number of characters and symbols. In this tutorial we’ll interface LCD with ARM7 based microcontroller LPC2138.
Fig. 2: Screenshot of LCD commands from its datasheet
Scrolling Text and Interfacing Keypad
lcd_string(“Hello World..This is LCD”)
for (i=0;i<8;i++) // shift displayed char. By 8 positions
{
lcd_command(0x18);
}
Project Source Code
###
***************Code for Interfacing LCD*************** #include<lpc21xx.h> // header file for lpc devices void delay(unsigned int t); // delay functionvoid init(void);
void cmd(unsigned char cd); // lcd command function
void data(unsigned char dt); // lcd data functionvoid str(unsigned char *str); // lcd string function
int main(void)
{
IODIR0=0X00000fff; // P0.0 to P0.11 selected as o/p pins
init(); // lcd initialization
cmd(0x80); // row 1 selected
str("LCD interfacing"); // display string 1
delay(10);
cmd(0xc0); // row 2 selected
str("with LPC2138");
delay(10);
while(1);return 0;
}void init()
{
cmd(0x01); //call 0x01 command to clear display
delay(50); //wait for completion of clear display command
cmd(0x38); //command for 16 character and 2 line display
delay(10); //wait for completion of command
cmd(0x0C); //turn ON display, cursor OFF, cursor blinking OFF
delay(10); //wait for completion of command
cmd(0x06); //increment cursor after each write,
delay(10); //wait for completion of command
}void cmd(unsigned char cd)
{
IOCLR0=(1<<10); // en=0
IOPIN0=cd; // Latch Command DATA on P0.0 to P0.7
IOCLR0=(1<<8); // r/s=0
IOCLR0=(1<<9); // r/w=0 (write operation)
IOSET0=(1<<10); // en=1 (lcd enable)
delay(1);
IOCLR0=(1<<10); // en=0 (lcd disable)
}void data(unsigned char dt)
{
IOCLR0=(1<<10); // en=0
IOPIN0=dt; // Latch Command DATA on P0.0 to P0.7
IOSET0=(1<<8); // r/s=0
IOCLR0=(1<<9); // r/w=0 (write operation)
IOSET0=(1<<10); // en=1 (lcd enable)
delay(1);
IOCLR0=(1<<10); // en=0 (lcd disable)
}void str(unsigned char *str)
{
unsigned int i=0;
while(str[i]!='