当前位置:网站首页>Verilog——篮球24S计时器
Verilog——篮球24S计时器
2022-07-21 16:59:00 【爱学习的岳岳】
设计要求
(1)具有显示24秒计时功能;
(2)系统设置外部操作开关,控制计时器的直接启动(重置为24)和暂停/继续功能;
(3)计时器为24秒递减计时,其计时间隔为1秒;
(4)计时器递减计时到零时,数码显示器不能灭灯,同时发出光电报警信号。
24s倒计时
代码实现
设计模块
module varmodcnt(CP,CLR,EN,PE,D,Q,carry_out);
parameter n=4,MOD=10;
input CP,CLR,EN,PE;
input [n-1:0] D;
output reg[n-1:0] Q;
output carry_out;
/*输入:CP时钟信号,CLR清零信号,EN使能,PE预制信号,D为预置输入 输出:Q为输出4位二进制数,carry_out为借位信号*/
//敏感信号:CP上升沿,CLR下降沿,PE上升沿
[email protected](posedge CP,negedge CLR)
begin
if(!CLR) Q<='d0; //清零
else if(!EN) Q<=Q; //保持,相当于暂停
else begin
if(Q==4'b0000) Q<=MOD-1; //递减
else Q<=Q-1;
end
end
[email protected](posedge PE)
begin
Q<=D; //置数
end
assign carry_out=(Q==4'b0000); //借位信号
endmodule
module _24s(CP,EN,PE,Q1,Q0);
input CP,EN,PE;
output [3:0] Q1,Q0;
/* 输入:CP为时钟信号,EN为使能信号,PE为预置信号 输出:Q1为十位输出数,Q0为个位输出数 */
wire carry_out;
wire carry_out1;
wire CP1;
assign CP1=~carry_out; //个位数减到0时,十位数递减
wire EN1;
assign EN1=EN&~(carry_out&carry_out1); //当减为0时,不在递减
varmodcnt U1(CP1,1'b1,EN1,PE,4'b0010,Q1,carry_out1); //元件实例化
varmodcnt U0(CP,1'b1,EN1,PE,4'b0100,Q0,carry_out); //元件实例化
endmodule
测试模块
`timescale 100ms/10ms
module tb_24s();
reg CP;
reg EN;
reg PE;
wire [3:0] Q1;
wire [3:0] Q0;
_24s U(CP,EN,PE,Q1,Q0); //元件实例化
initial
$monitor($time,"\tQ1=%b,Q0=%b\n",Q1,Q0);
//时钟
initial
CP=1;
always
#5 CP=~CP;
initial
begin
//启动:产生PE上升沿,进行预置
EN=1;PE=0;
#10;
EN=1;PE=1;
#10;
//计数
EN=1;PE=0;
#260;
//启动:产生PE上升沿,进行预置
EN=1;PE=1;
#10;
EN=1;PE=0;
#20;
//暂停
EN=0;PE=0;
#20;
$stop;
end
仿真结果
显示
代码实现
设计模块
//filename:_24show.v
module _24show(
input CP,EN,PE,BL,LT,
output [6:0] L1,L0);
/* 输入:CP时钟信号,EN使能信号,PE预制信号,BL,LT, */
wire [3:0]Q1,Q0;
wire BL1;
_24s U(CP,EN,PE,Q1,Q0);
assign BL1=BL&(Q1!=4'b0000);
_74HC4511 U1(1'b0,BL1,LT,Q1,L1);
_74HC4511 U0(1'b0,BL,LT,Q0,L0);
endmodule
module _74HC4511(
input LE,BL,LT,
input [3:0] D,
output reg [6:0] L);
/* 输入输出端口说明。 输入端口: LE,BL,LT为使能信号。D为待显示的四位二进制数字。 输出端口:L为7段显示器各段的工作情况。 */
wire [2:0] E;
assign E={
LE,BL,LT}; //中间变量用于后续的控制端优先级判断
[email protected](*)
begin
if(LE==0&&BL==1&<==1)
begin
case(D)
//0-9显示。
4'b0000:L=7'b111_1110;
4'b0001:L=7'b011_0000;
4'b0010:L=7'b110_1101;
4'b0011:L=7'b111_1001;
4'b0100:L=7'b011_0011;
4'b0101:L=7'b101_1011;
4'b0110:L=7'b001_1111;
4'b0111:L=7'b111_0000;
4'b1000:L=7'b111_1111;
4'b1001:L=7'b111_1011;
//以下为无效状态
4'b1010:L=7'b000_0000;
4'b1011:L=7'b000_0000;
4'b1100:L=7'b000_0000;
4'b1101:L=7'b000_0000;
4'b1110:L=7'b000_0000;
4'b1111:L=7'b000_0000;
endcase
end
else
begin
casex(E)
3'bxx0:L=7'b111_1111; //灯测试
3'bx01:L=7'b000_0000; //灭灯
3'b111:L<=L; //锁存
endcase
end
end
endmodule
测试模块
//filename:tb_show.v
`timescale 100ms/10ms
module tb_show();
reg CP,EN,PE,BL,LT;
wire [6:0] L1,L0;
_24show U3(CP,EN,PE,BL,LT,L1,L0);
initial
$monitor($time,"\tL1=%b,L0=%b\n,",L1,L0);
initial
CP=1;
always
#5 CP=~CP;
initial
begin
BL=1'b1;LT=1'b1;EN=1;PE=0;
#10;
BL=1'b1;LT=1'b1;EN=1;PE=1;
#10;
BL=1'b1;LT=1'b1;EN=1;PE=0;
#260;
$stop;
end
endmodule
仿真结果
边栏推荐
- jmmert聚合测试报告
- 用odoo集成EFK,實現日志可視化
- R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、构建没有截距项的回归模型(模型不包含截距)
- Information sharing | hc-05 Bluetooth module information
- 特征选择小结:过滤式、包裹式、嵌入式
- R语言检验相关性系数的显著性:使用cor.test函数计算相关性系数的值和置信区间及其统计显著性(如果变量来自非正态分布总体使用Spearman方法)
- Anaconda安装jupyter lab + jupyterlsp(代码提示,代码纠错)详细搭建过程
- [binary tree] verify binary tree
- 生产环境TiDB集群缩容TiKV操作步骤
- 编码之前先保证你的硬件稳定连接!!!
猜你喜欢
FFT快速傅里叶变换在字符串匹配中的应用详解【附模板,例题】五千字详解
地址总线、数据总线、控制总线详细解释
数据分析与挖掘1
Jmter -- database performance test
IDEA 如何自动导入(import)
Percona xtradb cluster installation
Installing MySQL on Linux (CentOS)
“万物互联,使能千行百业”,2022 开放原子全球开源峰会 OpenAtom OpenHarmony 分论坛即将开幕
Detailed explanation of the application of FFT fast Fourier transform in string matching [attached template, example] 5000 word detailed explanation
Linux(Centos)安装Mysql
随机推荐
测试面试过程中遇到的问题整理
Physical address introduction "recommended collection"
特征选择小结:过滤式、包裹式、嵌入式
Spark 读取csv文件操作,option参数解释
Finer grained useeffect
西门子博图安装期间反复重启的问题处理
Airflow详细搭建过程(亲测 + 总结)
机器学习实战笔记
Matlab drawing summary of mathematical modeling
架构师进阶,微服务设计与治理的 16 条常用原则
用odoo集成EFK,实现日志可视化
更细粒度的 useEffect
“万物互联,使能千行百业”,2022 开放原子全球开源峰会 OpenAtom OpenHarmony 分论坛即将开幕
Airflow scheduling start_ Date explanation
科研总结/编程常见问题
Move! What if you can't take the PMP Exam?
C语言中逗号表达式的使用
Fast Fourier transform, Lagrange interpolation, three thousand words with examples, sister chapters, application of FFT and string matching
UNet详解(附图文和代码实现)
Explain pytorch visualization tool visdom in detail (I)