1、可调时钟参考程序#include “intrins.h“#define ui unsigned int#define uc unsigned charvoid delay(ui t)while(t-);sbit h0=P30;sbit h1=P31;sbit h2=P32;sbit l0=P34;sbit l1=P35;sbit l2=P36;sbit l3=P37;uc key; /键值void scan()ui n;key=16;h0=0;h1=0;h2=0;if(l0=0|l1=0|l2=0|l3=0)n+;if(n=20)h0=0;h1=1;h2=1;if(l0=0)key=0;if(
2、l1=0)key=1;if(l2=0)key=2;if(l3=0)key=3;h0=1;h1=0;h2=1;if(l0=0)key=4;if(l1=0)key=5;if(l2=0)key=6;if(l3=0)key=7;h0=1;h1=1;h2=0;if(l0=0)key=8;if(l1=0)key=9;if(l2=0)key=10;if(l3=0)key=11;else n=0;sbit smcs1=P20;sbit smcs2=P21;sbit smwr=P22;uc w8=0,0,11,0,0,11,0,0,m8=0,0,11,0,0,11,0,0;uc code seg=0xc0,0x
3、f9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf;void sm()static uc i,px=0xfe;static ui n;n+;if(n=500)n=0;P0=segn=250?wi:mi;smcs1=0;smwr=0;smwr=1;smcs1=1;P0=px;smcs2=0;smwr=0;smwr=1;smcs2=1;delay(200);P0=0xff;smwr=0;smwr=1;smcs1=1;px=_crol_(px,1);i+;if(i=8)i=0;uc hh,mm,ss,mod=1,hms=0,gs=0;/hh 时
4、,mm分 ,ss 秒 ,mod计时 /调时 ,hms时 /分 /秒 ,gs个 /十void set()m7=w7;m6=w6;m4=w4;m3=w3;m1=w1;m0=w0;if(gs=0)switch(hms)case 0:mod=1;break;case 1:m6=10;break;case 2:m3=10;break;case 3:m0=10;break;elseswitch(hms)case 0:mod=1;gs=0;break;case 1:m7=10;break;case 2:m4=10;break;case 3:m1=10;break;void ts()if(gs=0)switc
5、h(hms)case 1:if(w7*10+key24)w6=key;break;case 2:if(w4*10+key60)w3=key;break;case 3:if(w1*10+key60)w0=key;break;elseswitch(hms)case 1:if(key*10+w624)w7=key;break;case 2:if(key*10+w360)w4=key;break;case 3:if(key*10+w060)w1=key;break;hh=w7*10+w6;mm=w4*10+w3;ss=w1*10+w0;void main()TMOD=0x01;TH0=(65536-2
6、000)/256;TL0=(65536-2000)%256;EA=1;ET0=1;TR0=1;while(1)scan();if(key=10)mod=0;hms+;if(hms=4)hms=0;set();if(key=11set();if(key10void t0() interrupt 1static ui n;TH0=(65536-2000)/256;TL0=(65536-2000)%256;if(mod)n+;if(n=500)n=0;ss+;if(ss=60)ss=0;mm+;if(mm=60)mm=0;hh+;if(hh=24)hh=0;w7=m7=hh/10;w6=m6=hh%10;w4=m4=mm/10;w3=m3=mm%10;w1=m1=ss/10;w0=m0=ss%10;sm();