找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3710|回复: 0
打印 上一主题 下一主题
收起左侧

单片机行列式键盘输入实验

[复制链接]
跳转到指定楼层
楼主
ID:72519 发表于 2015-1-21 23:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
是用51hei单片机开发板 电路图详见:http://www.51hei.com/f/51hei-5.pdf  的数码管部分, 用2个74hc573 锁存,p0口作为数据口 ,注意图中要改一下p3.6和p3.7分别是段和位的锁存端口.P2口上面是按键,p1口上面是8个led灯.
  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uchar code DIS_SEG7[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
  5. uchar code DIS_BIT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
  6. uchar code SKEY[16]={1,2,3,10,4,5,6,11,7,8,9,12,14,0,15,13};
  7. uchar code act[4]={0xfe,0xfd,0xfb,0xf7};
  8. sbit D=P3^6;
  9. sbit V=P3^7;
  10. //=======================
  11. void delay(uint k)
  12. {
  13. uint data i,j;
  14. for(i=0;i<k;i++){
  15. for(j=0;j<121;j++)
  16. {;}}
  17. }
  18. //==============
  19. char scan_key(void)
  20. {
  21. uchar i,j,in,ini,inj;
  22. bit find=0;
  23. for(i=0;i<4;i++)
  24. {
  25. P1=act[i];
  26. delay(10);
  27. in=P1;
  28. in=in>>4;
  29. in=in|0xf0;
  30. for(j=0;j<4;j++)
  31. {
  32. if(act[j]==in)
  33. {find=1;
  34. inj=j;ini=i;
  35.        }
  36. }
  37.   }
  38. if(find==0)return-1;
  39. return (ini*4+inj);
  40. }
  41. //===============
  42. void main(void)
  43. {uchar c;
  44. uchar key_value;
  45. while(1)
  46. {
  47. c=scan_key();
  48. if(c!=-1)key_value=SKEY[c];
  49. D=1;P0=DIS_SEG7[key_value];D=0;V=1;P0=DIS_BIT[0];V=0;delay(2);
  50.     }
  51. }
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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