欢迎来到天天文库
浏览记录
ID:55263464
大小:24.00 KB
页数:2页
时间:2020-05-08
《单片机秒表程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#defineSEGP2#defineSCANPP1sbitPB0=P3^2;sbitPB1=P3^3;#definecount_M150000#defineTH_M1(65536-count_M1)/256#defineTL_M1(65536-count_M1)%256intcount_T0=0;#definecount_M2250#defineTH_M2(250-count_M2)#defineTL_M2(250-count_M2)intcount_T1=0;charcodeTAB[10]={0xc0,0xf9,0xa4,
2、0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};chardisp[4]={0xc0,0xc0,0xc0,0xc0};intseconds=0;charscan=0;charsm=0x01;voiddebouncer(void);main(){IE=0x8f;TCON=0x00;TMOD=0x21;TH0=TH_M1;TL0=TL_M1;TR0=0;TH1=TH_M2;TL1=TL_M2;TR1=1;P3=0xff;while(1);}voidT0_1s(void)interrupt1{TH0=TH_M1;TL0=TL_M1;if(++c
3、ount_T0==2){count_T0=0;seconds++;if(seconds==10000)seconds=0;}disp[3]=TAB[seconds/1000];disp[2]=TAB[(seconds%1000)/100];disp[1]=TAB[(seconds%100)/10];disp[0]=TAB[seconds%10];}voidT1_4ms(void)interrupt3{if(++count_T1==16){count_T1=0;if(++scan==5){scan=1;sm=0x01;}SEG=0xff;SCANP=~sm;sm
4、=sm<<1;SEG=disp[scan-1];}}voidint0_sw(void)interrupt0{TR0=~TR0;while(PB0==0);debouncer();}voidint1_RST(void)interrupt2{while(PB1==0);debouncer();seconds=0;disp[0]=disp[1]=disp[2]=disp[3]=0xc0;}voiddebouncer(void){inti;for(i=0;i<2400;i++);}
此文档下载收益归作者所有