#include <reg51.h>
#include <intrins.h> //库函数头文件,代码中引用了_nop_()函数
sbit RS=0xb0; //P3.0
sbit RW=0xb1; //P3.1
sbit E= 0xb2; //P3.2
void lcd_w_cmd(unsigned char com);
void lcd_w_dat(unsigned char dat);
unsigned char lcd_r_start();
void int1();
void delay(unsigned char t);
void delay1();
void main()
{
P2=0xff;
int1();
lcd_w_cmd(0x40); //工
lcd_w_dat(0x1f);
lcd_w_cmd(0x41);
lcd_w_dat(0x1f);
lcd_w_cmd(0x42);
lcd_w_dat(0x04);
lcd_w_cmd(0x43);
lcd_w_dat(0x04);
lcd_w_cmd(0x44);
lcd_w_dat(0x04);
lcd_w_cmd(0x45);
lcd_w_dat(0x1f);
lcd_w_cmd(0x46);
lcd_w_dat(0x1f);
lcd_w_cmd(0x47);
lcd_w_dat(0x00);
lcd_w_cmd(0x48); //欠
lcd_w_dat(0x08);
lcd_w_cmd(0x49);
lcd_w_dat(0x0f);
lcd_w_cmd(0x4a);
lcd_w_dat(0x0d);
lcd_w_cmd(0x4b);
lcd_w_dat(0x14);
lcd_w_cmd(0x4c);
lcd_w_dat(0x04);
lcd_w_cmd(0x4d);
lcd_w_dat(0x0a);
lcd_w_cmd(0x4e);
lcd_w_dat(0x11);
lcd_w_cmd(0x4f);
lcd_w_dat(0x00);
lcd_w_cmd(0x50); //又
lcd_w_dat(0x00);
lcd_w_cmd(0x51);
lcd_w_dat(0x0e);
lcd_w_cmd(0x52);
lcd_w_dat(0x02);
lcd_w_cmd(0x53);
lcd_w_dat(0x0a);
lcd_w_cmd(0x54);
lcd_w_dat(0x04);
lcd_w_cmd(0x55);
lcd_w_dat(0x0a);
lcd_w_cmd(0x56);
lcd_w_dat(0x11);
lcd_w_cmd(0x57);
lcd_w_dat(0x00);
lcd_w_cmd(0x80);
lcd_w_dat(0x00);
lcd_w_cmd(0xc0);
lcd_w_dat(0x02);
lcd_w_dat(0x01);
while(1);
}
void delay(unsigned char t)
{
unsigned char j,i;
for(i=0;i<t;i++)
for(j=0;j<50;j++);
}
void delay1()
{
_nop_();
_nop_();
_nop_();
}
void int1()
{
lcd_w_cmd(0x3c);
lcd_w_cmd(0x0c);
lcd_w_cmd(0x01);
lcd_w_cmd(0x06);
lcd_w_cmd(0x80);
}
unsigned char lcd_r_start()
{
unsigned char s;
RW=1;
delay1();
RS=0;
delay1();
E=1;
delay1();
s=P2;
delay1();
E=0;
delay1();
RW=0;
delay1();
return(s);
}
void lcd_w_cmd(unsigned char com)
{
unsigned char i;
do{
i=lcd_r_start();
i=i&0x80;
delay(2);
}while(i!=0);
RW=0;
delay1();
RS=0;
delay1();
E=1;
delay1();
P2=com;
delay1();
E=0;
delay1();
RW=1;
delay(255);
}
void lcd_w_dat(unsigned char dat)
{
unsigned char i;
do{
i=lcd_r_start();
i=i&0x80;
delay(2);
}while(i!=0);
RW=0;
delay1();
RS=1;
delay1();
E=1;
delay1();
P2=dat;
delay1();
E=0;
delay1();
RW=1;
delay(255);
}
-
-
LCD1602显示我的学号和姓名.rar
下载积分: 积分 -1 分
34.26 KB, 下载次数: 5, 下载积分: 积分 -1 分
我自己改好了!
一周热门 更多>