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

Verilog刷题笔记23

题目:
Suppose you’re building a circuit to process scancodes from a PS/2 keyboard for a game. Given the last two bytes of scancodes received, you need to indicate whether one of the arrow keys on the keyboard have been pressed. This involves a fairly simple mapping, which can be implemented as a case statement (or if-elseif) with four cases.
在这里插入图片描述
解题:

module top_module (input [15:0] scancode,output reg left,output reg down,output reg right,output reg up  ); always@(*)beginup=1'b0;down=1'b0;left=1'b0;right=1'b0;case(scancode)16'HE06B:left=1'b1;16'HE072:down=1'b1;16'HE074:right=1'b1;16'HE075:up=1'b1;endcaseendendmodule

结果正确:
在这里插入图片描述
注意点:
为避免产生锁存,必须在所有可能条件下为所有输出分配一个值(另请参阅always_if2).仅仅有一个默认案例是不够的。在所有四种情况和默认情况下,必须为所有四个输出分配一个值。这可能涉及大量不必要的键入。解决此问题的一种简单方法是在 case 语句之前为输出分配一个“默认值”:

always @(*) beginup = 1'b0; down = 1'b0; left = 1'b0; right = 1'b0;case (scancode)... // Set to 1 as necessary.endcase
end

这种代码样式可确保在所有可能的情况下都为输出分配一个值(0),除非 case 语句覆盖赋值。这也意味着 default: case 项变得不必要。

http://www.lryc.cn/news/296327.html

相关文章:

  • C#验证字符串的长度,用正则表达式 vs 字符数组长度或字符串的长度
  • opencv C++ dnn模块调用yolov5以及Intel RealSense D435深度相机联合使用进行目标检测
  • 2024牛客寒假算法基础集训营1(视频讲解全部题目)
  • 第三百一十三回
  • 倒计时61天
  • npm后Truffle找不到命令(ubantu20系统)
  • 嵌入式学习第三篇——51单片机
  • RabbitMQ详解
  • CGAL::2D Arrangements-4
  • 终端命令提示符:如何查看我们电脑端口是否被占用和处理方式
  • elasticsearch重置密码操作
  • 从零开始手写mmo游戏从框架到爆炸(零)—— 导航
  • 机器学习7-K-近邻算法(K-NN)
  • 相机图像质量研究(7)常见问题总结:光学结构对成像的影响--镜片固化
  • 猫头虎分享已解决Bug || Go Error: cannot convert int to string
  • 前端bug手册
  • Elasticsearch中Document Routing特性
  • 【Git版本控制 03】远程操作
  • 【Git】Windows下通过Docker安装GitLab
  • flutter 操作mysql
  • c++阶梯之类与对象(中)< 续集 >
  • GitLag所有操作-汇总
  • JSch - 配置SFTP服务器SSH免密登录
  • RISC-V指令格式
  • Linux 文件比较工具
  • 【GAMES101】Lecture 17 材质
  • 数模.matlab画图
  • [word] word表格表头怎么取消重复出现? #媒体#笔记#职场发展
  • vue项目开发vscode配置
  • BUUCTF-Real-[Tomcat]CVE-2017-12615