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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1756|回復: 0
打印 上一主題 下一主題
收起左側(cè)

求助 單片機16LED花樣流水燈改程序

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:471297 發(fā)表于 2021-12-20 10:46 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
求助 16LED花樣流水燈改程序 ,源程序有9種模式,還有數(shù)碼管顯示模式,現(xiàn)在需要修改為只保留模式2效果(往返交替顯示),不需要數(shù)碼管顯示模式,16LED增加到24LED,調(diào)速需要保留,望大神幫幫往返交替顯示效果:


單片機源程序如下:
  1. #include <REG52.H>

  2. unsigned char RunMode;
  3. //**********************************System Fuction*************************************************
  4. void Delay1ms(unsigned int count)
  5. {
  6.         unsigned int i,j;
  7.         for(i=0;i<count;i++)
  8.         for(j=0;j<120;j++);
  9. }

  10. unsigned char code LEDDisplayCode[] = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,        //0~7
  11.                                                           0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF};

  12. void Display(unsigned char Value)
  13. {
  14.         P3 = LEDDisplayCode[Value];
  15. }

  16. void LEDFlash(unsigned char Count)
  17. {
  18.         unsigned char i;
  19.         bit Flag;
  20.         for(i = 0; i<Count;i++)
  21.         {
  22.                 Flag = !Flag;
  23.                 if(Flag)
  24.                         Display(RunMode);
  25.                 else
  26.                         Display(0x10);
  27.                 Delay1ms(100);
  28.         }
  29.         Display(RunMode);
  30. }

  31. unsigned char GetKey(void)
  32. {
  33.         unsigned char KeyTemp,CheckValue,Key = 0x00;
  34.         CheckValue = P2&0x32;
  35.         if(CheckValue==0x32)
  36.                 return 0x00;
  37.         
  38.         Delay1ms(10);
  39.         KeyTemp = P2&0x32;
  40.         if(KeyTemp==CheckValue)
  41.                 return 0x00;

  42.         if(!(CheckValue&0x02))
  43.                 Key|=0x01;
  44.         if(!(CheckValue&0x10))
  45.                 Key|=0x02;
  46.         if(!(CheckValue&0x20))
  47.                 Key|=0x04;
  48.         return Key;
  49. }

  50. unsigned int TimerCount,SystemSpeed,SystemSpeedIndex;
  51. void InitialTimer2(void)
  52. {
  53.         T2CON  = 0x00;                        //16 Bit Auto-Reload Mode
  54.          TH2 = RCAP2H = 0xFC;          //重裝值,初始值        TL2 = RCAP2L = 0x18;
  55.         ET2=1;                                        //定時器 2 中斷允許
  56.         TR2 = 1;                                //定時器 2 啟動
  57.         EA=1;
  58. }

  59. unsigned int code SpeedCode[]={   1,   2,   3,   5,   8,  10,  14,  17,  20,  30,
  60.                                                              40,  50,  60,  70,  80,  90, 100, 120, 140, 160,
  61.                                                                 180, 200, 300, 400, 500, 600, 700, 800, 900,1000};//30
  62. void SetSpeed(unsigned char Speed)
  63. {
  64.         SystemSpeed =SpeedCode[Speed];
  65. }

  66. void LEDShow(unsigned int LEDStatus)
  67. {
  68.         P1 = ~(LEDStatus&0x00FF);
  69.         P0 = ~((LEDStatus>>8)&0x00FF);
  70. }

  71. void InitialCPU(void)
  72. {
  73.         RunMode = 0x00;
  74.         TimerCount = 0;
  75.         SystemSpeedIndex = 10;

  76.         P1 = 0x00;
  77.         P0 = 0x00;
  78.         P2 = 0xFF;
  79.         P3 = 0x00;
  80.         Delay1ms(500);
  81.         P1 = 0xFF;
  82.         P0 = 0xFF;
  83.         P2 = 0xFF;
  84.         P3 = 0xFF;
  85.         SetSpeed(SystemSpeedIndex);
  86.         Display(RunMode);
  87. }

  88. //Mode 0
  89. unsigned int LEDIndex = 0;
  90. bit LEDDirection = 1,LEDFlag = 1;
  91. void Mode_0(void)
  92. {
  93.         LEDShow(0x0001<<LEDIndex);
  94.         LEDIndex = (LEDIndex+1)%16;
  95. }
  96. //Mode 1
  97. void Mode_1(void)
  98. {
  99.         LEDShow(0x8000>>LEDIndex);
  100.         LEDIndex = (LEDIndex+1)%16;
  101. }
  102. //Mode 2
  103. void Mode_2(void)
  104. {
  105.         if(LEDDirection)
  106.                 LEDShow(0x0001<<LEDIndex);
  107.         else
  108.                 LEDShow(0x8000>>LEDIndex);
  109.         if(LEDIndex==15)
  110.                 LEDDirection = !LEDDirection;
  111.    LEDIndex = (LEDIndex+1)%16;
  112. }
  113. //Mode 3
  114. void Mode_3(void)
  115. {
  116.         if(LEDDirection)
  117.                 LEDShow(~(0x0001<<LEDIndex));
  118.         else
  119.                 LEDShow(~(0x8000>>LEDIndex));
  120.         if(LEDIndex==15)
  121.                 LEDDirection = !LEDDirection;
  122.    LEDIndex = (LEDIndex+1)%16;
  123. }

  124. //Mode 4
  125. void Mode_4(void)
  126. {
  127.         if(LEDDirection)
  128.         {
  129.                 if(LEDFlag)
  130.                         LEDShow(0xFFFE<<LEDIndex);
  131.                    else
  132.                         LEDShow(~(0x7FFF>>LEDIndex));
  133.         }
  134.         else
  135.         {
  136.                 if(LEDFlag)
  137.                         LEDShow(0x7FFF>>LEDIndex);
  138.                 else
  139.                         LEDShow(~(0xFFFE<<LEDIndex));
  140.         }
  141.         if(LEDIndex==15)
  142.         {
  143.                 LEDDirection = !LEDDirection;
  144.                 if(LEDDirection)        LEDFlag = !LEDFlag;
  145.         }
  146.            LEDIndex = (LEDIndex+1)%16;
  147. }

  148. //Mode 5
  149. void Mode_5(void)
  150. {
  151.         if(LEDDirection)
  152.                 LEDShow(0x000F<<LEDIndex);
  153.         else
  154.                 LEDShow(0xF000>>LEDIndex);
  155.         if(LEDIndex==15)
  156.                 LEDDirection = !LEDDirection;
  157.     LEDIndex = (LEDIndex+1)%16;
  158. }

  159. //Mode 6
  160. void Mode_6(void)
  161. {
  162.         if(LEDDirection)
  163.                 LEDShow(~(0x000F<<LEDIndex));
  164.         else
  165.                 LEDShow(~(0xF000>>LEDIndex));
  166.         if(LEDIndex==15)
  167.                 LEDDirection = !LEDDirection;
  168.            LEDIndex = (LEDIndex+1)%16;
  169. }

  170. //Mode 7
  171. void Mode_7(void)
  172. {
  173.         if(LEDDirection)
  174.                 LEDShow(0x003F<<LEDIndex);
  175.         else
  176.                 LEDShow(0xFC00>>LEDIndex);
  177.         if(LEDIndex==9)
  178.                 LEDDirection = !LEDDirection;
  179.     LEDIndex = (LEDIndex+1)%10;
  180. }

  181. //Mode 8
  182. void Mode_8(void)
  183. {
  184.         LEDShow(++LEDIndex);
  185. }

  186. void TimerEventRun(void)
  187. {
  188.         if(RunMode==0x00)
  189.         {
  190.                 Mode_0();        
  191.         }
  192.         else if(RunMode ==0x01)
  193.         {
  194.                 Mode_1();
  195.         }
  196.         else if(RunMode ==0x02)
  197.         {
  198.                 Mode_2();
  199.         }
  200.         else if(RunMode ==0x03)
  201.         {
  202.                 Mode_3();
  203.         }
  204.         else if(RunMode ==0x04)
  205.         {
  206.                 Mode_4();
  207.         }
  208.         else if(RunMode ==0x05)
  209.         {
  210.                 Mode_5();
  211.         }
  212.         else if(RunMode ==0x06)
  213.         {
  214.                 Mode_6();
  215.         }
  216.         else if(RunMode ==0x07)
  217.         {
  218.                 Mode_7();
  219.         }
  220.         else if(RunMode ==0x08)
  221.         {
  222.                 Mode_8();
  223.         }
  224. }

  225. void Timer2(void) interrupt 5 using 3
  226. {
  227.         TF2 = 0;         //中斷標志清除( Timer2 必須軟件清標志!)
  228.         if(++TimerCount>=SystemSpeed)
  229.         {
  230.                 TimerCount = 0;
  231.                 TimerEventRun();
  232.            }
  233. }
  234. unsigned char MusicIndex = 0;
  235. void KeyDispose(unsigned char Key)
  236. {
  237.         if(Key&0x01)
  238.         {
  239.                 LEDDirection = 1;
  240.                 LEDIndex = 0;
  241.                 LEDFlag = 1;
  242.                 RunMode = (RunMode+1)%9;
  243.                 Display(RunMode);
  244.         }
  245.         if(Key&0x02)
  246.         {
  247.                 if(SystemSpeedIndex>0)
  248.                 {
  249.                         --SystemSpeedIndex;
  250.                         SetSpeed(SystemSpeedIndex);
  251.                 }
  252.                 else
  253.                 {
  254.                         LEDFlash(6);
  255.                 }
  256.         }
  257.         if(Key&0x04)
  258.         {
  259.                 if(SystemSpeedIndex<28)
  260.                 {
  261.                         ++SystemSpeedIndex;
  262.                         SetSpeed(SystemSpeedIndex);
  263.                 }
  264.                 else
  265.                 {
  266.                         LEDFlash(6);
  267.                 }
  268.         }        
  269. }

  270. //***********************************************************************************
  271. main()
  272. {
  273.         unsigned char Key;
  274.         InitialCPU();
  275.         InitialTimer2();

  276.         while(1)
  277.         {
  278.                 Key = GetKey();
  279.                 if(Key!=0x00)
  280.                 {
  281.                         KeyDispose(Key);
  282.                 }
  283.         }
  284. }
