Verilog | HDL 音乐盒设计(代码类)
博主github:https://github.com/MichaelBeechan
博主CSDN:https://blog.csdn.net/u011344545
module music(clk,beep,pause,stop,switch,led); //定义时钟及几个功能变量
input clk,pause,switch,stop; //输入变量
output beep; //输出变量,即蜂鸣器发声
output[8:1]led;
reg[8:1]led;
reg beep_r; //定义几个中间变量
reg a;
reg b;
reg c;
reg[7:0]state;
reg[7:0]state1;
reg[7:0]state2;
reg[15:0]count,count_end;
reg[23:0]count1;
parameter L_5=16'd61224,L_6=16'd54545,M_1=16'd45863,M_2=16'd40864,M_3=16'd36402,M_5=16'd30612,M_6=16'd27273,H_1=16'd22956;
parameter TIME=12000000; //时钟频率
assign beep=beep_r;
always@(posedge pause)
begin
a=!a; //暂停
end
always@(posedge stop)
begin
b=!b; //停止
end
always@(posedge switch)
begin
c=!c; //切换
end
always@(posedge clk)
begin if(a==1||b==1)
beep_r=1'b0;else
count<=count+1'b1;if(count==count_end)
begin
count<=16'h0;
beep<=!beep_r;
end
end
always@(posedge clk)
begin
if(count1<TIME )count=count1+1'b1;
else
begin
count1=24'd0;
if(state1==8'd147||state2==8'd60)
state=8'd0;
if(a==1&b==0)
begin
state=state;
end
if(a==0&b==0)
state=state+1'b1;
if(a==0&b==1)
begin
state=8'd0;
end
if(a==1&b==1)
state=state+1'b1;
if(c==1) //曲目1
begin
state1=state;
case(state1)
8'd0,8'd1: count_end=L_5;
8'd2,8'd3,8'd4,8'd5,8'd6,8'd7,8'd8: count_end=M_1;
8'd9,8'd10: count_end=M_3;
8'd11,8'd12,8'd13,8'd14: count_end=M_2;
8'd15: count_end=M_1;
8'd16,8'd17: count_end=M_2;
8'd18,8'd19: count_end=M_3;
8'd20,8'd21,8'd22,8'd23,8'd24: count_end=M_1;
8'd25,8'd26: count_end=M_3;
8'd27,8'd28: count_end=M_5;
8'd29,8'd30,8'd31,8'd32,8'd33: count_end=M_6;
8'd34,8'd35,8'd36,8'd37,8'd38: count_end=M_6;
8'd39,8'd40,8'd41,8'd42: count_end=M_5;
8'd43,8'd44,8'd45: count_end=M_3;
8'd46,8'd47: count_end=M_1;
8'd48,8'd49,8'd50,8'd51: count_end=M_2;
8'd52: count_end=M_1;
8'd53,8'd54: count_end=M_2;
8'd55,8'd56: count_end=M_3;
8'd57,8'd58,8'd59,8'd60: count_end=M_1;
8'd61,8'd62,8'd63: count_end=L_6;
8'd64,8'd65: count_end=M_5;
8'd66,8'd67,8'd68,8'd69: count_end=M_1;
8'd70,8'd71,8'd72,8'd73: count_end=M_1;
8'd74,8'd75: count_end=M_6;
8'd76,8'd77,8'd78,8'd79: count_end=M_5;
8'd80,8'd81,8'd82: count_end=M_3;
8'd83,8'd84: count_end=M_1;
8'd85,8'd86,8'd87,8'd88: count_end=M_2;
8'd89: count_end=M_1;
8'd90,8'd91: count_end=M_2;
8'd92,8'd93: count_end=M_6;
8'd94,8'd95,8'd96,8'd97: count_end=M_5;
8'd98,8'd99,8'd100: count_end=M_3;
8'd101,8'd102: count_end=M_5;
8'd103,8'd104,8'd105,8'd106: count_end=M_6;
8'd107,8'd108,8'd109,8'd110: count_end=M_6;
8'd111,8'd112: count_end=H_1;
8'd113,8'd114,8'd115,8'd116: count_end=M_5;
8'd117,8'd118,8'd119: count_end=M_3;
8'd120,8'd121: count_end=M_1;
8'd122,8'd123,8'd124,8'd125: count_end=M_2;
8'd126: count_end=M_1;
8'd127,8'd128: count_end=M_2;
8'd129,8'd130: count_end=M_3;
8'd131,8'd132,8'd133,8'd134: count_end=M_1;
8'd135,8'd136,8'd137: count_end=L_6;
8'd138,8'd139: count_end=M_5;
8'd140,8'd141,8'd142,8'd143: count_end=M_1;
8'd144,8'd145,8'd146,8'd147: count_end=M_1;
default:count_end=16'hffff;
endcase
end
if(c==0) //曲目2
begin
state2=state;
case(state)
8'd0,8'd1,8'd2: count_end=M_6;
8'd3: count_end=M_5;
8'd4,8'd5: count_end=M_3;
8'd6,8'd7,8'd8: count_end=M_5;
8'd9: count_end=H_1;
8'd10: count_end=M_6;
8'd11: count_end=M_5;
8'd12,8'd13,8'd14,8'd15: count_end=M_6;
8'd16,8'd17: count_end=M_3;
8'd18: count_end=M_5;
8'd19: count_end=M_6;
8'd20,8'd21: count_end=M_5;
8'd22: count_end=M_3;
8'd23: count_end=M_2;
8'd24: count_end=M_1;
8'd25: count_end=L_6;
8'd26: count_end=M_5;
8'd27: count_end=M_3;
8'd28,8'd29,8'd30,8'd31,8'd32,8'd33,8'd34:count_end=M_2;
8'd35: count_end=M_3;
8'd36,8'd37,8'd38: count_end=M_5;
8'd39: count_end=M_6;
8'd40,8'd41,8'd42: count_end=M_3;
8'd43,8'd44: count_end=M_2;
8'd45,8'd46,8'd47,8'd48: count_end=M_1;
8'd49,8'd50,8'd51: count_end=M_5;
8'd52: count_end=M_3;
8'd53: count_end=M_2;
8'd54: count_end=M_1;
8'd55: count_end=L_6;
8'd56: count_end=M_1;
8'd57,8'd58,8'd59,8'd60: count_end=L_5;
default:count_end=16'hffff;
endcase
end
end
end
always @(count)
begin
case(count)
L_5:led=8'b1111_1111;
L_6:led=8'b0111_1111;
M_1:led=8'b0011_1111;
M_2:led=8'b0001_1111;
M_3:led=8'b0000_1111;
M_5:led=8'b0000_0111;
M_6:led=8'b0000_0011;
H_1:led=8'b0000_0000;
default : led=8'b0;
endcase
end
endmodule
Verilog | HDL 音乐盒设计(代码类)相关推荐
- 【Verilog HDL学习之路】第一章 Verilog HDL 数字设计总论
1 Verilog HDL 数字设计总论 1.1 几个重要的概念 EDA(Electronic Design Automation) 电子技术自动化 EDA工具 类似于软件工程中的IDE(集成开发环境 ...
- (44)Verilog HDL 计数器设计
(44)Verilog HDL 计数器设计 1.1 目录 1)目录 2)FPGA简介 3)Verilog HDL简介 4)Verilog HDL 计数器设计 5)结语 1.2 FPGA简介 FPGA( ...
- (43)Verilog HDL 二分频设计
(43)Verilog HDL 二分频设计 1.1 目录 1)目录 2)FPGA简介 3)Verilog HDL简介 4)Verilog HDL 二分频设计 5)结语 1.2 FPGA简介 FPGA( ...
- (40)Verilog HDL锁存器设计
(40)Verilog HDL锁存器设计 1.1 目录 1)目录 2)FPGA简介 3)Verilog HDL简介 4)Verilog HDL锁存器设计 5)结语 1.2 FPGA简介 FPGA(Fi ...
- (135)Verilog HDL:设计一个加法器之Adder100i
(135)Verilog HDL:设计一个加法器之Adder100i 1.1 目录 1)目录 2)FPGA简介 3)Verilog HDL简介 4)VVerilog HDL:设计一个加法器之Adder ...
- (126)Verilog HDL:设计一个复用器之Always case
(126)Verilog HDL:设计一个复用器之Always case 1.1 目录 1)目录 2)FPGA简介 3)Verilog HDL简介 4)Verilog HDL:设计一个复用器之Alwa ...
- 【Verilog HDL】设计硬件电路时,如何避免生成锁存器?
这个问题很简单,前面的很多博文也多多少少提到了这个问题,(如:Verilog HDL 使用规范(一)),今天就系统地理一遍. Verilog HDL设计中容易犯的一个通病就是不正确使用语言,生成了并不 ...
- 模6计数器以及模10计数器(Verilog HDL语言设计)(Modelsim仿真与ISE综合)
目录 前言 模6计数器 Verilog HDL语言描述 测试文件 仿真电路图 RTL Schematic Technology Schematic 模10计数器 Verilog HDL语言描述 测试文 ...
- Verilog HDL语言设计计数器+加法器
完成课本例题4.12,进行综合和仿真(包括功能仿真和时序仿真),查看仿真结果,将Verilog代码和仿真波形图整理入实验报告. 功能文件: module shiyan1(out,reset,clk); ...
最新文章
- 首次揭秘!大麦如何应对超大规模高性能选座抢票?
- debain mariadb10配置root
- Android 6.0 权限管理最佳实践
- 让 fork 出来的 Github 仓库从远端仓库拖取最新的修改
- C++学习之路 | PTA乙级—— 1012 数字分类 (20分)(精简)
- Why React?
- 快速校对所有文件的md5值
- ios开发学习-指示器(HUD)效果源码分享
- [cuda]cuda驱动版本对应+旧版本cuda下载网址
- 利用Xming X Server使用服务器上使用kettle
- 今日分享-ios蓝牙
- 贝叶斯统计推断_统计推断对决:频繁主义者与贝叶斯主义者
- 《幸福人生 从心开始》讲座参后感
- Python——Day4(基础知识练习二)
- 枚举类与注解(复习)
- 商铺wifi短信验证如何实现?商铺无线wifi短信认证方案
- 3dsmax2014插件开发之环境搭建
- php 生成会员卡号,PHP生成独一会员卡号
- 文件包含(LFI/RFI)
- win10平板模式_win10隐藏的9种功能 效率提升10倍
热门文章
- 洛谷 P2888 [USACO07NOV]牛栏Cow Hurdles
- UOJ #513 [UR #19]清扫银河 (图论、线性基)
- win7 打开“计算机”慢,win7电脑启动慢解决方法
- cuda linux编译器_CUDA与Linux系统
- python 统计组合用什么库_Python数据科学,用这些库就够了
- 20211028 调节和跟踪
- bzoj:3110: [Zjoi2013]K大数查询
- 《第一行代码》学习笔记24-持久化技术(3)
- int转string的3种方法
- System.setProperty()