|
流水燈左右走程序.docx
(12.96 KB, 下載次數(shù): 7)
2019-10-12 12:32 上傳
點(diǎn)擊文件名下載附件
圖加程序
單片機(jī)源程序如下:
- #include <REG52.H>
- void Delay1ms(unsigned int count)
- {
- unsigned int i,j;
- for(i=0;i<count;i++)
- for(j=0;j<120;j++);
- }
- main()
- {
- unsigned char LEDIndex = 0;
- bit LEDDirection = 1;
- while(1)【滿(mǎn)足條件執(zhí)行下面程序】
- {
- if(LEDDirection)
- P1 = ~(0x01<<LEDIndex);【滿(mǎn)足】<<表示邏輯移位
- else
- P1 = ~(0x80>>LEDIndex);【不滿(mǎn)足】~表示按位取反
- if(LEDIndex==7)
- LEDDirection = !LEDDirection;
- LEDIndex = (LEDIndex+1)%8; 【%】取余數(shù)
- Delay1ms(100);
- }
- }
復(fù)制代碼
|
|