#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char tab[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0xff};
void delay(uint e) //延时函数,延时为0.5s
{
uint i,j;
while(e--)
{
for(i=0;i<500;i++)
for(j=0;j<110;j++);
}
}
void Timer0Init()
{
TMOD|=0x01;//选择为定时器0模式,工作方式1,仅用TR0打开启动。
TH0=0xfe; //给定时器赋初值,定时1ms
TL0=0xfc;
ET0=1;//打开定时器0中断允许
EA=1;//打开总中断
TR0=1;//打开定时器
}
void main()
{
Timer0Init();
while(1);
}
void timer0() interrupt 1
{
uchar i;
for(i=0;i<8;i++)
{
P2=tab[i];
delay(1);
}
for(i=0;i<8;i++)
{
P2=~tab[i];
delay(1);
}
}
温馨提示:答案为网友推荐,仅供参考