#include <reg51.h>
#include<math.h>
typedef unsigned int u16;
typedef unsigned char u8;
sbit led1=P2^0;
sbit led2=P2^1;
u16 b=2000;
u16 shuZu;
u16 ciShu=0;
u16 k;
u16 text[]={0,1,2,3,4,5,6,7,8,7,6,5,4,3,2,1,0,(-1),(-2),(-3),(-4),(-5),(-6),(-7),(-8),(-7),(-6),(-5),(-4),(-3),(-2),(-1)};
void InitTimer0(void)
{
TMOD = 0x02;
TH0 = 0x06;
TL0 = 0x06;//0.25ms中断
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main(void)
{
led1=0;
led2=1;
InitTimer0();
while(1);
}
void Timer0Interrupt(void) interrupt 1
{static int i=0;
i++;
if(i==b)
{led1=~led1;
led2=~led2;
i=0;
shuZu=ciShu%32;
k=text[shuZu];
b=b+pow((-1),(ciShu+1))*400*k;
ciShu++;
}
}
终于跑出来了,虽然用了中断。。
|