#include "reg52.h"
#include <stdio.h>// 准备工作:P0的8个引脚和8个LED引脚用排线相连
#define LED P0// 延时多少毫秒,这里是基于晶振12Mhz的51单片机
void Delay1ms(unsigned short time)
{unsigned short j = 0;for (j = 0; j < time; ++j){unsigned char i = 0;for (i = 0; i < 100; ++i);}}int main()
{while (1){int i = 0;for (i = 0; i < 8; ++i){// 单片机LED是低电平点亮,所以取反 // 0x01取反得 1111 1110(二进制),第一个灯点亮,其它灯是灭的// 左移一位后取反得 1111 1101(二进制),第二个灯点亮,其它灯熄灭;余此类推 LED = ~(0x01 << i); Delay1ms(1000);}}return 0;
}