#include<reg51.h>
void delay(int n)
{
int i,j;
for(i = 0; i < n; i++)
{
for(j = 0; j < 20; j++) //循环20次,即为1s
{
while(TF0 == 0);
TF0 = 0;
TH0 = 0x3c;
TL0 = 0xb0;
}
}
}
int a[8] = {1, 2, 4, 8, 16, 32, 64, 128};
void main()
{
int i = 0;
TMOD = 0x01; //使用模式1
TH0 = 0x3c; //50ms
TL0 = 0xb0;
TR0 = 1;
P2 = 1;
while(1) //使P2八个引脚循环出现高电平
{
P2 = a[i++];
delay(1);
if(i == 8)
{
i = 0;
}
}
}
欢迎大家批评指正!