#include <REGX51.H>
#define LCDPORT P2
sbit RS = LCDPORT ^ 2;
sbit E = LCDPORT ^ 3;
void delay(unsigned int itime)
{
unsigned int i, j;
for (i = 0; i < itime; i++)
for (j = 0; j < 1275; j++);
}
void latch(void)
{
E = 1;
delay(10);
E = 0;
}
void lcd_cmd(unsigned char c)
{
RS = 0;
delay(1);
LCDPORT = c & 0xf0;
latch();
delay(1);
LCDPORT = (c << 4);
latch();
}
void lcd_data(unsigned char c)
{
//RS =1;
delay(1);
LCDPORT = c & 0xf0 | 0x4;
delay(1);
latch();
LCDPORT = (c << 4) | 0x4;;
latch();
}
void lcd_init()
{
delay(50);
lcd_cmd(0x30);
delay(20);
lcd_cmd(0x30);
delay(4);
lcd_cmd(0x30);
delay(4);
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x0c); // Make cursorinvisible
lcd_cmd(0x6); // Set entry Mode(auto increment of cursor)
}
void main()
{
P2 = 0x00;
lcd_init();
lcd_cmd(0x80);
lcd_data(1); // just send "1" to lcd to display ;
P3 = 0xf0;
while (1);
}