标题: 键盘的录入和显示 [打印本页]

作者: as534246057    时间: 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. }
复制代码







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1