1、piano(in,clk_6MHz,clk_4Hz,song,speaker);inputin,clk_6MHz,clk_4Hz,song;outputspeaker;regreg7:0state;song_on;wire6:in;reg3:high,med,low;reg13:divider,origin;counter;out;wirecarry;reg20:i;parameterzero=8b0000_0000, /用于表示按键的状态.one=8b0000_0001, two=8b0000_0010, three=8b0000_0100, four=8b0000_1000, five=8
2、b0001_0000, six=8b0010_0000, seven=8b0100_0000;initial begin song_on=0;end always(posedgesong) /用于判断按键8(即乐曲播放按钮)的状态判断.=song_on;clk_6MHz) if(song_on) speaker=out;else begincase(in) zero:i=11451) speaker=!=i+1;two:/re =10204) three:/mi =9091) four:/fa =8596) five:/so =7653) six:/lo =6818) seven:/si =6073) default:endcase assigncarry=(divider=16383); /乐曲if(carry)divider=origin;else=divider+1;carry) out=out;/2分频产生方波信号 clk_4Hz)