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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 12425|回復(fù): 5
打印 上一主題 下一主題
收起左側(cè)

單片機(jī)4*4矩陣鍵盤按鍵控制led燈的程序及仿真

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:137190 發(fā)表于 2016-9-27 20:17 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
通過1-8按鍵顯示逐個燈亮一個。9全滅。。10左移一位依次類推。。。這是一個簡單的單片機(jī)例子,下面是仿真原理圖:

所有資料打包下載: 4乘4按鍵控制燈.zip (52.31 KB, 下載次數(shù): 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. }
復(fù)制代碼






分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:110866 發(fā)表于 2016-12-1 23:19 | 只看該作者
感謝分享,學(xué)習(xí)到了
回復(fù)

使用道具 舉報

板凳
ID:159790 發(fā)表于 2017-5-14 12:42 | 只看該作者
謝謝分享
回復(fù)

使用道具 舉報

地板
ID:867353 發(fā)表于 2020-12-24 20:28 來自手機(jī) | 只看該作者
有沒有詳細(xì)解釋??
回復(fù)

使用道具 舉報

5#
ID:867353 發(fā)表于 2020-12-24 20:31 來自手機(jī) | 只看該作者
求大神解釋代碼
回復(fù)

使用道具 舉報

6#
ID:896773 發(fā)表于 2021-4-19 14:45 | 只看該作者
代碼有注釋嗎?
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 日韩成人免费视频 | 精品国产不卡一区二区三区 | 黄色网址av | 亚洲精品久久区二区三区蜜桃臀 | 香蕉视频在线播放 | 麻豆亚洲 | 黄色大片免费播放 | 亚洲一区二区三区免费在线观看 | 国产成人综合在线 | 最新国产精品 | 国产一区二区在线播放视频 | 欧美成人免费在线视频 | 亚洲精品一区二区 | 欧美视频三级 | 欧美亚洲激情 | 岛国在线免费观看 | 国产精品久久久久国产a级 欧美日韩国产免费 | 中文字幕第一页在线 | 日本成人午夜影院 | 国产精品毛片一区二区三区 | 久久久国产精品视频 | 亚洲综合在线一区 | 网站国产| 日韩欧美一区二区三区四区 | 欧美激情精品久久久久久 | 天天插天天射天天干 | 成人高清在线视频 | 一区二区三区免费 | 国产精品自产拍在线观看蜜 | 国产中文视频 | 国产一区二区久久 | 日韩手机在线视频 | 国产精品明星裸体写真集 | 天天久久 | 欧美一区二区在线观看 | 日韩欧美在线免费观看 | 国产精品久久精品 | 福利久久| 日韩中出 | 久久久久网站 | 午夜资源 |