1、单片机二进制时钟源码sbit SET_M=P05;sbit SET_S=P16;uchar code DSY_CODE= /用于显示时钟的编码0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,
2、0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b;uint hour=0,min=0,sec=0,count=0;void delay_ms(unsigned char i)unsigned char j;while(i-)for(j=124;j0;j-);void Set_Interrupt_1()if(SET_H=0)delay_ms(100);if(SET_H=0)TR0=0;if(hour23)hour+;else hour=0; /delay_ms(50);TR0=1;P0=DSY_CODEhour;P1=DSY_CODEm
3、in;P2=DSY_CODEsec;void Set_Interrupt_2()if(SET_M=0)delay_ms(100);if(SET_M=0)TR0=0;TH0 = (65535-50000)/256;TL0 = (65535-50000)%256;if(min59)min+;else min=0;hour+;if(hour=24)hour=0; / delay_ms(50);TR0=1;P0=DSY_CODEhour;P1=DSY_CODEmin;P2=DSY_CODEsec; void Set_Interrupt_3()if(SET_S=0)delay_ms(100);if(SE
4、T_S=0)TR0=0;if(sec59)sec+;else sec=0;min+;if(min=60)min=0;hour+;if(hour=24)hour=0; /delay_ms(50);TR0=1;P0=DSY_CODEhour;P1=DSY_CODEmin;P2=DSY_CODEsec;void main()P0 = 0xff;P1 = 0xff;P2 = 0xff;TMOD = 0x01;TH0 = (65535-50000)/256;TL0 = (65535-50000)%256;/IE = 0x82;ET0=1;TR0 = 1;EA=1;while(1)Set_Interrupt_1();Set_Interrupt_2();Set_Interrupt_3();void Time0() interrupt 1TH0 = (65535-50000)/256;TL0 = (65535-50000)%256;if(count+1)!=20)count+;return;else if(sec+1)!=60) P2=DSY_CODE+sec;else sec=0;if(min+1)!=60)P1=DSY_CODE+min;elsemin=0;if(hour+1)!=60)P0=DSY_CODE+hour;elsehour=0;count = 0;