標(biāo)題: 求一個(gè)單片機(jī)流水燈暫停程序 [打印本頁(yè)]

作者: cxy822    時(shí)間: 2023-12-22 14:03
標(biāo)題: 求一個(gè)單片機(jī)流水燈暫停程序
由于本論壇禁止直接求程序,禁止伸手黨,所以向大家請(qǐng)教一下大致的實(shí)現(xiàn)方法與思路,理清頭緒后我自己來(lái)寫(xiě)程序去實(shí)現(xiàn),謝謝大家

求一個(gè)流水燈暫停程序,51單片機(jī),30個(gè)流水燈,要求一個(gè)(或者兩個(gè))按鍵控制流水燈暫停,按下按鍵流水燈暫停,保留當(dāng)前燈亮,再次按下繼續(xù)流水,有沒(méi)有大佬給指導(dǎo)一下 .謝謝!

作者: heicad    時(shí)間: 2023-12-22 14:49
這里有你要的代碼,自己增加流水燈數(shù)量即可:http://www.torrancerestoration.com/bbs/dpj-165812-1.html
作者: cxy822    時(shí)間: 2023-12-22 20:51
heicad 發(fā)表于 2023-12-22 14:49
這里有你要的代碼,自己增加流水燈數(shù)量即可:http://www.torrancerestoration.com/bbs/dpj-165812-1.html

謝謝。我去看看
作者: wulin    時(shí)間: 2023-12-23 09:48
  1. #include <reg51.h>

  2. #define uint unsigned int
  3. #define uchar unsigned char
  4. #define ulong unsigned long

  5. sbit key=P3^7;

  6. bit sign;
  7. bit flag;
  8. uint count,count1;

  9. void Delay_ms(uint t)
  10. {
  11.         uint i,j;
  12.         for(i=t;i>0;i--)
  13.                 for(j=120;j>0;j--);
  14. }

  15. void main()
  16. {
  17.         ulong num=0xfffffffe;
  18.         P0=num;
  19.         while (1)
  20.         {
  21.                 if(!key)
  22.                 {
  23.                         if(++count>10 && !sign)
  24.                         {
  25.                                 sign=1;
  26.                                 flag=~flag;
  27.                         }
  28.                 }
  29.                 else
  30.                 {
  31.                         sign=0;
  32.                         count=0;
  33.                 }

  34.                 if(++count1>500 && flag)
  35.                 {
  36.                         count1=0;
  37.                         num=(num<<1)+0x01;
  38.                         if(num==0xbfffffff)
  39.                         {
  40.                                 num=0xfffffffe;               
  41.                         }
  42.                         P0=num;
  43.                         P1=num>>8;
  44.                         P2=num>>16;
  45.                         P3=num>>24;
  46.                 }
  47.                 Delay_ms(1);
  48.         }
  49. }
復(fù)制代碼

作者: cxy822    時(shí)間: 2023-12-23 13:23
wulin 發(fā)表于 2023-12-23 09:48

十分感謝!本人小白,還得努力向您學(xué)習(xí),祝您工作順利,事業(yè)有成!
作者: cxy822    時(shí)間: 2023-12-23 13:34
heicad 發(fā)表于 2023-12-22 14:49
這里有你要的代碼,自己增加流水燈數(shù)量即可:http://www.torrancerestoration.com/bbs/dpj-165812-1.html

謝謝




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