Interfacing 16x2 LCD | AT89C51
I am using the AT89C51 to interface the 16x2 LCD Display. It will be a minimal display message.
The tools I will be using are :
- Keil uVision 5
- Proteus 8 Professional
The LCD is operated in 8 bit mode to display two lines of messages under 16 characters. When interfacing with an LCD screen only, it doesn't matter the communication mode. When incorporating other modules and shields, we require other port pins for various usage. There I will be demonstrating the 4-bit mode. In this article, I will be demonstrating two operations :
- Static 2 line message display
- Scrolling 2 line message display
___________________________________________________________________________________
STATIC MESSAGE DISPLAY ON 16x2 LCD SCREEN
___________________________________________________________________________________
IDE : Keil uVision 5
Simulator : Proteus 8 Professional
uController : AT89C51
/* Created by mbedsyst */
#include<reg51.h>
sbit rs = P1^0;
sbit rw = P1^1;
sbit en = P1^2;
void lcdcmd (unsigned char);
void lcddat (unsigned char);
void lcdinit ();
void delay( unsigned int count)
{
unsigned int i;
while(count)
{
i = 115;
while(i>0)
{
i--;
}
count--;
}
}
void lcdinit ()
{
lcdcmd (0x38); // 5X7 matrix crystal
delay(100);
lcdcmd (0x01); // clear screen
delay(100);
lcdcmd (0x10); // cursor blinking
delay(100);
lcdcmd (0x0C); // display on
delay(100);
lcdcmd (0x80); // Force cursor to 1x1 position
delay(100);
}
void lcdcmd (unsigned char val)
{
P2 = val;
rs = 0;
rw = 0;
en = 1;
delay(10);
en = 0;
}
void lcddat (unsigned char val)
{
P2 = val;
rs = 1;
rw = 0;
en = 1;
delay(10);
en = 0;
}
lcd_dataa (unsigned char *disp) // function to send string to LCD
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcddat (disp[x]);
}
}
void main()
{
P2 = 0x00; // output declaration, data lines d0-d7 connect
lcdinit();
while (1)
{
lcdcmd (0x80);
lcd_dataa (" System Online");
delay(2500);
lcdcmd (0xC0);
lcd_dataa (" mbedsyst");
delay(2500);
}
}
___________________________________________________________________________________