1、单片机音乐设计 单片机音乐设计题 目: 龙的传人 作 者: 焦亚琪_ 一、龙的传人的简谱二、龙的传人的硬件结构:三、龙的传人的程序如下:#include AT89X52.H#define F1 10000 /1/4#define F2 20000 /1/2#define F3 40000 /1/1unsigned char t0_high=0x00; /T0高8位unsigned char t0_low=0x00; /T0低8位unsigned char YH21= 0xF7,0xF8,0xF9,0xF9,0xFA,0xFB,0xFB, 0xFB,0xFC,0xFC,0xFC,0xFD,0xF
2、D,0xFD, 0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE;unsigned char YL21= 0xD8,0xBC,0x85,0xE5,0x92,0x29,0xB0, 0xEF,0x62,0xC7,0xF5,0x4C,0x97,0xDC, 0xFB,0x34,0x67,0x7D,0xA8,0xCF,0xF1;sbit Q=P27;stop1(void) unsigned int i; TR0=0; for(i=0;i=4700;i+); TR0=1;stop2(void) unsigned int i; TR0=0; for(i=0;i=11400;i+); TR
3、0=1;delay(n) unsigned int i; for(i=0;i=n;i+);void timer0() interrupt 1 /用于产生音符的T0中断服务程序 TH0=t0_high; TL0=t0_low;Q=Q; /取反beep引脚,发声void main(void) TMOD=0X01; /T0方式1 TR0=0; /关闭T0(不发声) TH0=0xFF; TL0=0x00; ET0=1; /允许T0中断 EA=1; /允许总中断 TR0=1; while(1) t0_high=YH13; t0_low=YL13; delay(F3); stop1(); t0_high=
4、YH14; t0_low=YL14; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F2); stop1(); t0_high=YH16; t0_low=YL16; delay(F3); stop1(); t0_high=YH17; t0_low=YL17; delay(F2); stop1(); t0_high=YH16; t0_low=YL16; delay(F2); stop1(); stop2(); /第一节 t0_high=YH15; t0_low=YL15; delay(F3); stop1(); t0_high=YH15
5、; t0_low=YL15; delay(F2); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); t0_high=YH13; t0_low=YL13; delay(F3+F3+F3); stop1(); stop2(); /第二节 t0_high=YH13; t0_low=YL13; delay(F3); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F2); stop1(); t0_high=YH
6、16; t0_low=YL16; delay(F3); stop1(); t0_high=YH17; t0_low=YL17; delay(F2); stop1(); t0_high=YH16; t0_low=YL16; delay(F2); stop1(); stop2(); /第三节 t0_high=YH15; t0_low=YL15; delay(F2); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F2); stop1(); t0_high=YH16;
7、t0_low=YL16; delay(F2); stop1(); t0_high=YH17; t0_low=YL17; delay(F3+F3+F3); stop1(); stop2(); /第四节 t0_high=YH13; t0_low=YL13; delay(F3); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F2); stop1(); t0_high=YH16; t0_low=YL16; delay(F3); stop1(); t0_high=YH17
8、; t0_low=YL17; delay(F2); stop1(); t0_high=YH16; t0_low=YL16; delay(F2); stop1(); stop2(); /第五节 t0_high=YH15; t0_low=YL15; delay(F3); stop1(); t0_high=YH15; t0_low=YL15; delay(F2); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); t0_high=YH13; t0_low=YL13; delay(F3+F3+F3); stop1(); stop2(); /
9、第六节 t0_high=YH14; t0_low=YL14; delay(F3); stop1(); t0_high=YH14; t0_low=YL14; delay(F3); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F3); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); stop2(); /第七节 t0_high=YH13; t0_low=YL13; delay(F3); stop1();
10、t0_high=YH13; t0_low=YL13; delay(F2); stop1(); t0_high=YH12; t0_low=YL12; delay(F2); stop1(); t0_high=YH13; t0_low=YL13; delay(F3+F3+F3); stop1(); stop2(); /第八节 t0_high=YH17; t0_low=YL17; delay(F3); stop1(); t0_high=YH17; t0_low=YL17; delay(F3); stop1(); t0_high=YH17; t0_low=YL17; delay(F3); stop1()
11、; t0_high=YH16; t0_low=YL16; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F2); stop1(); stop2(); /第九节 t0_high=YH16; t0_low=YL16; delay(F2); stop1(); t0_high=YH16; t0_low=YL16; delay(F2); stop1(); t0_high=YH17; t0_low=YL17; delay(F2); stop1(); t0_high=YH16; t0_low=YL16; delay(F3+F3+F3); stop1
12、(); stop2(); /第十节 t0_high=YH15; t0_low=YL15; delay(F3); stop1(); t0_high=YH15; t0_low=YL15; delay(F3); stop1(); t0_high=YH15; t0_low=YL15; delay(F3); stop1(); t0_high=YH16; t0_low=YL16; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F2); stop1(); stop2(); /第十一节 t0_high=YH14; t0_low=YL14; delay
13、(F3); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F2); stop1(); t0_high=YH14; t0_low=YL14; delay(F3+F3+F3); stop1(); stop2(); /第十二节 t0_high=YH17; t0_low=YL17; delay(F3); stop1(); t0_high=YH17; t0_low=YL17; delay(F3); stop1(); t0_high=YH17; t0_low=YL17; de
14、lay(F3); stop1(); t0_high=YH16; t0_low=YL16; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F2); stop1(); stop2(); /第十三节 t0_high=YH16; t0_low=YL16; delay(F2); stop1(); t0_high=YH16; t0_low=YL16; delay(F2); stop1(); t0_high=YH17; t0_low=YL17; delay(F2); stop1(); t0_high=YH16; t0_low=YL16; delay
15、(F3+F3+F3); stop1(); stop2(); /第十四节 t0_high=YH15; t0_low=YL15; delay(F3); stop1(); t0_high=YH15; t0_low=YL15; delay(F3); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); t0_high=YH15; t0_low=YL15; delay(F3); stop1(); t0_high=YH14; t0_low=YL14; delay(F2); stop1(); stop2(); /第十五节 t0_high=YH13;
16、t0_low=YL13; delay(F2); stop1(); t0_high=YH13; t0_low=YL13; delay(F2); stop1(); t0_high=YH12; t0_low=YL12; delay(F2); stop1(); t0_high=YH13; t0_low=YL13; delay(F3+F3+F3); stop1(); stop2(); /第十六节 TR0=0; while(1); 四、单片机发声原理1、用单片机产生音频脉冲 音频脉冲激音符发出各种不同的声音,通过计算音频的周期可以得出频率的脉冲。首先算出某一音频的周期(1/频率),将此音频周期除以2,即为半周期的时间,利用定时器计时这半个周期,如到半个周期时间就将输出脉冲的I/O反相。重复此计时操作,每当到半周期时间就输出脉冲的I/O反相,这样就可以得到音频的脉冲。2、用单片机实现音乐的节拍 音符节拍依靠延时程序来实现,各调1/4节拍的延时为多少。3、于蜂鸣器并联的发光二极管会与蜂鸣器同步的亮灭,表明蜂鸣器的工作状态。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1