久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: 單片機4*4矩陣鍵盤按鍵控制led燈的程序及仿真 [打印本頁]

作者: 51黑ff    時間: 2016-9-27 20:17
標題: 單片機4*4矩陣鍵盤按鍵控制led燈的程序及仿真
通過1-8按鍵顯示逐個燈亮一個。9全滅。。10左移一位依次類推。。。這是一個簡單的單片機例子,下面是仿真原理圖:

所有資料打包下載: 4乘4按鍵控制燈.zip (52.31 KB, 下載次數: 79)

原理圖:
  1. #include <reg52.h>
  2. #include<intrins.h>
  3. typedef  unsigned char   int8;
  4. typedef  unsigned int    int16;

  5. sbit KeyIn1  = P1^0;
  6. sbit KeyIn2  = P1^1;
  7. sbit KeyIn3  = P1^2;
  8. sbit KeyIn4  = P1^3;
  9. sbit KeyOut1 = P1^4;
  10. sbit KeyOut2 = P1^5;
  11. sbit KeyOut3 = P1^6;
  12. sbit KeyOut4 = P1^7;

  13. void delay(void);
  14. void delay1s(void)   
  15. {
  16.     unsigned char a,b,c;
  17.     for(c=167;c>0;c--)
  18.         for(b=171;b>0;b--)
  19.             for(a=16;a>0;a--);
  20.                         }

  21. main()
  22. {        int8 i;
  23.         P0 = 0xFF;
  24.         while (1)
  25.         {
  26.                 KeyOut1 = 0;
  27.                 KeyOut2 = 1;
  28.                 KeyOut3 = 1;
  29.                 KeyOut4 = 1;
  30.                 if(KeyIn1 == 0)
  31.                 {
  32.                         delay();
  33.                         if(KeyIn1 == 0)
  34.                          { i=0 ;P0 = 0xfe;  }
  35.                 }
  36.                 if(KeyIn2 == 0)
  37.                 {
  38.                         delay();
  39.                         if(KeyIn2 == 0)
  40.                           { i=0 ; P0 = 0xe0;}
  41.                 }
  42.                 if(KeyIn3 == 0)
  43.                 {
  44.                         delay();
  45.                         if(KeyIn3 == 0)
  46.                         { i=0 ; P0=0Xff; }
  47.                         
  48.                 }        
  49.                 if(KeyIn4 == 0)
  50.                 {
  51.                         delay();
  52.                         if(KeyIn4 == 0)
  53.                           {i=1;P0=0XF0;}
  54.                 }
  55.                 while((KeyIn1 == 0)||(KeyIn2 == 0)||
  56.                       (KeyIn3 == 0)||(KeyIn4 == 0));
  57.                
  58.                 KeyOut1 = 1;
  59.                 KeyOut2 = 0;
  60.                 KeyOut3 = 1;
  61.                 KeyOut4 = 1;
  62.                 if(KeyIn1 == 0)
  63.                 {
  64.                         delay();
  65.                         if(KeyIn1 == 0)
  66.                          { i=0 ;  P0 = 0xfc;   }
  67.                 }
  68.                 if(KeyIn2 == 0)
  69.                 {
  70.                         delay();
  71.                         if(KeyIn2 == 0)
  72.                          { i=0 ;  P0 = 0xc0; }
  73.                 }
  74.                 if(KeyIn3 == 0)
  75.                 {
  76.                         delay();
  77.                         if(KeyIn3 == 0)
  78.                          {  i=1;  P0=0XFE;}
  79.                 }        
  80.                 if(KeyIn4 == 0)
  81.                 {
  82.                         delay();
  83.                         if(KeyIn4 == 0)
  84.                            {i=1;P0=0XE0;}
  85.                 }
  86.                 while((KeyIn1 == 0)||(KeyIn2 == 0)||
  87.                       (KeyIn3 == 0)||(KeyIn4 == 0));

  88.                 KeyOut1 = 1;
  89.                 KeyOut2 = 1;
  90.                 KeyOut3 = 0;
  91.                 KeyOut4 = 1;
  92.                 if(KeyIn1 == 0)
  93.                 {
  94.                         delay();
  95.                         if(KeyIn1 == 0)
  96.                         { i=0 ;   P0 = 0xf8;  }
  97.                 }
  98.                 if(KeyIn2 == 0)
  99.                 {
  100.                         delay();
  101.                         if(KeyIn2 == 0)
  102.                         { i=0 ;   P0 = 0x80; }
  103.                 }
  104.                 if(KeyIn3 == 0)
  105.                 {
  106.                         delay();
  107.                         if(KeyIn3 == 0)
  108.                           {i=1;P0=0XFC;}
  109.                 }        
  110.                 if(KeyIn4 == 0)
  111.                 {
  112.                         delay();
  113.                         if(KeyIn4 == 0)
  114.                             {i=1;P0=0XC0;}
  115.                 }
  116.                 while((KeyIn1 == 0)||(KeyIn2 == 0)||
  117.                       (KeyIn3 == 0)||(KeyIn4 == 0));

  118.                 KeyOut1 = 1;
  119.                 KeyOut2 = 1;
  120.                 KeyOut3 = 1;
  121.                 KeyOut4 = 0;
  122.                 if(KeyIn1 == 0)
  123.                 {
  124.                         delay();
  125.                         if(KeyIn1 == 0)
  126.                          { i=0 ;   P0 = 0xf0; }
  127.                 }
  128.                 if(KeyIn2 == 0)
  129.                 {
  130.                         delay();
  131.                         if(KeyIn2 == 0)
  132.                           { i=0 ;  P0 = 0x00;}
  133.                 }
  134.                 if(KeyIn3 == 0)
  135.                 {
  136.                         delay();
  137.                         if(KeyIn3 == 0)
  138.                         {i=1;P0=0XF8;}
  139.                 }        
  140.                 if(KeyIn4 == 0)
  141.                 {
  142.                         delay();
  143.                         if(KeyIn4 == 0)
  144.                           {i=1;P0=0X80;}
  145.                 }
  146.                
  147.            while((KeyIn1 == 0)||(KeyIn2 == 0)||
  148.                       (KeyIn3 == 0)||(KeyIn4 == 0));
  149.                 switch(i)
  150.                 {        case 0: P0=P0;break;
  151.                         case 1: P0=_crol_(P0,1);delay1s(); break;
  152.                
  153.                         default:
  154.                           P0=0XFF;

  155.                
  156.                 }
  157.                
  158.         }
  159. }

  160. void delay(void)
  161. {
  162.         int16 i=500;

  163.         while (i--);

  164. }
