#include <reg52.h>
#include<intrins.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit RS = P3^5;
sbit RW = P3^6;
sbit EN = P3^4;
#define LCD1602_A P0
void delay_ms(uint n)
{
uint i,y;
for(i=n;i>0;i--)
{
for(y=114;y>0;y--);
}
}
void Read_busy()
{
uchar busy;
LCD1602_A = 0xff;
RS = 0;
RW = 1;
do{
EN = 1;
busy = LCD1602_A;
EN = 0;
}while(busy & 0x80);
}
void Write_cmd(uchar cmd)
{
Read_busy();
RS = 0;
RW = 0;
LCD1602_A = cmd;
EN = 1;
EN = 0;
}
void Write_dat(uchar dat)
{
Read_busy();
RS = 1;
RW = 0;
LCD1602_A = dat;
EN = 1;
EN = 0;
}
void Dis_onechar(uchar x, uchar y, uchar dat)
{
if(y) x |= 0x40;
x |= 0x80;
Write_cmd(x);
Write_dat(dat);
}
void Dis_str(uchar x, uchar y, uchar *str)
{
if(y) x |= 0x40;
x |= 0x80;
Write_cmd(x);
while(*str != '\0')
{
Write_dat(*str++);
}
}
void Init_LCD1602()
{
Write_cmd(0x38);
Write_cmd(0x0c);
Write_cmd(0x06);
Write_cmd(0x01);
}
void main()
{
while(1)
{
uchar i = 1;
uchar str[20]={"Just do it ! "} ;
uchar *p;
p = str;
Init_LCD1602();
while(1)
{
Dis_str(i,0,*p);
i++;
P++;
delay_ms(1000);
}
delay_ms(1000);
}
}
|