发布网友 发布时间:2022-05-09 13:15
共1个回答
热心网友 时间:2024-01-30 11:36
#include
unsigned int LED;
unsigned int a,i,m;
void yiwei();
void delay(unsigned int b);
void main()
TMOD=0x01; //T0为方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256; //初值
EA=1; //允许中断
ET0=1;
while(1)
P2=0x00;
delay(2000);
LED = 0x7f;
m
=0;
for (i = 0 ;i < 8 ; i++)
{
a=0;
TR0=1;
delay(100);
while(m);
delay(2000);
P2=0x00;
delay(2000);
LED = 0xfe;
m=0;
for (i = 0 ;i < 8 ; i++)
a=1;
TR0=1;
delay(100);
while(m);
}
delay(2000);
}
}
void t0() interrupt 1 using 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
m++;
if(m==20)
{
m=0;
yiwei();
}
}
void yiwei()
{
if(a==0)
{
P2=LED;
LED = LED>>1; // 右移
LED = LED|0x80;
}
else
{
P2 = LED;
LED = LED << 1; // 左移
LED = LED | 0x01;
}
}
void delay(unsigned int b)
{
unsigned char j;
for(b; b > 0; b--) //机器在这里执行需要一段时间 也就达到了延时效果
for(j = 255; j > 0; j--);
}
自己调试过,我12晶振