#include <REGX52.H> #include <INTRINS.H> void Delay500ms() //@11.0592MHz { unsigned char i, j, k; _nop_(); i = 4; j = 129; k = 119; do { do { while (--k); } while (--j); } while (--i); } void main() { while(1) { P2=0xFE;//1111 1110 Delay500ms(); P2=0xFD; Delay500ms(); P2=0xFB; Delay500ms(); P2=0xF7; Delay500ms(); P2=0xEF; Delay500ms(); P2=0xDF; Delay500ms(); P2=0xBF; Delay500ms(); P2=0x7F; Delay500ms(); } }
更高要求
建立新工程2-4 LED流水灯plus
#include <REGX52.H> #include <INTRINS.H> void Delay1ms(unsigned int xms) //@11.0592MHz { unsigned char i, j; while(xms) { i = 2; j = 199; do { while (--j); } while (--i); xms=xms-1; } } void main() { while(1) { P2=0xFE;//1111 1110 Delay1ms(500); P2=0xFD; Delay1ms(500); P2=0xFB; Delay1ms(500); P2=0xF7; Delay1ms(500); P2=0xEF; Delay1ms(500); P2=0xDF; Delay1ms(500); P2=0xBF; Delay1ms(500); P2=0x7F; Delay1ms(500); } }