#include <reg51.h> #define uchar unsigned char #define uint unsigned int uchar count=0; uchar flag=0; uchar code duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; void delay(uint z) { uint i,j; for(i=0;i<z;i++) for(j=0;j<124;j++); } void timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; count++; if(count>=20) { flag=1; count=0; } } void main() { uchar shi=23,fen=59,miao=45; TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; while(1) { if(flag==1) { miao++; if(miao==60) { miao=0; fen++; if(fen==60) { fen=0; shi++; if(shi==24) { shi=0; } } } flag=0; } P3=wei[0]; P2=duan[shi/10]; delay(5); P3=wei[1]; P2=duan[shi%10]; delay(5); P3=wei[2]; P2=~0x40; delay(5); P3=wei[3]; P2=duan[fen/10]; delay(5); P3=wei[4]; P2=duan[fen%10]; delay(5); P3=wei[5]; P2=~0x40; delay(5); P3=wei[6]; P2=duan[miao/10]; delay(5); P3=wei[7]; P2=duan[miao%10]; delay(5); } } |