#include<at89x51.h>
#include<intrins.h>
#define nop _nop_()
#define DB P1
sbit E=P3^0;
sbit RW=P3^1;
sbit RS=P3^2;
void init(void);
void write_com(unsigned char command);
void write_data(unsigned char dat);
void disp_char(unsigned char x,unsigned char y,unsigned char dat);
void check_busy(void);
void delay_n40us(unsigned int n);
/*****************************************
*************初始化函数******************/
void init(void)
{
write_com(0x38);
delay_n40us(500);
write_com(0x38);
delay_n40us(500);
write_com(0x38);
write_com(0x0c);
write_com(0x01);
write_com(0x0f);
write_com(0x06);
write_com(0x01);
delay_n40us(100);
}
void write_com(unsigned char command)
{
DB=command;
RS=0;
RW=0;
E=1;
nop;
E=0;
delay_n40us(1);
}
void write_data(unsigned char dat)
{
DB=dat;
RS=1;
RW=0;
E=1;
nop;
E=0;
delay_n40us(1);
}
void disp_char(unsigned char x,unsigned char y,unsigned char dat)
{
unsigned char address;
if(y==1)address=0x80+x;
else address=0xc0+x;
write_com(address);
write_data(dat);
}
void check_busy(void)
{
do
{
E=0;
RS=0;
RW=1;
DB=0xff;
E=1;
}while((DB&0x80)==0x80);
}
void delay_n40us(unsigned int n)
{
unsigned int i,j;
for(i=n;i>0;i--)
for(j=2;j>0;j--);
}
void main()
{ init();
while(1)
{
disp_char(0,1,'T');
// disp_char(0,1,'T');
disp_char(1,1,'h');
disp_char(2,1,'i');
disp_char(3,1,'s');
disp_char(4,1,' ');
disp_char(5,1,'i');
disp_char(6,1,'s');
disp_char(7,1,' ');
disp_char(8,1,'d');
disp_char(9,1,'e');
disp_char(10,1,'m');
disp_char(11,1,'o');
disp_char(12,1,' ');
disp_char(13,1,'f');
disp_char(14,1,'o');
disp_char(15,1,'r');
delay_n40us(10000);
delay_n40us(10000);
delay_n40us(10000);
write_com(0x07);
write_com(0x02);
disp_char(16,1,' ');
delay_n40us(5000);
disp_char(17,1,'5');
delay_n40us(5000);
disp_char(18,1,'1');
delay_n40us(5000);
disp_char(19,1,' ');
delay_n40us(5000);
disp_char(20,1,'c');
delay_n40us(5000);
disp_char(21,1,'o');
delay_n40us(5000);
disp_char(22,1,'n');
delay_n40us(5000);
disp_char(23,1,'t');
delay_n40us(5000);
disp_char(24,1,'r');
delay_n40us(5000);
disp_char(25,1,'o');
delay_n40us(5000);
disp_char(26,1,'l');
delay_n40us(5000);
disp_char(27,1,'l');
delay_n40us(5000);
disp_char(28,1,'i');
delay_n40us(5000);
disp_char(29,1,'n');
delay_n40us(5000);
disp_char(30,1,'g');
delay_n40us(5000);
disp_char(31,1,' ');
delay_n40us(5000);
disp_char(32,1,'1');
delay_n40us(5000);
disp_char(33,1,'6');
delay_n40us(5000);
disp_char(34,1,'0');
delay_n40us(5000);
disp_char(35,1,'2');
delay_n40us(5000);
disp_char(36,1,'L');
delay_n40us(5000);
disp_char(37,1,'C');
delay_n40us(5000);
disp_char(38,1,'D');
delay_n40us(5000);
disp_char(39,1,'!');
delay_n40us(5000);
delay_n40us(10000);
}
} |