以a为例编写程序如下:
#include
#include
#define uchar unsigned char
#define uint unsigned int
void delay(uint ms)
{
uchar a;
while(ms--)
{
for(a=100;a>0;a--);
}
}
main()
{
uchar i;
while(1)
{
P3=0xfe;
for(i=0;i<8;i++)
{
P3=_crol_(P3,1);
delay(500);
} //依次点亮LED1~8;
P3=0xff; //全部熄灭;
delay(500);
}
}