標(biāo)題:
51單片機(jī)LCD1602液晶顯示器(LM016L)顯示功能實(shí)現(xiàn)+Proteus仿真+常見(jiàn)問(wèn)題原因
[打印本頁(yè)]
作者:
Rremake
時(shí)間:
2022-5-9 21:14
標(biāo)題:
51單片機(jī)LCD1602液晶顯示器(LM016L)顯示功能實(shí)現(xiàn)+Proteus仿真+常見(jiàn)問(wèn)題原因
常見(jiàn)問(wèn)題:
液晶顯示器只有背光無(wú)法顯示字符
將判忙函數(shù)替換成延時(shí)函數(shù),延時(shí)5ms左右即可
proteus仿真圖
1.png
(54.06 KB, 下載次數(shù): 52)
下載附件
2022-5-9 21:57 上傳
代碼:
#include<reg51.h>
#include<intrins.h> //包含_nop_()函數(shù)定義的頭文件
#define uchar unsigned char
#define uint unsigned int
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
sbit BF=P1^7;
uchar code dis1[]={"hellow world"};
uchar code dis2[]={"1 2 3 4 5 6"};
void delay(uchar ms){ //延時(shí)ms時(shí)間
uchar i;
while(ms--){
for(i=0;i<250;i++){
_nop_();_nop_();_nop_();_nop_(); //延時(shí)4個(gè)機(jī)器周期
}
}
}
bit busy(){ //檢查是否忙碌
bit result;
RS=0;
RW=1;
E=1;
_nop_();_nop_();_nop_();_nop_()
result=BF;
E=0;
return result;
}
void wcmd(uchar cmd){ //寫(xiě)命令
//while(busy()==1); //判斷LCD是否忙碌
delay(20); //將判忙函數(shù)換成延時(shí)函數(shù)(5毫秒左右)可以改變LM016L只有背光不顯示的情況,還可以多次初始化
RS=0;
RW=0; //RS和RW同時(shí)為低電平時(shí),可以寫(xiě)入命令
E=0; //為了使E正跳變,先置低電平
_nop_();_nop_();_nop_();_nop_();
P1=cmd; //將命令輸入P1口
_nop_();_nop_();_nop_();_nop_();
E=1; //E置高電平,產(chǎn)生正跳變,將指令寫(xiě)入液晶模塊
_nop_();_nop_();_nop_();_nop_();
E=0;
}
void pos(uchar y,uchar x){ //設(shè)置顯示位置y行x列
y&=0x1; //最多兩行,限制y的范圍0~1
x&=0xf; //最多每行16個(gè)字符,限制x的范圍0~15
if(y==1) x|=0xc0;
if(y==0) x|=0x80;
wcmd(x); //發(fā)送地址碼
}
void wdat(uchar dat){ //寫(xiě)要顯示的內(nèi)容
//while(busy()==1);
delay(20);
RS=1;
RW=0;
E=0;
P1=dat;
_nop_();_nop_();_nop_();_nop_();
E=1;
_nop_();_nop_();_nop_();_nop_();
E=0;
}
void init(){ //初始化
delay(15);
wcmd(0x38);
delay(10);
wcmd(0x38);
delay(10);
wcmd(0x38);
delay(10);
wcmd(0x0c);
delay(10);
wcmd(0x06);
delay(10);
wcmd(0x01);
delay(10);
}
void main(void){
uchar i;
init();
delay(1);
pos(0,0);
i=0;
while(dis1[i]!='\0'){
wdat(dis1[i]);
i++;
}
pos(1,0);
i=0;
while(dis2[i]!='\0'){
wdat(dis2[i]);
i++;
}
while(1);
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1