51单片机定时器秒表设计程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

51单片机定时器秒表设计程序#includereg51.htypedefunsignedcharUINT8;typedefunsignedintUINT16;codeUINT8SEGMENT[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};codeUINT8SHU[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};codeUINT8SELECT[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};#defineS10x0e#defineS20x0d#defineS30x0b#defineS40x07sbitSPEAK=P3^5;sbitP3_3=P3^3;UINT8mSecond,Second;voidDelay(UINT16t){UINT16i,j;for(i=0;it;i++)for(j=0;j114;j++);}UINT8Scankey(void){UINT8key;if((P3&0x0f)==0x0f)return(0xff);Delay(10);if((P3&0x0f)==0x0f)return(0xff);key=P3&0x0f;while((P3&0x0f)!=0x0f);return(key);}voidDisplay(void){staticUINT8num=0;P2=0xff;switch(num){case0:P0=0xff;break;case1:P0=0xff;break;case2:P0=0xff;break;case3:P0=0xff;break;case4:P0=0xff;break;case5:P0=SHU[Second%100];break;case6:P0=SEGMENT[mSecond%100/10];break;case7:P0=SEGMENT[mSecond%10];break;}P2=SELECT[num];num++;num%=8;//if(num==8)num=0;}/*定时器初始化程序voidtimer_10ms(void)//定时器T0定时10ms{TMOD=0x01;TH0=-10000/256;TL0=-10000%256;TR0=1;//启动T0}*/main(){staticUINT8a=0;UINT8i,j;UINT16z;mSecond=0;Second=0;TMOD=0x01;TH0=0xdc;TL0=0x32;TR0=1;//启动T0EA=0;ET0=1;while(1){Display();Delay(2);i=Scankey();if(i==S1)//启动{EA=1;}elseif(i==S2)//停止{EA=0;}elseif(i==S3)//清除{EA=0;Second=0;mSecond=0;}if(i==S4)//暂停{EA=0;if(a==0){a=1;}elseif(a==1){a=0;EA=1;}}if(Second==10){while(1){for(j=0;j100;j++){SPEAK=0;Delay(1);SPEAK=1;Delay(1);}for(z=0;z100;z++){P2=0xfb;P0=SHU[9];Delay(5);P2=0xfd;P0=SEGMENT[9];Delay(5);P2=0xfe;P0=SEGMENT[9];Delay(5);}P2=0XFF;for(j=0;j100;j++){SPEAK=1;Delay(1);SPEAK=1;Delay(1);}//Delay(1000);}}}//}}voidint_0()interrupt1{TH0=0xdc;TL0=0x32;mSecond++;if(mSecond==100){Second++;mSecond=0;if(Second==10)EA=0;}}

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功