|
下面是我写的程序
#include<reg51.h>
#define BYTE unsigned char
BYTE str1[4]={"8051"};
BYTE str2[8]={"20140721"};
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
void delay(z)
{
unsigned char i,j;
for(j=0;j<0xff;j++)
{
for(i=0;i<0xff;i++)
{
}
}
}
void busy_check(m)
{
BYTE k;
do
{rs=0;
rw=1;
e=1;
delay(100);
k=P0;
e=0;}
while((k%0x80)&0x80==0x80);
}
void lcd_wrins(BYTE cmd)
{
busy_check(200);
rs=0;
rw=0;
e=0;
P0=cmd;
e=1;
delay(100);
e=0;
}
void lcd_wrdata(BYTE dat)
{
busy_check(200);
rs=1;
rw=0;
e=0;
P0=dat;
e=1;
delay(100);
e=0;
}
void lcd_init()
{
lcd_wrins(0x38);
delay(100);
lcd_wrins(0x01);
delay(100);
lcd_wrins(0x06);
delay(100);
lcd_wrins(0x0C);
delay(100);
}
void main()
{
unsigned char i;
lcd_init();
lcd_wrins(0x80);
for(i=0;i<4;i++)
{
lcd_wrdata(str1[i]);
}
lcd_wrins(0xC0);
for(i=0;i<8;i++);
{
lcd_wrdata(str2[i]);
}
while(1);
}
|
|