#include <reg52.h>
#include <string.h>
sbit RS = P1^0;
sbit RW = P1^1;
sbit EN = P1^2;
sbit BUSY = P0^7;
typedef unsigned char uint8;
typedef unsigned int uint16;
char string[]="guoyingjie";
char neirong[]="151307191";
void wait()
{ P0 = 0XFF;
do { EN=0;
RS=0;
RW=1;
EN=1;
}
while(BUSY==1);
EN=0;
}
void write_cmd(uint8 cmd)
{ wait();
EN=0;
RS=0;
RW=0;
P0=cmd;
EN=1;
EN=0;
}
void write_data(uint8 dat)
{ wait();
EN=0;
RS=1;
RW=0;
P0=dat;
EN=1;
EN=0;
}
void delay()
{
uint16 i=50000;
while(i--);}
void lcd_init()
{
write_cmd(0x38);
write_cmd(0x0c); ///初始化lcd
write_cmd(0x06);
write_cmd(0x01);
}
void w_str(uint8 addr,char *p)
{
write_cmd(addr);
while(*p!='\0')
write_data(*p++);
}
void guo()
{
lcd_init();
while(1)
{
w_str(0xa7-strlen(string),string);
w_str(0xe7-strlen(neirong),neirong);
write_cmd(0x1c); //0x1c向右,0x18向左移动
delay();
}
}