51单片机实现流水灯左移后右移动

代码如下

#include

void main() {
	
	int i = 0;
	unsigned count = 0;
	unsigned char flag = 0;
	P0 = 0x01;
	
	while(1) {
		if(flag%2 == 0) {
			P0 = ~(0x01 << count);
		} else {
			P0 = ~(0x80 >> count);
		}
		for(i = 0; i < 30000; i++);
		count++;
		if(count >= 8) {
			count = 1;
			flag++;
		}
	}
}

你可能感兴趣的:(c,单片机,51单片机,流水灯)