#include <reg52.h> #include <intrins.h> #define uchar unsigned char #define uint unsigned int uchar code hello[]={0x76,0x79,0x38,0x38,0x3f}; uchar code LED_W[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar temp,t0,t1,hundred,ten,bit,flag,flag1; uint num; void init(); void display(uchar,uchar,uchar); void display1(); void delay(); void main() { init(); while(1) { if(flag1!=1) display(hundred,ten,bit); else display1(); } } void init() { t0=0; t1=0; flag=0; flag1=0; num=432; temp=0xfe; P1=temp; TMOD=0x11; TH0=(65536-50000)/256; TL0=(65536-50000)%256; TH1=(65536-50000)/256; TL1=(65536-50000)%256; EA=1; ET0=1; ET1=1; TR0=1; TR1=1; } void timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; t0++; if(flag==0) { if(t0==10) { t0=0; temp=_crol_(temp,1); P1=temp; } } else { if(t0%4==0) P1=~P1; if(t0==60) { TR0=0; P1=0xff; flag1=1; } } } void timer1() interrupt 3 { TH1=(65536-50000)/256; TL1=(65536-50000)%256; t1++; if(t1==2) { t1=0; num--; hundred=num/100; ten=num%100/10; bit=num%10; if(num==398) { TR0=0; TH0=(65536-50000)/256; TL0=(65536-50000)%256; TR0=1; flag=1; t0=0; P1=0xff; TR1=0; } } } void display(uchar h,uchar t,uchar b) { P2=LED_W[0]; P0=table[b]; delay(); P2=LED_W[1]; P0=table[t]; delay(); P2=LED_W[2]; P0=table[h]; delay(); P2=LED_W[3]; P0=table[5]; delay(); P2=LED_W[4]; P0=table[6]; delay(); P2=LED_W[5]; P0=table[7]; delay(); } void display1() { P2=LED_W[4]; P0=hello[0]; delay(); P2=LED_W[3]; P0=hello[1]; delay(); P2=LED_W[2]; P0=hello[2]; delay(); P2=LED_W[1]; P0=hello[3]; delay(); P2=LED_W[0]; P0=hello[4]; delay(); } void delay() { uchar x,y; for(x=0;x<148;x++) for(y=0;y<10;y++); }