#include <REGX51.H>
#include <stdio.H>
#define LCDPORT P2
sbit RS = LCDPORT ^ 4;
sbit EN = LCDPORT ^ 5;
void delay(unsigned int msec)
{
int i, j;
for (i = 0; i < msec; i++)
for (j = 0; j < 1275; j++);
}
void LCDSTROBE(void)
{
EN = 1;
delay(4);
EN = 0;
}
void dt(unsigned char c)
{
RS = 1;
delay(50);
LCDPORT = ((c >> 4) & 0x0f);
LCDSTROBE();
LCDPORT = (c & 0x0F) ;
LCDSTROBE();
}
void cmd(unsigned char c)
{
RS = 0;
delay(50);
LCDPORT = ((c >> 4) & 0x0f);
LCDSTROBE();
LCDPORT = (c & 0x0F);
LCDSTROBE();
}
void lcdclear(void)
{
cmd(0x01);
delay(2);
}
void lcd_init()
{
delay(15);
cmd(0x38);
delay(1);
cmd(0x38);
delay(100);
cmd(0x38);
cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
delay(1);
cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
cmd(0x0c); // Make cursorinvisible
lcdclear(); // Clear screen
cmd(0x6); // Set entry Mode(auto increment of cursor)
}
void string(const char *q)
{
while (*q) {
dt(*q++);
}
}
main()
{
delay(50);
lcd_init();
LCDPORT = 0x00;
while (1) {
cmd(0x80);
string("HELLO WORLD");
cmd(0xc0);
string("IT IS WORKING:-)");
}
}