《单片机的可调秒表时钟程序.doc》由会员分享,可在线阅读,更多相关《单片机的可调秒表时钟程序.doc(16页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-date单片机的可调秒表时钟程序单片机的可调秒表时钟程序#include unsigned char i=0,count,second,minute,hour,key;unsigned char time8;unsigned char const dofly=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40;/ 显示
2、段码值012345679-unsigned char code seg=0,1,2,3,4,5,6,7;/分别对应相应的数码管点亮/sbit LED0=P10;sbit LED1=P11;sbit LED2=P12;sbit LED3=P13;sbit LED4=P14;sbit LED5=P15;sbit LED6=P16;sbit LED7=P17;sbit S1=P30;sbit S4=P31;sbit S7=P32;void Init_Timer0(void) TMOD |= 0x01; /使用模式1,16位定时器,使用|符号可以在使用多个定时器时不受影响 TH0=0x00; /给定初
3、值,这里使用定时器最大值从0开始计数一直到65535溢出 TL0=0x00; EA=1; /总中断打开 ET0=1; /定时器中断打开 TR0=1; /定时器开关打开void Init_Timer1(void) TMOD |= 0x10; /使用模式1,16位定时器,使用|符号可以在使用多个定时器时不受影响 TH1=0x00; /给定初值,这里使用定时器最大值从0开始计数一直到65535溢出 TL1=0x00; EA=1; /总中断打开 ET1=1; /定时器中断打开 TR1=1; /定时器开关打开void delay(unsigned int i)/延时函数while(i-);void ke
4、yscan()/键盘扫描函数,使用行列反转扫描法 if(S1=0) LED2=0; while(S1=0); LED2=1; hour+; if(S4=0) LED3=0; while(S4=0); LED3=1; minute+; if(S7=0) LED4=0; while(S7=0); LED4=1; second+; void main() hour=12;minute=35; Init_Timer0(); Init_Timer1(); time2=10; time5=10; while(1) keyscan();/调用键盘扫描, void Timer1_isr(void) inter
5、rupt 3 using 1 TH1 = 0xF8; TL1 = 0x30; P0=doflytimei;/取显示数据 P2=segi; /取段码 i+;if(i=8) i=0; LED0=LED0;void Timer0_isr(void) interrupt 1 using 1TH0 = 0xD8;TL0 = 0xF0;count+; if (count=100) count=0;second+;LED7=LED7; if (second=60) second=0;minute+; if (minute=60) minute=0;hour+; if (hour=24) hour=0; time7=second%10;time6=second/10;time4=minute%10;time3=minute/10;time1=hour%10;time0=hour/10;-