独立键盘和矩阵键盘中断和查询_第1页
独立键盘和矩阵键盘中断和查询_第2页
独立键盘和矩阵键盘中断和查询_第3页
独立键盘和矩阵键盘中断和查询_第4页
独立键盘和矩阵键盘中断和查询_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、独立键盘中断:#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit we = P27;sbit du = P26;sbit S2 = P30;sbit S3 = P31;sbit S4 = P32;sbit S5 = P33; uchar code leddata= 0x3F, /"0" 0x06, /"1" 0x5B, /"2" 0x4F, /"3" 0x66, /"4" 0x6D, /&

2、quot;5" 0x7D, /"6" 0x07, /"7" 0x7F, /"8" 0x6F, /"9" 0x77, /"A" 0x7C, /"B" 0x39, /"C" 0x5E, /"D" 0x79, /"E" 0x71, /"F" ;void delay(uint z)uint x,y;for(x = z; x > 0; x-)for(y = 114; y > 0 ; y

3、-);void delay1s(void)unsigned char a,b,c,d;for(a = 5; a > 0; a-)for(b = 4; b > 0; b-)for(c = 116; c > 0; c-)for(d = 214; d > 0; d-);void main ()TMOD = 0x01; /配置定时器0工作于方式一TH1 =(65536-50000)/256; /高八位装入初值TL1 = (65536-50000)%256; /低八位装入初值ET0 = 1; /开定时器0中断EA = 1; /开总中断TR0 = 1; /启动定时器0delay1s

4、();while(1)we = 1;/打开位选P0 = 0xfc;/八位数码管低两位we = 0;/锁存位选du = 1;/打开段选端P0 = leddata15;while(1)if(S2 = 0)delay(5);/软件消抖if(S2 = 0)P0 = leddata0;while( !S2 );/松手检测if(S3 = 0)delay(5);/软件消抖if(S3 = 0)P0 = leddata1;while( !S3 );/松手检测if(S4 = 0)delay(5);/软件消抖if(S4 = 0)P0 = leddata2;while( !S4 );/松手检测if(S5 = 0)de

5、lay(5);/软件消抖 if(S5 = 0)P0 = leddata3;while( !S5 );/松手检测void Timer0_int() interrupt 1 /重新装初值TH1 = (65536-50000)/256; /高八位装入初值TL1 = (65536-50000)%256; /低八位装入初值 矩阵键盘中断:#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit we = P27;sbit du = P26;uchar code leddata= 0x3F, /"

6、;0" 0x06, /"1" 0x5B, /"2" 0x4F, /"3" 0x66, /"4" 0x6D, /"5" 0x7D, /"6" 0x07, /"7" 0x7F, /"8" 0x6F, /"9" 0x77, /"A" 0x7C, /"B" 0x39, /"C" 0x5E, /"D" 0x79, /"E&quo

7、t; 0x71, /"F" ;void delay(uint z)uint x,y;for(x = z; x > 0; x-)for(y = 114; y > 0 ; y-);void delay1s(void)unsigned char a,b,c,d;for(a = 5; a > 0; a-)for(b = 4; b > 0; b-)for(c = 116; c > 0; c-)for(d = 214; d > 0; d-);uchar KeyScan()/带返回值的子函数uchar cord_l,cord_h;/声明列线和行线的值的

8、储存变量P3 = 0xf0;/1111 0000delay1s();if( (P3 & 0xf0) != 0xf0)/判断是否有按键按下delay(5);/软件消抖if( (P3 & 0xf0) != 0xf0)/判断是否有按键按下 cord_l = P3 & 0xf0;/ 储存列线值 P3 = cord_l | 0x0f; cord_h = P3 & 0x0f;/ 储存行线值 while( (P3 & 0x0f) != 0x0f );/松手检测 return (cord_l + cord_h);/返回键值码void KeyPro()switch( Ke

9、yScan() ) /第一行键值码case 0xee: P0 = leddata0;break;case 0xde: P0 = leddata1;break;case 0xbe: P0 = leddata2;break;case 0x7e: P0 = leddata3;break;/第二行键值码case 0xed: P0 = leddata4;break;case 0xdd: P0 = leddata5;break;case 0xbd: P0 = leddata6;break;case 0x7d: P0 = leddata7;break;/第三行键值码case 0xeb: P0 = ledda

