资源描述
#include"reg52.h"
#define uchar unsigned char
#define uint unsigned int
uchar code table1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar code table2[]={1,10,5,10,1}; //速度选挡
uchar temp,speed,aa,i;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
TMOD=0x01; //时钟1模式,自动清除更新标志
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void main()
{
init();
while(1)
{
if(aa==speed)
{
aa=0;
P0=table1[temp];
temp++;
if(temp==8)
{
temp=0;
speed=table2[i];
i++;
if(i==5)
i=0;
}
}
}
}
void timer0() interrupt 1 //时钟1,16位
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
展开阅读全文