程序如下: #include <reg52.h> #define uchar unsigned char #define uint unsigned int sbit duan=P2^6; sbit wei=P2^7; uchar a,shu,bai,shi,ge; uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void display(uchar bai,uchar shi,uchar ge); void init(); void delay(uchar z); void main() { init(); while(1) { if(a==20) { a=0; shu++; if(shu==101) shu=0; bai=shu/100; shi=shu%100/10; ge=shu%10; } display(bai,shi,ge); } } void init() { shu=0; TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; } void timer() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; a++; } void display(uchar bai,uchar shi,uchar ge) { duan=1; P0=table[bai]; duan=0; P0=0xff;//消隐 wei=1; P0=0xfe; wei=0; delay(5);
duan=1; P0=table[shi]; duan=0; P0=0xff;//消隐 wei=1; P0=0xfd; wei=0; delay(5);
duan=1; P0=table[ge]; duan=0; P0=0xff;//消隐 wei=1; P0=0xfb; wei=0; delay(5); } void delay(uchar z) { uchar x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } 我认为它应该每隔一秒动态显示1-100之间的数,可不知道它显示是从0-100. |