找回密码
 注册

QQ登录

只需一步,快速开始

搜索

51单片机控制条形LED程序和Proteus仿真文件

[复制链接]
coolfire 发表于 2021-5-6 01:00:26 | 显示全部楼层 |阅读模式
1.png
部分代码:
  1. #include <reg52.h>
  2. #include <intrins.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int

  5. uchar code DSY_CODE[]=
  6. {
  7.         0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x00
  8. };
  9. uchar code KeyCodeTable[]=
  10. {
  11.           0x11,0x12,0x14,0x18,0x21,0x22,0x24,0x28,0x41,0x42,0x44,0x48,0x81,0x82,0x84,0x88
  12. };

  13. void Delay()
  14. {
  15.         uchar i;
  16.         for(i=0;i<200;i++);
  17. }

  18. uchar Keys_Scan()
  19. {
  20.         uchar sCode,kCode,i,k;
  21.         P1 = 0xf0;
  22.         if((P1&0xf0)!=0xf0)
  23.         {
  24.                  Delay();
  25.                 if((P1&0xf0)!=0xf0)
  26.                 {
  27.                          sCode = 0xfe;
  28.                         for(k=0;k<4;k++)
  29.                         {
  30.                                  P1 = sCode;
  31.                                 if((P1&0xf0)!=0xf0)
  32.                                 {
  33.                                          kCode = ~P1;
  34.                                         for(i=0;i<16;i++)
  35.                                         {
  36.                                                  if(kCode == KeyCodeTable[i])
  37.                                                         return i;
  38.                                         }
  39.                                 }
  40.                                 else
  41.                                         sCode = _crol_(sCode,1);
  42.                         }
  43.                 }
  44.         }
  45.         return -1;
  46. }
复制代码
完整单片机c代码和仿真文件: 4×4键盘矩阵控制条形LED显示.zip (53.38 KB, 售价: 2 E币)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-3-29 19:46

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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