復制代碼


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

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品欧美一区二区三区不卡 | 求毛片| 亚洲一一在线 | 日韩欧美中文字幕在线观看 | av在线播放网 | 国产高清一区二区三区 | 精品久久影院 | 中文字幕一区二区三区精彩视频 | 免费99精品国产自在在线 | 精品粉嫩aⅴ一区二区三区四区 | 色约约视频 | 久久久蜜臀国产一区二区 | 日韩成人精品在线 | 喷潮网站| 精品国产亚洲一区二区三区大结局 | 亚洲福利在线观看 | 亚洲在线免费 | 久久久免费毛片 | 操久久| 99国产精品99久久久久久 | 亚洲国产成人精品女人久久久 | 青青草一区二区 | 二区国产 | 久久噜| 一区二区三区在线免费观看 | 久久国产欧美日韩精品 | 国产精品视频一区二区三区四蜜臂 | 久久青 | 成人a视频片观看免费 | 黄色毛片免费看 | 久久久久免费精品国产 | 欧美一级大片免费看 | 日本三级全黄三级三级三级口周 | 一区二区三区视频 | 国产欧美精品一区二区色综合朱莉 | 青青草社区 | 免费一级片 | 国产精品美女一区二区 | 国产成都精品91一区二区三 | 久久一视频 | 亚洲国产aⅴ成人精品无吗 欧美激情欧美激情在线五月 |