找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

1602键盘扫描求助!!!!

[复制链接]
admin 发表于 2012-9-2 05:12:01 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
4*4矩阵键盘+1602液晶显示;
#include<reg52.h>
#include<stdio.h>
#include<string.h>
#include"diy.h"
bit time_flag=0;
uint8 const dofly[]="0123456789abcdef";
unsigned char const dofly1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71};//0-F
uint8 Read_busy();
void delay(unsigned int z);
uint8 Key_Scan();
uint8 key_Dis();
sbit jp=P2^1;
sbit RS=P2^4;
sbit RW=P2^5;
sbit E=P2^6;
void Write_Com(unsigned char Com)
{
E=0;
RS=0;
RW=0;
delay(4);
E=1;
PORT0=Com;
E=0;
}
void Write_Dat(unsigned char Dat)
{
E=0;
RS=1;
RW=0;
delay(4);
E=1;
PORT0=Dat;
E=0;
}
uint8 Read_busy()
{ unsigned char dat;
E=0;
RS=0;
RW=1;
//E=0;
delay(3);
E=1;
dat=PORT0;
E=0;
return dat;

}
void delay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}

void Init()
{
delay(3);
Write_Com(0x38);//设置1602显示
delay(3);
Write_Com(0x0e);//开显示显示光标、光标闪烁
Write_Com(0x06);//当读一个字符后。地址指针加一,且光标加一
Write_Com(0x0c);//不显示光标
Write_Com(0x01);//清屏
TMOD=0X01;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
EA=1;
ET0=1;
TR0=1;

}
uint8 Key_Scan()
{
uint8 key_value,value_l,value_r;
PORT3=0XF0;
value_l=PORT3&0XF0;
if((value_l)!=0xf0)
{
delay(100);
if((value_l)!=0XF0)
{
value_l=PORT3&0XF0;
PORT3=value_l|0X0F;
value_r=0x0f&PORT3;
key_value=value_l|value_r;

return key_value;
}

}
return 0xff;
}
uint8 key_Dis(uint8 key)
{
uint8 key_number;
key=Key_Scan;
switch(key)
{
case 0x7e: key_number=dofly[0];P0=dofly1[0];break;
case 0x7d: key_number=dofly[1];P0=dofly1[1];break;
case 0x7b: key_number=dofly[2];P0=dofly1[2];break;
case 0x77: key_number=dofly[3];P0=dofly1[3];break;
case 0xbe: key_number=dofly[4];P0=dofly1[4];break;
case 0xbd: key_number=dofly[5];P0=dofly1[5];break;
case 0xbb: key_number=dofly[6];P0=dofly1[6];break;
case 0xb7: key_number=dofly[7];P0=dofly1[7];break;
case 0xde: key_number=dofly[8];P0=dofly1[8];break;
case 0xdd: key_number=dofly[9];P0=dofly1[9];break;
case 0xdb: key_number=dofly[10];P0=dofly1[10];break;
case 0xd7: key_number=dofly[11];P0=dofly1[11];break;
case 0xee: key_number=dofly[12];P0=dofly1[12];break;
case 0xed: key_number=dofly[13];P0=dofly1[13];break;
case 0xeb: key_number=dofly[14];P0=dofly1[14];break;
case 0xe7: key_number=dofly[15];P0=dofly1[15];break;

default :key_number=' ';break;
}
return key_number;
}
void main()
{
uint8 key,key_number,busy,com;
com=0x80+1;
if(time_flag==1)
{
time_flag=0;
key=Key_Scan();
jp=0;
key_number=key_Dis(key);
Init();
delay(1);
busy=Read_busy();
busy=busy&0x80;

if(busy!=0x80)
{
delay(1);
Write_Com(com++);
delay(1);
Write_Dat(key_number);
if(com>0x90)
{
com=0x80+1;
Write_Com(0x01);//清屏
}

}
else
{
delay(1);
busy=Read_busy();
}
}
}

void time0() interrupt 1
{
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
time_flag=1;

}
我使用的是STC89c54单片机,晶振为12m,
下面是我板子的硬件原理图,还希望各位指点!!!!!


5_143438_1619dd4f4e6a456.jpg 5_143438_761addf1adab0f7.jpg 5_143438_696d9f42acdff00.jpg 5_143438_24b6d3ef51efcd8.jpg
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-23 23:06 , Processed in 0.063722 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表