找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1791|回复: 0
收起左侧

51单片机控制条形LEDProteus仿真程序

[复制链接]
ID:891089 发表于 2021-4-30 18:04 | 显示全部楼层 |阅读模式
51hei.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. }

  47. void main()
  48. {
  49.         uchar KeyNO = -1;
  50.         uchar i,P2_LED,P3_LED;
  51.         while(1)
  52.         {
  53.                  KeyNO = Keys_Scan();
  54.                 if(KeyNO != -1)
  55.                 {
  56.                          P2_LED = 0xff;
  57.                         P3_LED = 0xff;
  58.                         for(i=0;i<=KeyNO;i++)
  59.                         {
  60.                                  if(i<8)
  61.                                         P3_LED>>=1;
  62.                                 else
  63.                                         P2_LED>>=1;
  64.                         }
  65.                         P3 = P3_LED;
  66.                         P2 = P2_LED;
  67.                 }
  68.         }
  69. }
复制代码

所有资料51hei提供下载:
4×4键盘矩阵控制条形LED显示.zip (54.05 KB, 下载次数: 16)
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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