完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
在proteus中用arm7LPC2131仿真时,用LCD显示好好地,可只要将矩阵键盘接入ARM7的P0.16到P0.22端口时,LCD的显示就会受到影响这是为什么?下面是我写的代码
#include"config.h" #define BUSY (1<<7) #define RS (1<<8) #define RW (1<<9) #define E (1<<10) unsigned int k; uint8 str[] = {"Enter password:"}; void delay1ms(void) { unsigned int i,j; for(i=0;i<4;i++) for(j=0;j<38;j++); } void delaynms(unsigned int n) { unsigned int i; for(i=0;i } //LCD查忙 unsigned int lcd_busy(void) { unsigned int busy; IO0DIR = 0XFFF; IO0CLR = RS; IO0SET = RW; IO0SET = E; for(k=1;k>0;k--); busy = (IO0PIN & (1<<7)); IO0CLR = E; return busy; } //LCD模式设置 void lcd_modset(unsigned char mod) { while(lcd_busy() != 0); IO0CLR = RS; IO0CLR = RW; IO0CLR = E; for(k=1;k>0;k--); IO0CLR = 0XFF; IO0SET = mod; for(k=1;k>0;k--); IO0SET = E; for(k=1;k>0;k--); IO0CLR = E; } //指定字符显示的实际地址 void lcd_waddr(unsigned char addr) { lcd_modset(addr|0x80); } //将数据字符的标准ASCII码写入液晶模块 void lcd_wdata(unsigned char data) { while(lcd_busy() != 0); IO0SET = RS; IO0CLR = RW; IO0CLR = E; IO0CLR = 0XFF; IO0SET = data; for(k=1;k>0;k--); IO0SET = E; for(k=1;k>0;k--) IO0CLR = E; } //将字符串写入液晶模块 void lcd_wstr(uint8 *str) { unsigned int i=0; for(;i<15;i++) { lcd_wdata(str[i]); delaynms(50); } } //LCD初始化 void lcd_init(void) { delaynms(15); lcd_modset(0x38); delaynms(10); lcd_modset(0x38); delaynms(10); lcd_modset(0x38); delaynms(10); lcd_modset(0x0f); delaynms(10); lcd_modset(0x06); delaynms(10); lcd_modset(0x01); delaynms(10); } //KEYPAD_PHONE键盘扫描函数 void key_s(void) { IO0CLR = 0X7<<16; IO0DIR = IO0DIR | 0X7F<<16; IO0SET = 0XF<<19; IO0CLR = 1<<19; delay1ms(); IO0SET = 1<<19; IO0CLR = 1<<20; delay1ms(); IO0SET = 1<<20; IO0CLR = 1<<21; delay1ms(); IO0SET = 1<<21; IO0CLR = 1<<22; delay1ms(); IO0SET = 1<<22; } //键盘键值读取函数 unsigned int key_r(void) { int row,col; row = 0; switch(IO0PIN & (7<<16)) { case 0x3: col = 3;break; case 0x5: col = 2;break; case 0x6: col = 1;break; default:break; } switch(IO0PIN & (0xf<<19)) { case 0xe: row = 1;break; case 0xc: row = 2;break; case 0xa: row = 3;break; case 0x7: row = 4;break; default:break; } if(row != 0) row = (row-1)*3 + col; else row = 0; return(row); } //初始化 void init(void) { PINSEL0 = 0X00000000; PINSEL1 = 0X00000000; lcd_init(); lcd_waddr(0x00); lcd_wstr(str); delaynms(500); //lcd_waddr(0x40); //lcd_wdata('E'); //delaynms(500); lcd_waddr(0x40+15); lcd_wdata('s'); } int main(void) { init(); while(1) { key_s(); switch(key_r()) { case 0: break; case 1: lcd_waddr(0x40);lcd_wdata('1');delaynms(500);break; } } } |
|
相关推荐
4个回答
|
|
各位大神,帮忙看一下呗,拜托了
|
|
|
|
朋友,做出来了没?能不能把你整个文件给我发一下 看一下
|
|
|
|
额。。。。,不好意思,刚看到,现在还需要吗? |
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1093 浏览 1 评论
飞凌嵌入式ElfBoard ELF 1板卡-spi编程示例之spi编写程序
607 浏览 0 评论
飞凌嵌入式-ELFBOARD 4.3吋电容触摸液晶模块简介第三期 :机械机构说明
762 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-i2c与从设备通讯编程示例之开发板测试
1440 浏览 0 评论
ubuntu ping 开发板存在严重的丢包情况,请问该怎么解决?
2708 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-11 05:59 , Processed in 0.621708 second(s), Total 77, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号