資源描述:
《樂曲演奏電路》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、9.10樂曲演奏電路低音頻率/Hz中音頻率/Hz高音頻率/Hz1261.61C523.311046.52293.72D587.321174.73329.63E659.331318.54349.24F698.541396.953925G784515686A4406880617607B493.97987.871975.5音調(diào)控制預置計數(shù)器6MHz二分頻器揚聲器低音66MHz/2/440Hz=68189365+6818=16383音長控制全音符1秒四分音符4Hz八分音符8Hz曲譜產(chǎn)生4Hz音符顯示數(shù)碼管[9.22]梁祝樂曲演奏電路/*clk50m輸入時鐘
2、,50MHzspeaker驅(qū)動揚聲器的方波high,med,low顯示高,中,低音*/modulesong(clk50m,speaker,high,med,low);inputclk50m;outputregspeaker;outputreg[3:0]high,med,low;regclk_6mhz;//產(chǎn)生音階的基準時鐘regclk_4hz;//控制音長的時鐘reg[13:0]divider,origin;//分頻計數(shù),預置數(shù)wirecarry;//分頻進位reg[7:0]counter;//節(jié)拍計數(shù)reg[2:0]count8;//分頻計數(shù)re
3、g[19:0]count20;//分頻計數(shù)//分頻得到6MHz時鐘always@(posedgeclk50m)if(count8==7)begincount8<=0;clk_6mhz<=1;endelsebegincount8<=count8+1;clk_6mhz<=0;end//分頻得到4Hz時鐘always@(posedgeclk_6mhz)if(count20==781250)beginclk_4hz<=~clk_4hz;count20<=0;endelsebegincount20<=count20+1;end//通過置數(shù),改變分頻比alwa
4、ys@(posedgeclk_6mhz)if(divider==16383)begincarry<=1;divider<=origin;endelsebegindivider<=divider+1;carry=0;end//得到驅(qū)動揚聲器的方波always@(posedgecarry)speaker<=~speaker;always@(posedgeclk_4hz)//預置分頻比case({high,med,low})'h001:origin<=4915;//低音1'h002:origin<=6168;//低音2……'h700:origin<=14
5、864;//高音7'h000:origin<=16383;//休止符endcaseend//分頻比預置'h003:origin<=7281;//低音3'h004:origin<=7792;//低音4'h005:origin<=8730;//低音5'h006:origin<=9365;//低音6'h007:origin<=10310;//低音7'h010:origin<=10647;//中音1'h020:origin<=11272;//中音2'h030:origin<=11831;//中音3'h040:origin<=12094;//中音4'h050
6、:origin<=12556;//中音5'h060:origin<=12974;//中音6'h070:origin<=13346;//中音7'h100:origin<=13516;//高音1'h200:origin<=13829;//高音2'h300:origin<=14109;//高音3//演奏樂譜always@(posedgeclk_4hz)beginif(counter==134)counter<=0;//循環(huán)演奏elsecounter<=counter+1;case(counter)0:{high,med,low}<='h003;//低31
7、:{high,med,low}<='h003;//持續(xù)4拍2:{high,med,low}<='h003;3:{high,med,low}<='h003;……134:{high,med,low}<='h000;default:{high,med,low}<='h000;endcaseendendmodule