关于单片机的一个c程序
#include<reg51.h>#defineucharunsignedcharuchardistab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92...
#include<reg51.h>
#define uchar unsigned char
uchar distab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
uchar number=0;
void t0isr() interrupt 1
{
TH0=0xf4;
TL0=0x48;
switch(number)
{
case 0:P2=0x01;P0=distab[1];break;
case 1:P2=0x02;P0=distab[2];break;
case 2:P2=0x04;P0=distab[3];break;
case 3:P2=0x08;P0=distab[4];break;
case 4:P2=0x10;P0=distab[5];break;
case 5:P2=0x20;P0=distab[6];break;
default:break;
}
number++;
if(number>5)number=0;
}
main()
{
TMOD = 0x01;
number = 0;
TH0=0xf4;
TL0=0x48;
TR0=1;
ET0=1;
EA=1;
while(1);
}
如果想要输出的数字顺序不同需要怎么修改,比如变成134625 展开
#define uchar unsigned char
uchar distab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
uchar number=0;
void t0isr() interrupt 1
{
TH0=0xf4;
TL0=0x48;
switch(number)
{
case 0:P2=0x01;P0=distab[1];break;
case 1:P2=0x02;P0=distab[2];break;
case 2:P2=0x04;P0=distab[3];break;
case 3:P2=0x08;P0=distab[4];break;
case 4:P2=0x10;P0=distab[5];break;
case 5:P2=0x20;P0=distab[6];break;
default:break;
}
number++;
if(number>5)number=0;
}
main()
{
TMOD = 0x01;
number = 0;
TH0=0xf4;
TL0=0x48;
TR0=1;
ET0=1;
EA=1;
while(1);
}
如果想要输出的数字顺序不同需要怎么修改,比如变成134625 展开
1个回答
展开全部
修改switch里面内容就可以了。
switch(number)
{
case 0:P2=0x01;P0=distab[1];break;
case 1:P2=0x02;P0=distab[3];break;
case 2:P2=0x04;P0=distab[4];break;
case 3:P2=0x08;P0=distab[6];break;
case 4:P2=0x10;P0=distab[2];break;
case 5:P2=0x20;P0=distab[5];break;
default:break;
}
switch(number)
{
case 0:P2=0x01;P0=distab[1];break;
case 1:P2=0x02;P0=distab[3];break;
case 2:P2=0x04;P0=distab[4];break;
case 3:P2=0x08;P0=distab[6];break;
case 4:P2=0x10;P0=distab[2];break;
case 5:P2=0x20;P0=distab[5];break;
default:break;
}
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询