原件清单:
源程序:
- #include <reg51.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)
- {
- if(LEDDirection)
- P2 = ~(0x01<<LEDIndex);
- else
- P2 = ~(0x80>>LEDIndex);
- if(LEDIndex==7)
-
- LEDDirection = !LEDDirection;
- LEDIndex = (LEDIndex+1)%8;
- Delay1ms(200);
- }
- }
复制代码
|