基于verilog的电子琴设计Word文档下载推荐.doc
《基于verilog的电子琴设计Word文档下载推荐.doc》由会员分享,可在线阅读,更多相关《基于verilog的电子琴设计Word文档下载推荐.doc(6页珍藏版)》请在冰豆网上搜索。
piano(in,clk_6MHz,clk_4Hz,song,speaker);
input
in,clk_6MHz,clk_4Hz,song;
output
speaker;
reg
reg[7:
0]
state;
song_on;
wire[6:
in;
reg[3:
high,med,low;
reg[13:
divider,origin;
counter;
out;
wire
carry;
reg[20:
i;
parameter
zero=8'
b0000_0000,//用于表示按键的状态….
one=8'
b0000_0001,
two=8'
b0000_0010,
three=8'
b0000_0100,
four=8'
b0000_1000,
five=8'
b0001_0000,
six=8'
b0010_0000,
seven=8'
b0100_0000;
initial
begin
song_on<
=0;
end
always
@(posedge
song)//用于判断按键8(即乐曲播放按钮)的状态判断.
=~song_on;
clk_6MHz)
if(song_on)
speaker<
=out;
else
begin
case(in)
zero:
i<
one:
//do
if(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
assign
carry=(divider==16383);
//乐曲<
梁祝>
if(carry)
divider<
=origin;
else
=divider+1;
carry)
out<
=~out;
//2
分频产生方波信号
clk_4Hz)