我在郭天祥的
单片机板子上面用了下面的代码,液晶显示1602就不显示了呢?
其他引脚的功能我没有变化,只是把RS,RW,EN分别插到引脚P1.0,P1.1,P1.2。望哪位大神帮忙解答一下,
在此谢谢!
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define Lcd_DB P0
- sbit Lcd_RS = P1^0;
- sbit Lcd_RW = P1^1;
- sbit Lcd_EN = P1^2;
- sbit dula = P2^6;
- sbit wela = P2^7;
- void InitLcd1602();
- void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str);
- void main()
- {
- wela = 0;
- dula = 0;
- InitLcd1602();
- LcdShowStr(2,0,"UESTC.COM");
- LcdShowStr(0,1,"WELCOME TO UESTC");
- while(1);
- }
- void LcdWaitReady()
- {
- unsigned char sta;
- Lcd_DB = 0xff;
- Lcd_RS = 0;
- Lcd_RW = 1;
- do{
- Lcd_EN = 1;
- sta = Lcd_DB;
- Lcd_EN = 0;
- }while(sta&0x80);
- }
- void LcdWriteCmd(unsigned char cmd)
- {
- LcdWaitReady();
- Lcd_RS = 0;
- Lcd_RW = 0;
- Lcd_DB = cmd;
- Lcd_EN = 1;
- Lcd_EN = 0;
- }
- void InitLcd1602()
- {
- LcdWriteCmd(0x38);
- LcdWriteCmd(0x0C);
- LcdWriteCmd(0x06);
- LcdWriteCmd(0x01);
- }
- void LcdShowCursor(unsigned char x, unsigned char y)
- {
- unsigned char addr;
- if(0==y)
- {
- addr = 0x00 + x;
- }
- else
- addr = 0x40 + x;
- LcdWriteCmd(addr | 0x80);
- }
- void LcdWriteDat(unsigned char dat)
- {
- LcdWaitReady();
- Lcd_RS = 1;
- Lcd_RW = 0;
- Lcd_DB = dat;
- Lcd_EN = 1;
- Lcd_EN = 0;
- }
- void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str)
- {
- LcdShowCursor(x,y);
-
- while(*str != ' ')
- {
- LcdWriteDat(*str++);
- }
- }
复制代码
PO口才是LCD的数据口,”郭天祥“的上面的代码直接就把R/W接在了低电平上面,所以就没有判断LCD的状态是否忙,就添加了很多延时在上面。我现在想根据另外一种方式,通过判断LCD处在闲的状态,然后写命令和数据,就不用添加延时了。昨天把R/W还在了P3.7接口就成功了,但是不知道怎么回事。
一周热门 更多>