本帖最后由 孤独的凯 于 2013-1-6 20:07 编辑
#include<AT89X52.h>
#define led P2
unsigned int i,j,t,z;
int code a[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
int code b[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
int code c[8]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};
int code d[8]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f};
void first() //led灯从左向右依次循环并返回
{
if(t<8) //t表示执行次数
{ //j表示数组a的j-1个元素
led = a[j];
j++;
z++;
i = 0; //清除标志位
t++; }
else
{
if(t >= 8 && t <=15)
{
led = b[j-8];
j++;
z++;
i = 0;
t++; }
else
{
i=0; //清除标志位
t=0; //执行次数清零
j=0;
}
}
}
void second()
{
if(t<8)
{
led = c[j-8];
j++;
z++;
i = 0;
t++;
}
else
{
if(t >= 8 && t < 16)
{
led = d[j-16];
j++;
z++;
i=0;
t++; }
else
{
j=0;
i=0;
t=0; //执行次数清零
z=0;
}
}
}
void main()
{
TMOD = 0x01;
TH0 = 0xD8;
TL0 = 0xf0;
EA = 1;
ET0 = 1;
i = 0;
j = 0;
t = 0; //执行次数清零
z = 0;
TR0 = 1;
led = 0xff;
while(1);
}
void et0interrupt() interrupt 1
{
TH0 = 0xD8;
TL0 = 0xf0;
i++;
if(i == 50)
{
if(z / 16 == 0)
{
first();
}
else
{
if(z /16 =1)
{
second();
}
// else
// third();
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
正解
一周热门 更多>