单片机代码及截图如下
#include "reg52.h"
#include"intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define out P0
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
void lcd_initial(void);
void check_busy(void);
void write_command(uchar com);
void write_data(uchar dat);
void string(uchar ad,uchar*s);
void delay(uint);
void main(void)
{ lcd_initial();
while(1)
{ string(0x80,"Welcome");
string(0xC0,"Chengdu CHINA");
delay(1000);
write_command(0x01);
delay(1000);
}
}
void delay(uint j)
{ uchar i=250;
for( ;j>0;j--)
{ while(--i);
i=249;
while(--i);
i=250;
}
}
void check_busy(void)
{ uchar dt;
do
{ dt=0xff;
E=0;
RS=0;
RW=1;
E=1;
dt=out;
}while(dt&0x80);
E=0;
}
void write_command(uchar com)
{ check_busy();
E=0;
RS=0;
RW=0;
out=com;
E=1;
_nop_( );
E=0;
delay(1);
}
void write_data(uchar dat)
{ check_busy();
E=0;
RS=1;
RW=0;
out=dat;
E=1;
_nop_();
E=0;
delay(1);
}
void lcd_initial(void)
{ write_command(0x38);
write_command(0x0F);
write_command(0x06);
write_command(0x01);
delay(1);
}
void string(uchar ad,uchar *s)
{ write_command(ad);
while(*s>0)
{ write_data(*s++);
delay(100);
}
}
|