10、ta8;break;case 0xdb: P0 = leddata9;break;case 0xbb: P0 = leddata10;break;case 0x7b: P0 = leddata11;break;/第四行键值码case 0xe7: P0 = leddata12;break;case 0xd7: P0 = leddata13;break;case 0xb7: P0 = leddata14;break;case 0x77: P0 = leddata15;break;void main ()TMOD = 0x01; /配置定时器0工作于方式一TH1 =(65536-50000)/256

11、; /高八位装入初值TL1 = (65536-50000)%256; /低八位装入初值ET0 = 1; /开定时器0中断EA = 1; /开总中断TR0 = 1; /启动定时器0while(1)we = 1;/打开位选P0 = 0xfc;/八位数码管低两位we = 0;/锁存位选du = 1;/打开段选端P0 = leddata0;while(1)KeyPro();/提取键值码并且送不同数值给数码管显示void Timer0_int() interrupt 1 /重新装初值TH1 = (65536-50000)/256; /高八位装入初值TL1 = (65536-50000)%256; /低八

12、位装入初值 矩阵查询#include <reg52.h>#define uchar unsigned char#define uint unsigned intsbit we = P27;sbit du = P26;uchar code leddata= 0x3F, /"0" 0x06, /"1" 0x5B, /"2" 0x4F, /"3" 0x66, /"4" 0x6D, /"5" 0x7D, /"6" 0x07, /"7"

13、; 0x7F, /"8" 0x6F, /"9" 0x77, /"A" 0x7C, /"B" 0x39, /"C" 0x5E, /"D" 0x79, /"E" 0x71, /"F" 0x76, /"H" 0x38, /"L" 0x37, /"n" 0x3E, /"u" 0x73, /"P" 0x5C, /"o" 0x40

14、, /"-" 0x00, /熄灭 0x00 /自定义 ;void delay10ms(void)unsigned char i,j,k;for(i = 5; j > 0; i-)for(j = 4; j > 0; j-)for(k = 248; k > 0; k-);void delay1s(void)unsigned char a,b,c,d;for(a = 5; a > 0; a-)for(b = 4; b > 0; b-)for(c = 116; c > 0; c-)for(d = 214; d > 0; d-);uchar

15、KeyScan()/带返回值的子函数unsigned char p;uchar cord_l,cord_h;/声明列线和行线的值的储存变量P3 = 0xf0;/1111 0000delay1s();if( (P3 & 0xf0) != 0xf0)/判断是否有按键按下delay10ms();/软件消抖if( (P3 & 0xf0) != 0xf0)/判断是否有按键按下 cord_l = P3 & 0xf0;/ 储存列线值 P3 = cord_l | 0x0f; cord_h = P3 & 0x0f;/ 储存行线值 while( (P3 & 0x0f) !=

16、 0x0f );/松手检测 return (cord_l + cord_h);/返回键值码void KeyPro()switch( KeyScan() ) /第一行键值码case 0xee: P0 = leddata0;break;case 0xde: P0 = leddata1;break;case 0xbe: P0 = leddata2;break;case 0x7e: P0 = leddata3;break;/第二行键值码case 0xed: P0 = leddata4;break;case 0xdd: P0 = leddata5;break;case 0xbd: P0 = leddat

17、a6;break;case 0x7d: P0 = leddata7;break;/第三行键值码case 0xeb: P0 = leddata8;break;case 0xdb: P0 = leddata9;break;case 0xbb: P0 = leddata10;break;case 0x7b: P0 = leddata11;break;/第四行键值码case 0xe7: P0 = leddata12;break;case 0xd7: P0 = leddata13;break;case 0xb7: P0 = leddata14;break;case 0x77: P0 = leddata1

18、5;break;void main()we = 1;/打开位选P0 = 0;/八位数码管全显示we = 0;/锁存位选du = 1;/打开段选端P0 = leddata22;while(1) KeyPro();/提取键值码并且送不同数值给数码管显示独立查询#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit we = P27;sbit du = P26;sbit S2 = P30;sbit S3 = P31;sbit S4 = P32;sbit S5 = P33; uchar code l

19、eddata= 0x3F, /"0" 0x06, /"1" 0x5B, /"2" 0x4F, /"3" 0x66, /"4" 0x6D, /"5" 0x7D, /"6" 0x07, /"7" 0x7F, /"8" 0x6F, /"9" 0x77, /"A" 0x7C, /"B" 0x39, /"C" 0x5E, /"D" 0x79, /"E" 0x71, /&qu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论