相关知识

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

相关知识:1.要产生音频脉冲,只要算出某一音频的周期(1/频率),然后将此周期除以2,即为半周期的时间。利用定时器计时这个半周期时间,每当计时到后就将输出脉冲的I/O反相,然后重复计时此半周期时间再对I/O反相,就可在I/O脚上得到此频率的脉冲。2.利用8051的内部定时器使其工作在计数器模式MODE1下,改变计数值TH0及TL0以产生不同频率的方法。3.例如频率为523Hz,其周期T=1/523=1912us,因此只要令计数器计时956us/1us=956,在每计数956次时将I/O反相,就可得到中音DO(523Hz)。计数脉冲值与频率的关系公式如下:N=Fi÷2÷FrN:计数值;Fi:内部计时一次为1us,故其频率为12MHz;Fr:要产生的频率;4.其计数值的求法如下:T=65536-N=65536-Fi÷2÷Fr例如:设K=65536,F=1000000=Fi=1MHz,求低音DO(261MHz)、中音DO(523MHz)、高音DO(1046MHz)的计数值。T=65536-N=65536-Fi÷2÷Fr=65536-1000000÷2÷Fr=65536-500000/Fr低音DO的T=65536-500000/262=63627中音DO的T=65536-500000/523=64580高音DO的T=65536-500000/1047=650595.C调各音符频率与计数值T的对照表如下:表1C调各音符频率与计数值T的对照表音符低1DO频率(Hz)简谱码(T值)音符频率(Hz)简谱码(T值)26263628#4FA#74064860#1DO#27763731中5SO78464898低2RE#2RE#29463835#5SO#8316493431163928中6LA88064968低3M33064021#693264994低4FA34964103中7SI98865030#4FA#37064185高1DO104665058低5SO39264260#1DO#110965085#5SO#41564331高2RE117565110低6LA44064400#2RE#124565134#646664463高3M131865157低7SI49464524高4FA139765178中1DO52364580#4FA#148065198#1DO#55464633高5SO156865217中2RE58764684#5SO#166165235#2RE#62264732高6LA176065252中3M65964777#6186565268中4FA69864820高196765283表2节拍与节拍码对照节拍码节拍数节拍码节拍数11/4拍11/8拍22/4拍21/4拍33/4拍33/8拍41拍41/2拍51又1/4拍55/8拍61又1/2拍63/4拍82拍81A2又1/2拍A1又1/4拍C3拍C1又1/2拍F3又3/4拍表3各调1/4节拍的时间设定各调1/4节拍的时间设定曲调值DELAY曲调值DELAY调4/4125毫秒调4/462毫秒调3/4187毫秒调3/494毫秒调2/4250毫秒调2/4125毫秒1/4拍的延迟时间=187毫秒DELAY:MOVR7,#02D2:MOVR4,#187别的延迟值,只需修改这儿的值为相应值,即可。D3:MOVR3,#248DJNZR3,$DJNZR4,D3DJNZR7,D2DJNZR5,DELAY节拍值放在R5,决定节拍RET建立音乐的步骤:1.先把乐谱的音符找出,然后建立T值表的顺序。2.把T值表建立在TABLE1,构成发音符是计数值放在“TABLE”。3.简谱码(音符)为高位,节拍为(节拍数)为低4位,音符节拍码放在程序的“TABLE”处。相关知识:每一音符使用1个字节,字节的高4位代表音符的高低,低4位代表音符的节拍,表2为节拍与节拍码的对照。如果1拍为0.4秒,1/4拍是0.1秒,只要设定延迟时间就可求得节拍的时间。假使1/4拍为1DELAY,则1拍应为4DELAY,以此类推。所以只要求得1/4拍的DEALY时间,其余的节拍就是它的倍数,如表3为1/4和1/8节拍的时间设定。简谱发音简谱码T值5低音SO1642606低音LA2644007低音TI3645241中音DO4645802中音RE5646843中音MI3647774中音FA7648205中音SO8648986中音LA9649687中音TIA650301高音DOB650582高音REC651103高音MID651574高音FAE651785高音SOF65217不发音0节拍码节拍数11/4拍22/4拍33/4拍41拍51又1/4拍61又1/2拍82拍A2又1/2拍C3拍F3又3/4拍表4简谱对应的简谱码、T值、节拍数#includereg51.h#defineuintunsignedint#defineucharunsignedcharuchar*TABLE;codeuintTABLE1[15]={64260,64400,64524,64580,64684,64777,64820,64898,64968,65030,65058,65110,65157,65178,65217};codeucharSONG[]={//1.迟来的爱//00x08,0x08,//10x02,0x12,0x42,0x62,0x52,0x42,0x21,11,0x18,0x18,0x02,0x22,0x42,0x82,0x92,0x82,0x61,0x51,0x42,0x58,0x58,//20x66,0x51,0x61,0x84,0x62,0x82,0x52,0x62,0x42,0x52,0x28,0x52,0x42,0x52,0x62,0x94,0x81,0x91,0x81,0x61,0x1C,0x12,0x82,//30x68,0x02,0x92,0x82,0x42,0x5C,0x12,0x62,0x58,0x02,0x42,0x51,0x41,0x22,0x4C,0x62,0x52,//40x66,0x82,0x92,0x82,0x61,0x51,0x41,0x51,0x6C,0x52,0x62,0x53,0x63,0x52,0x42,0x42,0x22,0x1C,0x12,0x22,//50x42,0x44,0x51,0x61,0x82,0x84,0x61,0x81,0x96,0x82,0x66,0x51,0x61,0x56,0x42,0x22,0x42,0x82,0x62,0x5C,0x62,0x52,//60x66,0x82,0x92,0x82,0x61,0x51,0x41,0x51,0x6C,0x52,0x62,0x56,0x62,0x52,0x42,0x42,0x22,0x1C,0x12,0x22,//70x42,0x44,0x51,0x61,0x82,0x84,0x61,0x81,0x96,0x82,0x66,0x51,0x61,0x56,0x62,0x92,0x82,0x62,0x52,0x4C,0x62,0x61,0x81,//80x9C,0x81,0x91,0x81,0x61,0x6C,0x82,0x62,0x56,0x42,0x24,0x42,0x52,0x6C,0x62,0x61,0x81,//90x9C,0xB2,0x92,0x8C,0x82,0x92,0xB2,0xB2,0xB2,0x92,0xD4,0xC1,0xD1,0xC1,0xB1,0xCC,0xB2,0xB1,0xC1,//A0xDC,0xD2,0xC1,0xB1,0x9C,0x92,0x91,0xC1,0x92,0x84,0x92,0x82,0x62,0x51,0x61,0x51,0x41,0x48,0x48,//B0x42,0x41,0x51,0x66,0x82,0x91,0xB1,0x92,0x86,0x88,0x42,0x41,0x51,0x66,0x42,0x41,0x51,0x22,0x16,0x18,0x86,0x62,0x58,//C0x83,0x91,0x62,0x82,0x58,0x52,0x62,0x52,0x42,0x22,0x12,0x62,0x52,0x4C,0x62,0x52,//60x66,0x82,0x92,0x82,0x61,0x51,0x41,0x51,0x6C,0x52,0x62,0x56,0x62,0x52,0x42,0x42,0x22,0x1C,0x12,0x22,//70x42,0x44,0x51,0x61,0x82,0x84,0x61,0x81,0x96,0x82,0x66,0x51,0x61,0x56,0x62,0x92,0x82,0x62,0x52,0x4C,0x62,0x61,0x81,//80x9C,0x81,0x91,0x81,0x61,0x6C,0x82,0x62,0x56,0x42,0x24,0x42,0x52,0x6C,0x62,0x61,0x81,//90x9C,0xB2,0x92,0x8C,0x82,0x92,0xB2,0xB2,0xB2,0x92,0xD4,0xC1,0xD1,0xC1,0xB1,0xCC,0xB2,0xB1,0xC1,//A0xDC,0xD2,0xC1,0xB1,0x9C,0x92,0x91,0xC1,0x92,0x84,0x92,0x82,0x62,0x51,0x61,0x51,0x41,0x4C,0x62,0x61,0x81,//80x9C,0x81,0x91,0x81,0x61,0x6C,0x82,0x62,0x56,0x42,0x24,0x42,0x52,0x6C,0x62,0x61,0x81,//90x9C,0xB2,0x92,0x8C,0x82,0x92,0xB2,0xB2,0xB2,0x92,0xD4,0xC1,0xD1,0xC1,0xB1,0xCC,0xB2,0xB1,0xC1,//A0xDC,0xD2,0xC1,0xB1,0x9C,0x92,0x91,0xC1,0x92,0x84,0x92,0x82,0x62,0x51,0x61,0x51,0x41,0x4C,0x62,0x61,0x81,//D0x66,0x51,0x61,0x86,0x61,0x81,0x52,0x62,0x52,0x42,0x28,0x82,0x91,0x01,0x62,0x11,0x52,0x11,0x01,0x62,0x54,0x48,0x48,0x00};ucharljsz;ucharjpm;ucharyfm;uchart0=0;uinti=0;sbitSpeaker=P1^0;uintk;voidDelay1(){for(k=0;k20000;k++);}voidLignt(){uchart;for(t=0;t10;t++){P2=0xff;Delay1();P2=0x00;Delay1();}}voidLignt1(){P2=0xaa;Delay1();P2=0x55;Delay1();}voidDelay(uchart0)//延时{while(t0--)//决定节拍Lignt1();

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功