完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
在学习51单片机,做了一个矩阵键盘输入,按键内容显示到LCD1602和串口发送的试验。结果串口发送正常,LCD1602不显示。有请大牛们帮忙看看是什么问题?
以下是代码: -------------------------------------------------------------------------------------------------------------- main.c #include #include "lcd.h" #define KEYS P1 unsigned char COL,ROW; unsigned char VALUES[4][4] = {{'0','1','2','3'},{'4','5','6','7'},{'8','9','A','B'},{'C','D','E','F'}}; void serial(unsigned char); void initLcd(); void main(void){ EA = 1; ES = 1; ET1 = 1; PCON |= 0x80; TH1 = 0xf3; TMOD = 0x20; SCON = 0x50; TR1 = 1; initLcd(); KEYS = 0x0f; while(1){ if(KEYS != 0x0f){ delay1ms(); if(KEYS != 0x0f){ switch(KEYS){ case 0x0e:COL = 3;break; case 0x0d:COL = 2;break; case 0x0b:COL = 1;break; case 0x07:COL = 0;break; } KEYS = 0xf0; switch(KEYS){ case 0xe0:ROW = 3;break; case 0xd0:ROW = 2;break; case 0xb0:ROW = 1;break; case 0x70:ROW = 0;break; } lcdWriteCom(0x80); lcdWriteData(VALUES[ROW][COL]); serial(VALUES[ROW][COL]); while(KEYS != 0xf0); } KEYS = 0x0f; } } } void serial(unsigned char dat){ SBUF = dat; while(ti == 0); TI = 0; } void initLcd(){ lcdWriteCom(0x01); lcdWriteCom(0x06); lcdWriteCom(0x0c); lcdWriteCom(0x30); } -------------------------------------------------------------------------------------------- lcd.h #ifndef _LCD_H #define _LCD_H ***it lcd_rs = P2^6; ***it lcd_rw = P2^5; ***it lcd_e = P2^7; void lcdWriteCom(unsigned char); void lcdWriteData(unsigned char); void delay1ms(); void delay5ms(); //void delay200ms(); #endif --------------------------------------------------------------------------------------------- lcd.c #include #include "lcd.h" void lcdWriteCom(unsigned char com){ lcd_e = 0; lcd_rs = 0; lcd_rw = 0; P0 = com; delay1ms(); lcd_e = 1; delay5ms(); lcd_e = 0; } void lcdWriteData(unsigned char dat){ lcd_e = 0; lcd_rs = 1; lcd_rw = 0; P0 = dat; delay1ms(); lcd_e = 1; delay5ms(); lcd_e = 0; } void delay1ms(){ unsigned char a,b,c; for(c=1;c>0;c--) for(b=142;b>0;b--) for(a=2;a>0;a--); } void delay5ms(){ unsigned char i; for(i=0;i<5;i++) delay1ms(); } ----------------------------------------------------------------------------------------------------- |
|
相关推荐
1个回答
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-Linux内核移植之内核启动流程
325 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-TF卡烧录流程之烧写过程
1362 浏览 0 评论
2780 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-mfgtools烧录流程之烧写原理
1883 浏览 0 评论
请问SPH0641LU4H这款麦克风如何在不使用I2S的情况下,单纯通过GPIO来进行驱动且正常读取数据呢
1409 浏览 1 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12133 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-8 02:47 , Processed in 0.730191 second(s), Total 86, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号