LCD1602点阵字符型LCD模块Keil C51驱动程序

[复制链接]
查看2117 | 回复0 | 2011-9-7 22:49:51 | 显示全部楼层 |阅读模式
<





16×2点阵字符型LCD模块Keil C51驱动程序


#i nclude
#define uchar unsigned char
idata char flag0 ;
idata char flag1 ;
idata char flag2 ;
idata char flag3 ;
idata char flag4 ;
idata char flag5 ;
idata char flag6 ;
idata char flag7 ;
sbit RS=P2^3;
sbit RW=P2^4;
sbit LCDE=P2^5;
sbit big=P3^2;
sbit fd=P3^3;
unsigned char line1[16],line2[16];
unsigned char code cgram1[64]={0x00,0x1f,0x12,0x09,0x1f,0x11,0x01,0x0f,
0x1e,0x04,0x04,0x08,0x1f,0x01,0x00,0x1e,
0x02,0x03,0x06,0x05,0x04,0x09,0x09,0x12,
0x00,0x1c,0x04,0x08,0x10,0x18,0x04,0x07,
0x00,0x0f,0x09,0x09,0x0f,0x09,0x09,0x0f,0x00,0x1c,0x04,0x04,0x1c,0x04,0x04,0x1c,
0x00,0x04,0x14,0x14,0x14,0x04,0x04,0x03,0x00,0x12,0x13,0x11,0x01,0x04,0x04,0x1c};/

void delay5ms()
{
register int i;
for (i=0;i<1000;i )
;
}
void delay50us()
{
register int i;
for (i=0;i<20;i )
;
}
wr_com(unsigned char comm)
{
LCDE=0;
RS=0;
RW=0;
LCDE=1;
P0=comm;
RS=0;
RW=0;
LCDE=0;
}
wr_data(unsigned char dat)
{
LCDE=0;
RS=0;
RW=0;
RS=1;
RW=0;
LCDE=1;
P0=dat;
LCDE=0;
RS=0;
RW=0;
}

unsigned char rd_bf()
{
unsigned char i;
P0=0xff;
LCDE=0;
RS=0;
RW=0;
RS=0;
RW=1;
LCDE=1;
i=P0;
LCDE=0;
return(i);
}

void init()
{
unsigned char in,i;
wr_com(0x30);
delay5ms();
wr_com(0x30);
delay5ms();
wr_com(0x30);
delay5ms();
in=rd_bf();
delay5ms();
wr_com(0x01);
delay5ms();
in=rd_bf();
delay5ms();
wr_com(0x06);
delay5ms();
in=rd_bf();
delay50us();
wr_com(0x38);
delay50us();
in=rd_bf();
delay50us();
wr_com(0x0c);
delay50us();
in=rd_bf();
delay50us();

wr_com(0x40); //set cgram address
delay50us();
in=rd_bf();
delay50us();
for(i=0;i<64;i )
{
wr_data(cgram1); //display "0"
delay50us();
in=rd_bf();
}



}

display_162()
{
unsigned char in,i;
wr_com(0x80); //set ram address
delay50us();
in=rd_bf();
delay50us();
for(i=0;i<16;i )
{
wr_data(line1); //display "0"
delay50us();
in=rd_bf();
}
in=rd_bf();
delay50us();
wr_com(0xc0);
delay50us();
in=rd_bf();
delay50us();
for(i=0;i<16;i )
{
wr_data(line2); //display "0"
delay50us();
in=rd_bf();
}
}
main()
{
unsigned char in,i,da;
delay5ms();
delay5ms();
delay5ms();
delay5ms();


init();
while(1)
{
if(fd==1)
{
line1[0]=0x20;
line1[1]=0; //display "爱思"
line1[2]=1;
line1[3]=4;
line1[4]=5;
line1[5]=0x20;
line1[6]=0; //display "爱思"
line1[7]=1;
line1[8]=4;
line1[9]=5;
line1[10]=0x20;
line1[11]=0; //display "爱思"
line1[12]=1;
line1[13]=4;
line1[14]=5;
line1[15]=0x20;

line2[0]=0x20;
line2[1]=2; //display "爱思"
line2[2]=3;
line2[3]=6;
line2[4]=7;
line2[5]=0x20;
line2[6]=2; //display "爱思"
line2[7]=3;
line2[8]=6;
line2[9]=7;
line2[10]=0x20;
line2[11]=2; //display "爱思"
line2[12]=3;
line2[13]=6;
line2[14]=7;
line2[15]=0x20;

}
else if(big==1)
本新闻共2页,当前在第1页 [1] [2]
热帖推荐
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则