#include<reg52.h>缓带
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={ //段编码
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,
0xff,0xc7,0xc1,0x84,0x91};
uchar code tab[]= { //位编码
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar tabl[]={ //存数 数组
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
uchar num,tt,aa,bb,cc,dd;
void init();
void delay(uint z) //延时函数
{
uint x,y;
for(x = z;x >0;x--)
for(y = 110;y > 0;y--);
}
void main()
{
tabl[5]=table[1]; //输入要显示的数字
tabl[6]=table[5];
tabl[7]=table[0];
tabl[8]=table[0];
tabl[9]=table[8];
tabl[10]=table[2];
tabl[11]=table[7];
tabl[12]=table[0];
tabl[13]=table[7];
tabl[14]=table[1];
tabl[15]=table[9];
TMOD=0x01;//选定时器和方式
TH0=(65536-50000)/256; //装入初值
TL0=(65536-50000)%256;
EA=1;// 开总中断
ET0=1;//开定时器0中断
郑好 TR0=1;//启动定时器0
while(1) //大循环 数字滚动流入
{
cc=6;
bb=0;
dd=0;
init();
bb=1;
dd=1;
init();
bb=2;
dd=2;
init();
bb=3;
dd=3;
init();
bb=4;
dd=4;
init();
bb=5;
dd=5;
init();
bb=6;
dd=6;
init();
bb=7;
dd=7;
init();
bb=8;
dd=8;
init();
bb=9;
dd=9;
init();
bb=10;
dd=10;
init();
bb=11;
dd=11;
init();
bb=12;
dd=12;
init();
bb=13;
dd=13;
init();
bb=14;
dd=14;
init();
bb=15;
dd=15;
init();
}
}
void exter0() interrupt 1 //中断子程序
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num==20)
{
num=0;
tt=0;
cc++;
}
}
void 扰丛芦init() //动态扫描子程序
{
aa=0;
tt=1;
while(tt)
{
P2= tab[aa];
aa++;
if(aa==6)
{
aa=0;
}
P0=tabl[bb];
bb++;
delay(5) ;
if(bb%cc==0)
{
bb=dd;
}
P0=0xff;
}
}
程序哥哥
芯片哥哥