手动计数器的设计与制作:秒表C程序.docx
")9共阳极段码表秒计数按键功能:0启动,1停止,2清零定时次数计数按键按键状态延时程序/TO中断服务程序重装初值,5OmS每50ms*20=1s刷新一次计满59秒后回0显示个位显示十位,十位为0则不显示按键处理子程序启动计时停止计时任务4.4一秒表C程序#indude"reg51.h"unsignedcharsegtab10=0xc0,0xf9z0xa4z0×b0,0×99,0x92,0x82,0xf8,0x80,0x90;unsignedcharcount;unsignedcharkey_f1ag;unsignedcharnum;sbitkey=P37;bitkey_state;sbitIed=P1zxI;sbitIedZ=P1zxO;voidDe1ay(unsignedcharn)unsignedcharij;for(i=0;i<n;i+)for(j=0;j<200;j+);)voidTimerO()interrupt1THo=(65536-50000)/256;T10=(65536-50000)%256;num+;tf(num=20)num=0;count+;if(count=60)count=0;P0=segtabcount%10;if(count10=0)PO=Oxff;e1seP0=segtabcount10;)voidKey_Event()if(key_state=O)key_f1ag=(key_f1ag+1)%3;switch(key_f1ag)case0:TRO=Ijbreak;case1:TRO=O;break;case2:清零P2=0xc0;P0=0xff;count=0;num=0;break;)voidmain()P2=0xc0;PO=Oxff;num=0;count=0;key_f1ag=2;key_state=1;TMOD=OxOI;TH0=(65536-50000)256;T10=(65536-50000)%256;EA=I;ETO=1;whi1e(1)if(key_state!=key)DeIay(IO);key_state=key;Key_Event();主程序显示Os按键标志初值为2/TO定时50ms开放中断等待按键