代码如下:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^4;
uint i,j;
uchar num;
uchar code table1[]="YL51 MCU";
uchar code table2[]="000000000000";
void delay(uint x)
{
for(i=x;i>0;i--)
{
for(j=120;j>0;j--);
}
}
void write_com(uchar com)
{
RS=0;
RW=0;
E=0;
P2=com;
E=1;
delay(5);
E=0;
}
void write_data(uchar dat)
{
RS = 1;
RW = 0;
E=0;
P2 = dat;
E = 1;
delay(5);
E = 0;
}
void init()
{
write_com(0x38);
write_com(0x08);
write_com(0x01);
write_com(0x06);
}
void main()
{
init();
for(num=0;num<9;num++)
{
write_data(table1[num]);
delay(300);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_data(table2[num]);
delay(300);
}
while(1);
}
|