復制代碼







作者: lehigh    時間: 2016-12-1 23:19
感謝分享,學習到了
作者: devlinFan    時間: 2017-5-14 12:42
謝謝分享
作者: ffhbfy    時間: 2020-12-24 20:28
有沒有詳細解釋??
作者: ffhbfy    時間: 2020-12-24 20:31
求大神解釋代碼
作者: g'f'yeu'y    時間: 2021-4-19 14:45
代碼有注釋嗎?




歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 欧美bondage紧缚视频 | 久久五月婷 | 亚洲精品综合 | 欧美三级视频在线观看 | 亚洲一区二区久久 | 久久免费视频在线 | 噜噜噜噜狠狠狠7777视频 | 亚洲成a人片 | 久久亚洲综合 | 久久精品97 | 国产一区二区三区四区在线观看 | 免费久久久久久 | 亚洲精品久久久久久久久久久 | 91久久综合| 欧州一区二区三区 | 久久小视频 | 久久久精品在线 | 97精品国产97久久久久久免费 | 欧美日韩不卡合集视频 | 澳门永久av免费网站 | 日本人做爰大片免费观看一老师 | 天天躁日日躁狠狠躁2018小说 | 91精品国产91久久久久久最新 | 盗摄精品av一区二区三区 | 日韩成人中文字幕 | 97人人超碰| 国产综合在线视频 | 综合国产第二页 | 亚洲视频在线看 | 女朋友的闺蜜3韩国三级 | www性色 | 国产精品成人国产乱 | 免费看黄色小视频 | 色综合区| 九九热九九 | 国产视频中文字幕 | 欧美成人a∨高清免费观看 欧美日韩中 | av在线天堂网 | 日韩字幕 | 国产精品不卡视频 | 亚洲精品9999|