1、#includeunsigned char code LEDcode=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /定义共阴 0-8 + 黑屏; unsigned char dispbitcode=0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe, /定义一位为 00xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff;unsigned char dispbuf=16,16,16,16,16,16,16,16, /定义一个一
2、维数组,初值随便16,16,16,16,16,16,16,16;unsigned char dispbitcnt;unsigned int t04scnt;unsigned char t1mscnt;unsigned char u;unsigned char i;/=void main()TMOD=0x02; /定时器 0,方式 2TH0=0x06;TL0=0x06; /250usTR0=1; /开定时ET0=1;EA=1;while(1);/=void t0(void) interrupt 1 using 0t1mscnt+;if(t1mscnt=4) /1ms循环 8个数码管一遍t1mscnt=0;P2=0xff;P0=LEDcodedispbufdispbitcnt; /段P2=dispbitcodedispbitcnt; /位dispbitcnt+;if(dispbitcnt=16)dispbitcnt=0;t04scnt+;if(t04scnt=3000) /0.75s滑动一个数码管t04scnt=0;u+; /通过该循环定义 dispbufi,1-uif(u=16) /保证移位时,8 个数的顺序不变u=0;for(i=0;i16;i+) /左到右,1 到 8,从左拉入,从右拉出dispbufi=16;for(i=0;iu;i+)dispbufi=u-i;