如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
#include<reg51.h>#defineucharunsignedchar#defineuintunsignedintucharstate=0;uchark=-1;uchargewei_s=0;ucharshiwei_s=0;uchargewei_m=0;ucharshiwei_m=0;uchargewei_h=0;ucharshiwei_h=0;ucharcount_s=0;ucharcount_m=0;ucharcount_h=0;ucharnum[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};voidmain(void){//uchari;EX0=1;IT0=1;//外部中断0EX1=1;IT1=1;//外部中断1TMOD=0x01;TH1=-1;TL1=-1;TR1=1;//定时器中断1ET1=1;TMOD=0x01;TH0=-50000/256;TL0=-50000%256;TR0=1;//定时器中断0ET0=1;EA=1;//CPU开中断while(1){}}voidkey_h(void)interrupt0//外部中断0,调整小时{count_h++;count_h%=24;gewei_h=count_h%10;shiwei_h=count_h/10;}voidkey_m(void)interrupt2//外部中断1,调整分{count_m++;count_m%=60;gewei_m=count_m%10;shiwei_m=count_m/10;}voidtime0(void)interrupt1//定时器1中断,不断刷新LED{TH0=-50000/256;TL0=-50000%256;state++;if(state==15){state=0;count_s++;count_s%=60;gewei_s=count_s%10;shiwei_s=count_s/10;if(count_s==0){count_m++;count_m%=60;gewei_m=count_m%10;shiwei_m=count_m/10;}if(count_m==0&&count_s==0){count_h++;count_h%=24;gewei_h=count_h%10;shiwei_h=count_h/10;}}}voidtime1(void)interrupt3//定时器中断,利用视觉暂留原理,稳定显示LED{TH1=-1;TL1=-1;P2=0x00;P0=0xff;k++;k%=6;switch(k){case0:P0=num[gewei_s];P2=0xc1;break;case1:P0=num[shiwei_s];P2=0xc2;break;case2:P0=num[gewei_m];P2=0xc4;break;case3:P0=num[shiwei_m];P2=0xc8;break;case4:P0=num[gewei_h];P2=0xd0;break;case5:P0=num[shiwei_h];P2=0xe0;break;}}