//-------------------------------------------
#include<reg52.h>
#include<intrins.h>
#define dataport P1
#define uchar unsigned char
#define uint unsigned int
// sbit RS =P2^4;
// sbit RW =P2^3;
// sbit En =P2^2;
sbit RS=P2^1;
sbit RW=P2^0;
sbit En=P2^2;
void delay_ms(uchar time)
{
uchar i,j;
for(i=time;i>0;i--)
{
for(j=125;j>0;j--)
{;}
}
}
//----------------------------------------- 忙等
void read_bf(void)
{
En=0;
RS=0;
RW=1;
dataport=0xff;
_nop_();
_nop_();
En=1;
while(dataport&0x80) ;
En=0;
}
//-----------------------------------------写命令
void write_command(uchar command)
{
read_bf();
RW=0;
RS=0;
En=1;
dataport=command;
_nop_();
_nop_();
En=0;
}
//------------------------------------------写数据
void write_data(uchar data_)
{
read_bf();
RW=0;
RS=1;
En=1;
dataport=data_;
_nop_();
_nop_();
En=0;
}
//-------------------------------------------初始化
void init_lcd(void)
{
delay_ms(15);
write_command(0x38);
delay_ms(5);
write_command(0x38);
delay_ms(5);
write_command(0x38);
read_bf();
write_command(0x38);
read_bf();
write_command(0x08);
read_bf();
write_command(0x01);
read_bf();
write_command(0x06);
read_bf();
write_command(0x0c);
}
void lcd_disp(uchar addr,uchar a_data)
{
write_command(addr);
write_data(a_data);
}
//-------------------------------------------主函数
void main()
{
uchar ch[8]= {0x53,0x54,0x43,0x38,0x39,0x43,0x35,0x32};
uchar i;
init_lcd();
for(i=0;i<7;i++)
lcd_disp(0x80+i,ch[i]) ;
while(1);
}
//------------------------------------------- |