#include <stc8.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs = P1^0;
sbit rw = P1^1;
sbit e = P1^2;
uchar code table[] = "Welcome MKX";
uchar code table1[] = "Hello!";
void delay(uint n);
void Init();
void write_cmd(uchar cmd);
void write_dat(uchar dat);
void main(void)
{
uchar a,b,c;
Init();
delay(200);
while(1)
{
write_cmd(0x80+3);
for(b = 0;b < 11;b++)
{
write_dat(table[b]);
delay(5000);
}
write_cmd(0x80+0x45);
for(a = 0;a <6;a++)
{
write_dat(table1[a]);
delay(5000);
}
for(c = 0;c <15;c++)
{
delay(5000);
write_cmd(0x1c);
delay(5000);
}
write_cmd(0x01);
delay(200);
}
}
void delay(uint n)
{
uint x,y;
for(x = n;x > 0;x--)
{
for(y = 110;y > 0;y--);
}
}
void write_cmd(uchar cmd)
{
rs = 0;
rw = 0;
P7 = cmd;
delay(5);
e = 1;
e = 0;
}
void write_dat(uchar dat)
{
rs = 1;
rw = 0;
P7 = dat;
delay(5);
e = 1;
e = 0;
}
void Init()
{
write_cmd(0x38);
write_cmd(0x0c);
write_cmd(0x06);
write_cmd(0x01);
}
|