#include <reg51.h>
// 延时子程序
void delayms(unsigned char ms)
{
unsigned char i;
while(ms--)
{
for(i = 0; i < 120; i++); //又机器周期决定,1ms包含多少个执行次数。执行120次空指令
}
}
main()
{
unsigned char LED;
LED = 0xfe; //0xfe = 1111 1110
while(1)
{
P1 = LED; //P1端口赋值
delayms(250);
LED = LED << 1; //循环左移1位,点亮下一个LED "<<"为左移位
if(LED == 0x00 )
{ P1 = LED; LED = 0xfe; delayms(250); } // 0xfe = 1111 1110
}
}