找回密码
 立即注册

QQ登录

只需一步,快速开始

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

键盘的录入和显示

[复制链接]
跳转到指定楼层
楼主
ID:440722 发表于 2018-12-6 10:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. #include <reg52.h>
  2. unsigned char code table[]={0xee,0xde,0xbe,0x7e,0xed,0xdd,0xbd,0x7d,0xeb,0xdb,0xbb,0x7b,0xe7,0xd7,0xb7,0x77};
  3. unsigned char a[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
  4. unsigned char KeyH;
  5. unsigned char KeyL;
  6. unsigned char Key;
  7. unsigned char d4;
  8. void delay(unsigned int x);
  9. void display1(unsigned char d4);
  10. #define shuma P0
  11. sbit LED_0=P1^0;
  12. sbit LED_1=P1^1;
  13. sbit LED_2=P1^2;
  14. sbit LED_3=P1^3;
  15. #define KL_0 P2&=0xf0
  16. #define KL_F P2|=0x0f
  17. #define KH_0 P2&=0x0f
  18. #define KH_F P2|=0xf0
  19. void main()
  20. {
  21.    unsigned char t;
  22.    unsigned char i;
  23.    unsigned char res;
  24.    d4=0;
  25.    while(1)
  26.    {
  27.       display1(d4);
  28.           KL_0;
  29.           t=P2&0xf0;
  30.           if(t!=0xf0)
  31.           {
  32.              KeyH=t&0xf0;
  33.                  P2=0xff;
  34.                  delay(100);
  35.                  P2&=0x0f;
  36.                  t=P2&0x0f;
  37.                  if(t!=0x0f)
  38.                  {
  39.                     KeyL=t;
  40.                         Key=KeyH|KeyL;
  41.                         for(i=0;i<16;i++)
  42.                         {
  43.                            if(table[i]==Key)
  44.                            res=i;
  45.                         }
  46.                         d4=res;
  47.                  }
  48.           }
  49.           P2=0xff;
  50.    }
  51. }
  52. void delay(unsigned int x)
  53. {
  54.    unsigned int i;
  55.    for(i=0;i<x;i++);
  56. }
  57. void display1(unsigned char d4)
  58. {
  59.    shuma=a[d4];
  60.    LED_3=0;
  61.    delay(100);
  62.    LED_3=1;
  63. }
复制代码


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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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