#include<reg52.h>
#define uc unsigned char
#define ui unsigned int
#define LCD P1
sbit LCD_RS = P2^5;
sbit LCD_RW = P2^6;
sbit LCD_EN = P2^7;
uc code table[] = "HELLO";
uc code table1[] = "WORLD";
uc number;
void InitLcd1602();
void LcdWrite_com(uc);
void LcdWrite_date(uc);
/*void delay(ui z)
{
ui x,y;
for(x = z; x>0; x--)
for(y=110;y>0;y--);
}*/
void main()
{
InitLcd1602();
LcdWrite_com(0x80);
for(number = 0 ; number<5; number++)
{
LcdWrite_date(table[number]);
//delay(5);
}
LcdWrite_com(0x80+0x40);
for(number = 0 ; number<5;number++)
{
LcdWrite_date(table1[number]);
//delay(5);
}
while(1);
}
void LcdReady()
{
uc sta;
LCD = 0xFF;
LCD_RS = 0;
LCD_RW = 1;
do
{
LCD_EN = 1;
sta = LCD;
LCD_EN = 0;
}
while(sta & 0x80);
}
void LcdWrite_date(uc date)
{
LcdReady();
LCD_RS = 1;
LCD_RW = 0;
LCD = date;
//delay(5);
LCD_EN = 1;
//delay(5);
LCD_EN = 0;
}
void LcdWrite_com(uc com)
{
LcdReady();
LCD_RS = 0;
LCD_RW = 0;
LCD = com;
//delay(5);
LCD_EN = 1;
//delay(5);
LCD_EN = 0;
}
void InitLcd1602()
{
LcdWrite_com(0x38);
LcdWrite_com(0x0c);
LcdWrite_com(0x06);
LcdWrite_com(0x01);
} |