1、产品所用程序:/*File name ; demo_11_4.cChip type ; ATmega16Program type ; ApplicationClock frequency ; 1.000 000 MHzMemory model ; SmallExternal SPAM size ; 0Data stack size ; 256*/#include macros.hconst unsigned char led_710 = 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90;const unsigned char position6
2、 = 0xC1,0xC2,0xC4,0xC8,0xD0,0xE0;const unsigned int t16 = 0,1912,1730,1518,1433,1276,1136,1012,956,865,759,716,638,568,506,470;const unsigned char d16 = 0,52,58,66,70,78,88,99,105,116,132,140,157,176,198,209;const unsigned char Max_note8=84,86,64,88,90,100,78,102;const unsigned char music8102=5,2,4,
3、2,5,2,10,6,10,2,11,2,10,2,9,2,7,2,8,10,8,2,7,2,8,2,12,6,12,2,11,2,10,2,9,2,10,2,10,10,5,2,4,2,5,2,10,6,10,2,11,2,10,2,9,2,7,2,8,2,9,2,10,2,14,2,13,6,10,2,12,2,11,2,10,2,11,2,10,6,9,2,8,14,12,2,12,2,10,2,9,2,10,2,6,4,9,2,10,2,12,2,10,2,9,10,12,2,12,2,10,2,9,2,10,2,5,4,9,2,10,2,12,2,9,2,8,10,8,2,9,2,1
4、0,2,12,2,13,2,12,2,10,2,12,2,10,2,10,2,9,2,9,10,8,2,9,2,8,2,9,4,8,2,9,4,10,4,12,2,10,10,2,4,2,4,3,4,3,6,2,2,3,4,5,2,6,4,5,6,1,4,2,4,3,4,6,4,5,4,3,2,5,14,5,2,6,2,8,8,6,4,5,4,3,4,5,2,3,6,1,2,2,2,3,6,1,2,1,4,3,4,2,2,2,4,3,4,5,4,8,12,8,4,7,8,6,4,5,4,6,4,8,4,3,4,2,4,1,8,1,4,1,4,1,4,8,8,6,4,5,4,3,4,2,4,1,
5、4,2,24,3,4,5,4,8,12,8,4,7,8,6,4,5,4,6,4,8,4,3,4,2,4,1,8,1,4,1,4,1,4,8,8,6,4,5,4,3,4,2,4,1,4,1,24,8,4,7,4,8,12,9,4,10,4,9,4,8,4,7,4,8,12,8,4,8,4,5,4,5,4,1,4,6,12,6,4,5,4,1,4,1,4,3,4,2,12,4,4,4,4,5,4,8,4,7,4,8,12,9,4,10,4,9,4,8,4,7,4,8,12,8,4,8,4,5,4,5,4,1,4,6,12,6,4,5,4,5,4,8,4,7,4,8,24,5,4,12,4,11,4
6、,10,8,10,4,11,2,10,10,10,4,11,4,10,4,11,4,10,4,9,2,8,6,8,4,10,4,12,4,13,8,13,4,13,2,12,6,9,4,9,4,11,2,10,22,8,4,10,4,12,4,13,8,13,4,13,2,12,2,12,4,9,4,9,4,11,4,10,4,11,4,10,4,9,2,8,10,9,4,10,4,6,8,6,4,8,4,8,4,7,4,7,8,8,24,12,4,12,4,11,4,10,4,9,12,9,4,9,4,10,4,11,4,10,12,8,4,8,8,9,8,10,8,9,8,8,8,7,4,
7、6,4,5,12,12,4,12,4,11,4,10,4,9,8,9,4,9,4,10,4,11,4,10,12,8,4,8,8,9,4,10,4,11,8,10,8,9,8,8,4,7,4,8,24,5,2,8,2,8,2,8,3,9,1,10,2,8,4,6,2,8,2,8,2,8,3,8,1,6,2,5,4,5,2,8,2,8,2,8,3,9,1,10,2,8,4,8,2,9,2,9,2,9,1,8,1,9,1,10,1,9,6,5,2,8,2,8,2,8,3,9,1,10,2,8,4,8,2,6,2,8,2,8,2,9,2,8,6,5,2,8,2,8,2,8,4,12,2,11,2,1
8、0,2,8,2,8,8;unsigned char note_n;unsigned int int_n;int play_on;int clock_style=0,lazy_style=0,ci=0,cci;unsigned char week_clock8=0,1,2,3,4,5,6,7,time3,time_clock83 = 10,0,7,11,5,7,12,10,7,13,15,7,14,20,7,15,25,7,16,30,7,17,35,7;unsigned char dis_buff6;unsigned char time_counter,key_stime_counter;un
9、signed char clock_state = 6,return_time;int point_on=0,set_on=0,time_1s_ok=0,key_stime_ok=0;int week;void display(void) static unsigned char posit = 0; PORTB = 0xFF; PORTA = led_7dis_buffposit; if(set_on & (posit = clock_state) PORTA = 0xFF; if(point_on & (posit = 2 | posit = 4) PORTA &= 0x7F; PORTB
10、 = positionposit; if(+posit = 6) posit = 0;/Timer 0 比较匹配中断服务,2ms定时#pragma interrupt_handler timer0_comp_isr:iv_TIMER0_COMPvoid timer0_comp_isr(void) display(); if (+key_stime_counter = 5) key_stime_counter = 0; key_stime_ok = 1; if(!(+time_counter % 25) set_on = !set_on; if(time_counter = 100) time_
11、counter = 0; time_1s_ok = 1; /T/C1 比较匹配A中断服务#pragma interrupt_handler timer1_compa_isr:iv_TIMER1_COMPAvoid timer1_compa_isr(void) if(!play_on) note_n = 0; int_n = 1; play_on = 1; else if(-int_n = 0) TCCR1B = 0x08; if (note_n Max_notecci) OCR1A = tmusicccinote_n; int_n = dmusicccinote_n; note_n+; int
12、_n = int_n * musicccinote_n; TCCR1B = 0x09; else play_on = 0;void time_to_disbuffer(unsigned char *time) /时钟时间送显示缓冲区函数 unsigned char i,j=0; for(i=0;i=100) if(+clock_style1) clock_style=0; return key_return;void main(void) unsigned char key_temp,i; DDRA = 0xFF; /LED段码输出 PORTB = 0x00; DDRB = 0x3F; /LE
13、D位控输出 DDRD = 0x20; /PD5音乐播放输出 /T/C0初始化 OCR0 = 0xF9; /OCR0 = 0xF9(249),(249+1)/(125kHz) = 2ms TCCR0 = 0x0A; /内部时钟,8分频(1MHz/8 = 125 kHz),CTC模式 /T/C1初始化 TCCR1A = 0x40; TCCR1B = 0x08; TIMSK = 0x12; /使能T/C1比较匹配A中断,使能T/C0比较匹配中断 time2 = 6; time1 =58; time0 = 55; week=0; /设时间初始值为23:58:55 星期天 SEI(); /使能全局中断
14、while(1) if(time_1s_ok) /1s到 time_1s_ok = 0; point_on = !point_on; /秒闪烁标志 if(+time0 = 60) /秒加1,以下为时间调整 time0 = 0; if(lazy_style) TCCR1B = 0x09; /1min到 懒人模式响铃 if(+time1 = 60) time1 = 0; if(+time2 = 24) time2 = 0; if(+week=7) week=0; if(time2=time_clockweek2)&(time1=time_clockweek1)&(time_clockweek0!=
15、week) if(time_clockweek0)=(10+week) ci=week_clockweek;TCCR1B = 0x09;lazy_style=1; if(time_clockweek0+=10)(30+week) time_clockweek0=20+week; cci=week_clockweek; /周闹钟时间到响铃 同时懒人模式启动 if(time2=time_clock72)&(time1=time_clock71)&(time_clock70!=7) if(time_clock70)=(17) cci=week_clockweek; if(time_clock70+=
16、10)(37) time_clock70=27; cci=week_clock7; /日闹钟时间到响铃 同时懒人模式启动 if(+return_time =20) & (clock_state != 6)|(clock_style=1) clock_state = 6;clock_style=0; if(clock_style = 1) ctime_to_disbuffer(ci); if(clock_state!=0)time_to_disbuffer(time); if(key_stime_ok) /10ms到,键处理 key_stime_ok = 0; key_temp = read_k
17、ey(); /调用按键接口程序 if(clock_style) /判断是否处于闹钟设置状态 if(key_temp) /确认有键按下 return_time = 0; if(key_temp = key_k1) if(+clock_state = 7) clock_state = 0; if(clock_state = 0) ctime_to_disbuffer(ci); if(clock_state = 6) if(clock_state = 0) & (key_temp = key_k2) if(+ci=8) ci=0; ctime_to_disbuffer(ci); if(clock_s
18、tate = 1) & if(time_clockci0+=10)(30+ci) time_clockci0=ci; ctime_to_disbuffer(ci); if(clock_state=6) & if(+week_clockci)=8) week_clockci=0; cci=week_clockci; if(clock_state1) & (key_temp = key_k2) /K2键按下 if(clock_state % 2) time_clockciclock_state / 2 += 10; else if(time_clockciclock_state / 2 % 10) = 9) time_clockciclock_state / 2 -= 9; else time_clockcicloc
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2