当前位置:网站首页>Verilog之数码管译码
Verilog之数码管译码
2022-07-30 09:49:00 【贱贱的剑】
参考文献:https://www.runoob.com/w3cnote/verilog-function.html
一、代码修改
参考文献中的测试代码有些不理解,自己稍作修改。四个数码管用abcdefg_x来分别表示。这里附上digital_tube代码
digital_tube.v
`timescale 1ns/1ns;
module digital_tube(
input clk,
input rstn,
input en,
input [3:0] single_digit,
input [3:0] ten_digit,
input [3:0] hundred_digit,
input [3:0] kilo_digit,
output reg [6:0] abcdefg_1, //light control
output reg [6:0] abcdefg_2,
output reg [6:0] abcdefg_3,
output reg [6:0] abcdefg_4
);
always @(posedge clk or negedge rstn) begin
if(!rstn) begin
abcdefg_1 <= 7'd0;
abcdefg_2 <= 7'd0;
abcdefg_3 <= 7'd0;
abcdefg_4 <= 7'd0;
end
else if(en) begin
abcdefg_1 <= dt_translate(single_digit);
abcdefg_2 <= dt_translate(ten_digit);
abcdefg_3 <= dt_translate(hundred_digit);
abcdefg_4 <= dt_translate(kilo_digit);
end
end
// translate function
function [6:0] dt_translate;
input [3:0] data;
begin
case(data)
4'd0: dt_translate = 7'b1111110; //number 0 -> 0x7e
4'd1: dt_translate = 7'b0110000; //number 1 -> 0x30
4'd2: dt_translate = 7'b1101101; //number 2 -> 0x6d
4'd3: dt_translate = 7'b1111001; //number 3 -> 0x79
4'd4: dt_translate = 7'b0110011; //number 4 -> 0x33
4'd5: dt_translate = 7'b1011011; //number 5 -> 0x5b
4'd6: dt_translate = 7'b1011111; //number 6 -> 0x5f
4'd7: dt_translate = 7'b1110000; //number 7 -> 0x70
4'd8: dt_translate = 7'b1111111; //number 8 -> 0x7f
4'd9: dt_translate = 7'b1111011; //number 9 -> 0x7b
endcase
end
endfunction
initial begin
$vcdpluson;
end
endmodule
自己修改的test.v文件
`timescale 1ns/1ns
module test;
reg clk;
reg rstn;
reg en;
reg [3:0] single_digit;
reg [3:0] ten_digit;
reg [3:0] hundred_digit;
reg [3:0] kilo_digit;
wire [3:0] abcdefg_1;
wire [3:0] abcdefg_2;
wire [3:0] abcdefg_3;
wire [3:0] abcdefg_4;
integer i = 0;
integer temp = 0;
digital_tube digit(
.clk (clk),
.rstn (rstn),
.en (en),
.single_digit (single_digit),
.ten_digit (ten_digit),
.hundred_digit (hundred_digit),
.kilo_digit (kilo_digit),
.abcdefg_1 (abcdefg_1),
.abcdefg_2 (abcdefg_2),
.abcdefg_3 (abcdefg_3),
.abcdefg_4 (abcdefg_4)
);
initial begin
for(i = 0; i < 9999; i = i + 1) begin
single_digit <= (i % 10);
ten_digit <= ((i % 100) / 10);
hundred_digit <= ((i % 1000) / 100);
kilo_digit <= (i / 1000);
#2;
end
end
initial begin
clk = 1'b0;
rstn = 1'b0;
en = 1'b0;
forever begin
#1;
clk = ~clk;
if ($time > 5000) begin
$finish;
end
end
end
initial begin
#1;
rstn = 1'b1;
en = 1'b1;
end
initial begin
$vcdpluson;
end
endmodule
显示了从0到9999的显示过程,每个数字显示两个时间单位
二、运行结果
- 全局图
由波形图可以看出数据的变化确实如我们所预想。

2) 一个十进制
定位到一个进位波形图
- 能看到
abcdefg_x代表4个数码管。 - 按照要求依次增加一个数。
边栏推荐
- STM32CubeMX配置生成FreeRTOS项目
- Matplotlib--plot markers
- Js array operating mobile for encapsulation
- Meikle Studio - see the actual combat notes of Hongmeng device development 4 - kernel development
- 通过构建一个顺序表——教你计算时间复杂度和空间复杂度(含递归)
- Re21: Read the paper MSJudge Legal Judgment Prediction with Multi-Stage Case Representation Learning in the Real
- idea2021+Activiti [the most complete note one (basic use)]
- 多线程保证单个线程开启事务并生效的方案
- Matplotlib--绘图标记
- Understanding of deadlock
猜你喜欢

系统设计精选 | 基于FPGA的CAN总线控制器的设计(附代码)

在机器人行业的专业人士眼里,机器人行业目前的情况如何?

PyQt5-用像素点绘制正弦曲线

Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL

Security Thought Project Summary

阿里云OSS对象存储

Flink_CDC搭建及简单使用

线程池方式开启线程--submit()和execute()的区别

Flink_CDC construction and simple use

The thread pool method opens the thread -- the difference between submit() and execute()
随机推荐
【AGC】增长服务2-应用内消息示例
方法的参数传递
梅科尔工作室-看鸿蒙设备开发实战笔记六—无线联网开发
Study Notes 10--Main Methods of Local Trajectory Generation
The thread pool method opens the thread -- the difference between submit() and execute()
Re18: Read the paper GCI Everything Has a Cause: Leveraging Causal Inference in Legal Text Analysis
唯物辩证法-条件论
MFCC to audio, the effect should not be too funny >V
idea2021+Activiti【最完整笔记一(基础使用)】
MySQL installation tutorial [installation version]
A new generation of free open source terminal tool, so cool
一个近乎完美的 Unity 全平台热更方案
debian10安装djando
flowable工作流所有业务概念
In the robot industry professionals, Mr Robot industry current situation?
Array of Shell System Learning
4. yolov5-6.0 ERROR: AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' solution
SST-Calib: A lidar-visual extrinsic parameter calibration method combining semantics and VO for spatiotemporal synchronization calibration (ITSC 2022)
606. Create a string from a binary tree (video explanation!!!)
实战演练 | 在 MySQL 中计算每日平均日期或时间间隔