1、基于单片机智能音乐闹钟源代码0财富基于单片机智能音乐闹钟源代码/*/#include#include#define uchar unsigned char #define uint unsigned intuchar code font=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf; /uchar code tab=0xc40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0
2、e;uint code note_value14= 0,63628,63835,64021,64103,64260,64400,64524,63731,63928,0,64185,64331,64463, /低音1,2,3,4,5,6,7,#1,#2,0(#3在此程序中无需设),#4,#5,#6 相对应的定时器初值 0,64580,64684,64777,64820,64898,64968,65030,64633,64732,0,64860,64934,64994, /中音1,2,3,4,5,6,7,#1,#2,0(#3在此程序中无需设),#4,#5,#6 相对应的定时器初值 0,65058,
3、65110,65157,65178,65217,65252,65283,65085,65134,0,65198,65235,65268 /高音1,2,3,4,5,6,7,#1,#2,0(#3在此程序中无需设),#4,#5,#6 相对应的定时器初值 ; uint code song67=/* 0 嘀(按键时的嘀嗒声)*/ 0x2701,0x0,/* 1 茉莉花 */ 0x1304,0x1302,0x1502,0x1602,0x2102,0x2102,0x1602,0x1504,0x1502,0x1602,0x1507,0x1001,/* 0x1304,0x1302,0x1502,0x1602,0
4、x2102,0x2102,0x1602,0x1504,0x1502,0x1602,0x1507,0x1001,*/ 0x1504,0x1504,0x1504,0x1302,0x1502,0x1604,0x1604,0x1507,0x1001, 0x1304,0x1202,0x1302,0x1504,0x1302,0x1202,0x1104,0x1102,0x1202,0x1107,0x1001, 0x1302,0x1202,0x1102,0x1302,0x1204,0x1002,0x1302,0x1504,0x1602,0x2102,0x1507,0x1001, 0x1202,0x1302,0
5、x1502,0x1202,0x1302,0x1102,0x0602,0x0507,0x1001,0x0604,0x0602,0x1102,0x1206,0x1302,0x1102,0x1202,0x1102,0x0602,0x050d,0x0, /* 2 莫斯科郊外的晚上 */ 0x0602,0x1102,0x1302,0x1102,0x1204,0x1102,0x0702,0x1304,0x1204,0x0607,0x1001, 0x1102,0x1302,0x1502,0x1502,0x1604,0x1502,0x1402,0x1307,0x1001, 0x1414,0x1514,0x17
6、02,0x1602,0x1304, 0x1002,0x0704,0x0602,0x1302,0x1202,0x1404, 0x1004,0x1502,0x1402,0x1304,0x1202,0x1102,0x1304,0x1204,0x060c, 0x0,/* 3 祝你生日快乐 */ 0x0502,0x0502,0x0604,0x0504,0x1104,0x0708,0x0502,0x0502,0x0604,0x0504,0x1204,0x1108,0x0502,0x0502,0x1504,0x1304,0x1104,0x0704,0x0604,0x1402,0x1402,0x1304,0x
7、1104,0x1204,0x1108,0x0,/* 4 铃儿响叮当 */ 0x1302,0x1302,0x1303,0x1001, 0x1302,0x1303,0x1001, 0x1302,0x1502,0x1102,0x1202,0x1307,0x1001, 0x1402,0x1402,0x1402,0x1402,0x1402,0x1302,0x1302,0x1302,0x1302,0x1202,0x1202,0x1302,0x1204,0x1503,0x1001, 0x1302,0x1302,0x1303,0x1001, 0x1302,0x1303,0x1001, 0x1302,0x150
8、2,0x1102,0x1202,0x1307,0x1001, 0x1402,0x1402,0x1402,0x1402,0x1402,0x1302,0x1302,0x1302,0x1502,0x1502,0x1402,0x1202,0x1108,0x0,/* 5 喀秋莎 */ 0x0606,0x0702,0x1106,0x0602,0x1102,0x1102,0x0702,0x0602,0x0704,0x1002, 0x0706,0x1102,0x1206,0x0702,0x1202,0x1202,0x1102,0x0702,0x0607,0x1001, 0x1304,0x1604,0x1504
9、,0x1602,0x1502,0x1402,0x1402,0x1302,0x1202,0x1304,0x0604, 0x1002,0x1404,0x1202,0x1306,0x1102,0x0702,0x0302,0x1102,0x0702,0x0608,0x0,/* 6 欢乐颂 */ 0x1304,0x1304,0x1404,0x1504,0x1504,0x1404,0x1304,0x1204,0x1104,0x1104,0x1204,0x1304,0x1306,0x1202,0x1207,0x1001, 0x1304,0x1304,0x1404,0x1504,0x1504,0x1404,0
10、x1304,0x1204,0x1104,0x1104,0x1204,0x1304,0x1206,0x1102,0x1107,0x1001, 0x0,/* 7 四季歌 */ 0x1304,0x1302,0x1202,0x1104,0x1102,0x0702,0x0604,0x0604,0x0607,0x1001, 0x1404,0x1402,0x1302,0x1202,0x1102,0x1202,0x1402,0x130f,0x1001, 0x1404,0x1402,0x1302,0x1204,0x1202,0x1402,0x1304,0x1302,0x1102,0x0604,0x0604,0x
11、0704,0x1304,0x1302,0x1102,0x0702,0x1102,0x060f,0x0,/* 8 月亮代表我的心 */ 0x150a,0x1302,0x1202,0x1102,0x130f,0x160a,0x1402,0x1202,0x1102,0x070c,0x1002,0x0502,0x1106,0x1302,0x1506,0x1102,0x0706,0x1302,0x1504,0x1002,0x1502,0x1606,0x1702,0x2106,0x1604,0x150a,0x1302,0x1202,0x1106,0x1102,0x1104,0x1302,0x1202,0x
12、1106,0x1102,0x1104,0x1202,0x1302,0x1206,0x1102,0x0606,0x1201,0x1301,0x120c,0x1002,0x0502,0x1106,0x1302,0x1506,0x1102,0x0706,0x1302,0x1504,0x1002,0x1502,0x1606,0x1702,0x2106,0x1604,0x150a,0x1302,0x1202,0x1106,0x1102,0x1104,0x1302,0x0,/0x1202,0x1106,0x1102,0x1104,0x1202,0x1302,0x1206,0x0602,0x0704,0x1
13、102,011202,0x110c,0x1302,0x1502,0x1306,0x1202,0x1104,0x1504,0x070c,0x0602,0x0702,0x0606,0x0702,0x0604,0x0504,0x130c,0x1504,0x1306,0x1202,0x1104,0x1504,0x070c,0x0602,0x0702,0x1106,0x1102,0x1104,0x1202,0x1302,0x120c,0x1002,0x0502,0x1106,0x1302,0x1506,0x1102,0x0706,0x1302,0x1504,0x1002,0x1502,0x1606,0x
14、1702,0x2106,0x1604,0x150a,0x1302,0x1202,0x1106,0x1102,0x1104,0x1302,0x1202,0x1106,0x1102,0x1104,0x1202,0x1302,0x1206,0x0602,0x0704,0x1102,0x1202,0x1104,0x1502,0x1402,0x1304,0x1202,0x1102,0x1104,0x0702,0x0602,0x0518,0x050f,0x0,/* 9 献给爱丽丝 */ 0x2302,0x2212,0x2302,0x2212,0x2302,0x1702,0x2202,0x2102,0x16
15、04, 0x1002,0x1102,0x1302,0x1602,0x1704, 0x1002,0x1302,0x1512,0x1702,0x2104, 0x1002,0x1302,0x2302,0x2212,0x2302,0x2212,0x2302,0x1702,0x2202,0x2102,0x1604, 0x1002,0x1102,0x1302,0x1602,0x1704, 0x1002,0x1202,0x2102,0x1702,0x1604, 0x1002,0x1702,0x2102,0x2202,0x2305,0x1001, 0x1502,0x2402,0x2302,0x2205,0x1
16、001, 0x1402,0x2302,0x2202,0x2105,0x1001, 0x1302,0x2202,0x2102,0x1704, 0x1002,0x1302,0x2302,0x1002, 0x0,/ 0x2212,0x2302, 0x1002,0x1002,0x2212,0x2302,0x2212,0x2302,0x2212,0x2302,0x1702,0x2202,0x2102,0x1604, 0x1002,0x1102,0x1302,0x1602,0x1704, 0x1002,0x1302,0x1512,0x1702,0x2104, 0x1002,0x1302,0x2302,0x
17、2212,0x2302,0x2212,0x2302,0x1702,0x2202,0x2102,0x1604, 0x1002,0x1102,0x1302,0x1602,0x1704, 0x1002,0x1202,0x2102,0x1702,0x1604,0x1004,0x0,/* 10 小星星,亮晶晶 */ 0x1104,0x1104,0x1504,0x1504,0x1604,0x1604,0x1507,0x1001, 0x1404,0x1404,0x1304,0x1304,0x1204,0x1204,0x1107,0x1001, 0x1504,0x1504,0x1404,0x1404,0x13
18、04,0x1304,0x1207,0x1001, 0x1504,0x1504,0x1404,0x1404,0x1304,0x1304,0x1207,0x1001, 0x1104,0x1104,0x1504,0x1504,0x1604,0x1604,0x1507,0x1001, 0x1404,0x1404,0x1304,0x1304,0x1204,0x1204,0x1107,0x1001, 0x0,/* 11 Nokia经典铃声 */ 0x2502,0x2402,0x1604,0x1704,0x2302,0x2202,0x1404,0x1504,0x2202,0x2102,0x1304,0x15
19、04,0x210c, 0x2502,0x2402,0x1604,0x1704,0x2302,0x2202,0x1404,0x1504,0x2202,0x2102,0x1304,0x1504,0x210c,0x0/* 12 两只老虎 */ 0x1104,0x1204,0x1304,0x1104,0x1104,0x1204,0x1304,0x1104,0x1304,0x1404,0x1508,0x1304,0x1404,0x1508,0x1502,0x1602,0x1502,0x1402,0x1304,0x1104,0x1502,0x1602,0x1502,0x1402,0x1304,0x1104
20、,0x1304,0x0504,0x1108,0x1304,0x0504,0x1108,0x0 ;sbit key_select=P10; /功能键sbit key_inc=P11; / 增大建sbit key_dec=P12; / 减小键&强行关闹钟和歌曲键sbit key_alarm_or_song=P13; /调闹钟键&点歌键sbit buzzer=P00;bit music_break=0; uchar week=1,hour=12,minute=0,second=0, alarm_num,display=1,2,0,0,0,0,n=0,bit_code=0xfb,alarm_break
21、=1,flag_display=0,flag_alarm=0; /定义数组display6作为显示缓冲区,n为数组下标,flag_display用于设置时间或闹钟时的闪烁显示标志,flag_alarm用于闹钟键按下的标志 uchar display_music6=0x10,0x10,0,0,0x10,0x10,display_alarm6=0,0,0,0,0,0,alarm3=12,12,1,12,3,12,5,1,2,3,4,5,6,alarm_num=0,song_num=0;uint initial_value,count_display=0,count=0; /count_displa
22、y用于设置时间或闹钟时的闪烁显示记时变量void delay_ms(uint t) /延时1ms uint i,j; for(i=t;i0;i-) for(j=110;j0;j-); void di() /按键发声函数 buzzer=0; delay_ms(100); buzzer=1; void music(uchar song_number) uchar i,section,basic_note,changed_note,pitch,duration,note_num=0; /分别定义i,音区,基本音级,变化音级,音高,时值,所选歌曲的音符的编号 uint note; /定义音符变量 ET
23、1=1; music_break=1; note=songsong_numbernote_num; while(note!=0&music_break) section=note/0x1000; basic_note=note/0x100%0x10; changed_note=note/0x10%0x10; duration=note%0x10; if(changed_note=1) pitch=basic_note+7; pitch=basic_note; initial_value=note_valuesectionpitch; if(initial_value!=0) TH1=initi
24、al_value/256; TL1=initial_value%256; TR1=1; else TR1=0; if(key_alarm_or_song=0) delay_ms(10); if(key_alarm_or_song=0) break; for(i=duration;i0;i-) /音符延时函数 delay_ms(125); note_num+; note=songsong_numbernote_num; if(key_dec=0) /强行关闭闹钟 delay_ms(10); if(key_dec=0) while(!key_dec); break; music_break=0;
25、TR1=0; void alarm_() for(alarm_num=1;alarm_num0;k-) buzzer=0; delay_ms(100); buzzer=1; */ void scan_key() /按键扫描函数 bit flag_break=0; /flag_break作为跳出按键扫描循环程序的标志位 if(key_select=0) delay_ms(10); if(key_select=0) / 确认功能键被按下 while(!key_select); /释放 确认 di(); while(1) /时按键处理 flag_display=1; if(flag_break=1)
26、 alarm_num=0; break; if(key_alarm_or_song=0) delay_ms(10); if(key_alarm_or_song=0) flag_alarm=1; if(flag_break=1) alarm_num=0; break; alarm_num+; if(alarm_num=10) /添加闹钟时需要修改的地方! alarm_num=1; display_alarm0=alarmalarm_num0/10; display_alarm1=alarmalarm_num0%10; display_alarm2=alarmalarm_num1/10; disp
27、lay_alarm3=alarmalarm_num1%10; display_alarm4=0x10; display_alarm5=alarm_num%10; while(!key_alarm_or_song); di(); if(key_select=0) delay_ms(10); if(key_select=0) /确认功能键改时被按下 while(!key_select); /释放 确认 di(); while(1) /分按键处理 flag_display=2; if(flag_break=1) break; if(key_select=0) delay_ms(10); if(key_select=0) /
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1