#include<reg52.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int sbit dula=P2^0; sbit wela=P2^1; uint num,num1; uchar code table[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71}; void delayus(uint us) { while(us--); } void delay(uint z) { uint a,b; for(a=0;a<z;z++) for(b=0;b<110;b++); } void display(uint disnum) { uchar wan,qian,bai,shi,ge; wan=disnum/10000; qian=disnum%10000/1000; bai=disnum%1000/100; shi=disnum%100/10; ge=disnum%10; dula=1; P0=table[wan]; dula=0; P0=0xff; wela=1; P0=0xf7; wela=0; delayus(100); dula=1; P0=table[qian]; dula=0; P0=0xff; wela=1; P0=0xef; wela=0; delayus(100); dula=1; P0=table[bai]; dula=0; P0=0xff; wela=1; P0=0xdf; wela=0; delayus(100); dula=1; P0=table[shi]; dula=0; P0=0xff; wela=1; P0=0xbf; wela=0; delayus(100); dula=1; P0=table[ge]; dula=0; P0=0xff; wela=1; P0=0x7f; wela=0; delayus(100); } void main() { TH0=(65536-46080)/256; TL0=(65536-46080)%256; TMOD=0x01; EA=1; ET0=1; TR0=1; while(1) { if(num==20) { num=0; num1++; } if(num1==600) num1=0; display(num1); } } void T0_timer() interrupt 1 { TH0=(65536-46080)/256; TL0=(65536-46080)%256; num++; }