標(biāo)題: 單片機(jī)實現(xiàn)一個按鈕對一個燈的控制 Proteus仿真代碼 [打印本頁]

作者: QWERRQT    時間: 2022-3-11 16:24
標(biāo)題: 單片機(jī)實現(xiàn)一個按鈕對一個燈的控制 Proteus仿真代碼
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  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.                        
復(fù)制代碼

Keil代碼與Proteus仿真下載:
新建 51hei壓縮 ZIP 文件.zip (31.42 KB, 下載次數(shù): 13)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1