标题: 单片机实现一个按钮对一个灯的控制 Proteus仿真代码 [打印本页]

作者: QWERRQT    时间: 2022-3-11 16:24
标题: 单片机实现一个按钮对一个灯的控制 Proteus仿真代码
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  1. #include<reg51.h>
  2. #define uint unsigned int
  3.         #define uchar unsigned char
  4.                 uchar j;
  5.         uchar  t;
  6.         uint n;
  7.         const uchar tab[]={0xde,0xfd,0xfb,0xf7,0xef,0xbf};
  8.         void delay(uint n)
  9.         {uint i;
  10.                 for(i=0;i<n;i++);
  11.         }
  12.         void main(void)
  13.         {uchar key;
  14.                 P0=0x7f;
  15.                 P1=0xff;
  16.                 while(1)
  17.                 {while(P1==0xff);
  18.                         delay(2500);
  19.                         while(P1==0xff);
  20.                         key=P1;
  21.                         switch(key)
  22.                                 {case 0xfe: P0=tab[0];break;
  23.                                         case 0xfd: P0=tab[1];break;
  24.                                         case 0xfb:P0=tab[2];break;
  25.                                         case 0xf7: P0=tab[3];break;
  26.                                         case 0xef:P0=tab[4];break;
  27.                                         case 0xdf:P0=tab[5];break;
  28.                 }}
  29.         }
  30.                        
复制代码

Keil代码与Proteus仿真下载:
新建 51hei压缩 ZIP 文件.zip (31.42 KB, 下载次数: 13)







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