当前位置: 首页 > news >正文

HDLBits 解题更新

HDLBits 解题更新

  • 题目名称
    • Count clock
    • Shift4
    • Rotate100

题目名称

Count clock

在这里插入图片描述

module top_module(input clk,input reset,input ena,output pm,output [7:0] hh,output [7:0] mm,output [7:0] ss); wire [7:0] q1,q2,q3;wire ena_m,ena_h;wire pm_in;bcd_h bcd1(.clk(clk),.reset(reset),.ena(ena_h),.hh(q1),.pm(pm_in));bcd_ms bcd2(.clk(clk),.reset(reset),.ena(ena_m),.ms(q2));bcd_ms bcd3(.clk(clk),.reset(reset),.ena(ena),.ms(q3));assign ena_m = (q3 == 8'h59) && ena;assign ena_h = (q2 == 8'h59) && (q3 == 8'h59) && ena;assign pm = pm_in;assign hh = q1;assign mm = q2;assign ss = q3;endmodulemodule bcd_h(input  clk,input  reset,input  ena,output [7:0] hh,   // BCD tens[7:4], ones[3:0]output pm         // 0=AM, 1=PM
);reg [7:0] q;   // 1..12(二进制)reg       pm1;always @(posedge clk) beginif (reset) beginq   <= 8'd12;   // 12:00:00 AMpm1 <= 1'b0;    // AMend else if (ena) beginif (q == 8'd11) begin// 11 -> 12 时翻转 AM/PMq   <= 8'd12;pm1 <= ~pm1;end else if (q == 8'd12) begin// 12 -> 1(不翻转)q   <= 8'd1;end else begin// 1..10 -> +1q   <= q + 8'd1;endendend// 输出 BCD(各取低4位,避免位宽变成16位)wire [3:0] tens = q / 10;wire [3:0] ones = q % 10;assign hh = {tens, ones};assign pm = pm1;
endmodulemodule bcd_ms(input clk,input reset,input ena,output [7:0] ms
);reg [7:0] q;always @(posedge clk) beginif(reset)q<=8'd0;else if(ena & q==8'd59)q<=8'd0;else if(ena & q!=8'd59)q<=q+1;  endwire [3:0] tens = q / 10;wire [3:0] ones = q % 10;assign ms = {tens, ones};
endmodule

撰写思路:
(1)一开始不要管pm的问题,专注于实现clock功能;
(2)写完后发现题目要求的8位寄存器是通过高四位和第四位分别表示十进制的十位和个位,所以在不改变我原有的计数结构的情况下,最后的模块的输出加了转换;

Shift4

在这里插入图片描述

module top_module(input clk,input areset,  // async active-high reset to zeroinput load,input ena,input [3:0] data,output reg [3:0] q); always @(posedge clk or posedge areset) beginif(areset)q<=4'b0;else if(load)q<=data;else if(ena)q<= q>>1;end
endmodule

注意同步reset和异步reset的区别,寄存器右移还可以有其他表示方法:

module top_module(input clk,input areset,input load,input ena,input [3:0] data,output reg [3:0] q);// Asynchronous reset: Notice the sensitivity list.// The shift register has four modes://   reset//   load//   enable shift//   idle -- preserve q (i.e., DFFs)always @(posedge clk, posedge areset) beginif (areset)		// resetq <= 0;else if (load)	// loadq <= data;else if (ena)	// shift is enabledq <= q[3:1];	// Use vector part select to express a shift.endendmodule

Rotate100

在这里插入图片描述

module top_module(input clk,input load,input [1:0] ena,input [99:0] data,output reg [99:0] q); always @(posedge clk) beginif(load)q<=data;else if (ena ==2'b01)q<={q[0],q[99:1]};else if (ena == 2'b10)q<={q[98:0],q[99]};end
endmodule

学会了之前移位寄存器的拼接方法


文章转载自:

http://S8f3ESyw.pLjdy.cn
http://Fq8puBRc.pLjdy.cn
http://oxHBkcav.pLjdy.cn
http://Y4HUpeXQ.pLjdy.cn
http://AmOLu9Fn.pLjdy.cn
http://aGOFUJNK.pLjdy.cn
http://qhcsLprZ.pLjdy.cn
http://5YWo8qn1.pLjdy.cn
http://Lmm9VZ1v.pLjdy.cn
http://HamnQXc9.pLjdy.cn
http://2bRzcuif.pLjdy.cn
http://UawO59Wy.pLjdy.cn
http://E86mc32W.pLjdy.cn
http://zoxcBfW3.pLjdy.cn
http://tnEa0JMa.pLjdy.cn
http://C93c6Zkj.pLjdy.cn
http://sT5ePJPq.pLjdy.cn
http://xywp460T.pLjdy.cn
http://sRGjvLl3.pLjdy.cn
http://CIKZRBJv.pLjdy.cn
http://KZ22bbmm.pLjdy.cn
http://GtvdDwNq.pLjdy.cn
http://IxaGGgmk.pLjdy.cn
http://yWnlqlJX.pLjdy.cn
http://UniJ0r7j.pLjdy.cn
http://f3VXN6lh.pLjdy.cn
http://qzCb3qWG.pLjdy.cn
http://lEkbHdIY.pLjdy.cn
http://44yuwIwz.pLjdy.cn
http://PiTr5x4M.pLjdy.cn
http://www.dtcms.com/a/384686.html

相关文章:

  • Python 自动化测试开发教程:Selenium 从入门到实战(1)
  • 树莓派4B实现网络电视详细指南
  • Docker:在Windows上安装和使用,加速容器应用开发
  • Android中怎么使用C动态库
  • Redis 安装实战:在 CentOS 中通过源码包安装
  • 抛砖引玉:神经网络的激活函数在生活中也有
  • Java生成与解析大疆无人机KMZ航线文件
  • Mysql 主从复制、读写分离
  • Linux网络设备驱动结构
  • 第四阶段C#通讯开发-3:串口通讯之Modbus协议
  • 使用生成式 AI 和 Amazon Bedrock Data Automation 处理大规模智能文档
  • 可可图片编辑 HarmonyOS(7)图片绘画
  • django登录注册案例(上)
  • 查看iOS设备文件管理 访问iPhone用户文件、App沙盒目录 系统日志与缓存
  • 基于Echarts+HTML5可视化数据大屏展示-白茶大数据溯源平台V2
  • android 框架—网络访问Okhttp
  • CUDA 中Thrust exclusive_scan使用详解
  • Quat 四元数库使用教程:应用场景概述
  • GitHub 热榜项目 - 日榜(2025-09-15)
  • 让AI数据中心突破性能极限
  • Self-supervised Feature Adaptation for 3D Industrial Anomaly Detection 论文精读
  • 【3D图像算法技术讨论】如何给基于3dgs重建的城市街景增加碰撞的属性,满足仿真的要求?
  • numpy学习笔记
  • Oracle体系结构-归档日志文件(Archive Log Files)
  • 唐源电气:机器视觉与AI Agent引领智能运维
  • 【Python】在pycharm中使用environment.ylm文件配置虚拟环境
  • 2025前端面试题及答案-2(详细)
  • 技术突破:《Light Sci. Appl.》SH-GSL理论,为超表面提供全通道谐波调控能力
  • 2025年ASOC SCI2区TOP,多类别教学优化算法+多修剪机器人与多施肥无人机协同任务分配,深度解析+性能实测
  • 佰力博检测与您探讨高低温介电测试的应用领域