#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
char code ledp[4]={0xfe,0xfd,0xfb,0xf7};//预定的写入 P1 的值
sbit P10 = P1^0; //头文件中没有定义的 IO 就要自己来定义了
sbit P11 = P1^1;
sbit P12 = P1^2;
sbit P13 = P1^3;
bit ldelay=0;
uchar speed=10;
uchar ledi;
char code dx516[3] _at_ 0x003b;
void main(void)
{
RCAP2H =0x10;
RCAP2L =0x10;
ET2=1;
EA=1;
TR2=1;
while(1)
{
;
if(ldely)
{
ldely=0;
P1=ledp[ledi++];
if(ledi==4)
{
ledi=0;
speed--;
if(speed==0)
speed=10;
}
}
}
}
void timer2() interrupt 5
{
static uchar t;
TF2=0;
t++;
if(t==speed )
{
t=0;
ldely=1;
}
} |