找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 2751|回復(fù): 0
收起左側(cè)

51單片機(jī)流水燈從左到右 源程序+電路圖

[復(fù)制鏈接]
ID:622126 發(fā)表于 2019-10-12 12:33 | 顯示全部樓層 |閱讀模式
流水燈左右走程序.docx (12.96 KB, 下載次數(shù): 7)
圖加程序
SK6$MFA$[5}BP2FSO3`19~T.png

單片機(jī)源程序如下:
  1. #include <REG52.H>
  2. void Delay1ms(unsigned int count)
  3. {
  4.     unsigned int i,j;
  5.     for(i=0;i<count;i++)
  6.     for(j=0;j<120;j++);
  7. }
  8. main()
  9. {
  10.     unsigned char LEDIndex = 0;
  11.     bit LEDDirection = 1;
  12.     while(1)【滿(mǎn)足條件執(zhí)行下面程序】
  13.     {
  14.         if(LEDDirection)
  15.             P1 = ~(0x01<<LEDIndex);【滿(mǎn)足】<<表示邏輯移位
  16.         else
  17.             P1 = ~(0x80>>LEDIndex);【不滿(mǎn)足】~表示按位取反
  18.         if(LEDIndex==7)
  19.             LEDDirection = !LEDDirection;
  20.         LEDIndex = (LEDIndex+1)%8;    【%】取余數(shù)
  21.         Delay1ms(100);
  22.     }
  23. }

復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表