当前位置:网站首页>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个数码管。 - 按照要求依次增加一个数。
边栏推荐
- mysql安装教程【安装版】
- 死锁的理解
- Flink_CDC construction and simple use
- If someone asks you about distributed transactions again, throw this to him
- Do you really understand the 5 basic data structures of Redis?
- 你真的懂Redis的5种基本数据结构吗?
- 实战演练 | 在 MySQL 中计算每日平均日期或时间间隔
- Paper reading: SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
- 时刻铭记:总有一天你将破蛹而出
- spark udf accepts and handles null values.
猜你喜欢

Alibaba Cloud OSS Object Storage

多线程保证单个线程开启事务并生效的方案

自适应控制——仿真实验一 用李雅普诺夫稳定性理论设计自适应规律

ospf2双点双向重发布(题2)
![MySQL installation tutorial [installation version]](/img/e9/9c7b0e3aac22206d126de428c1a4bd.png)
MySQL installation tutorial [installation version]

(***重点***)Flink常见内存问题及调优指南(一)

百度推广助手遇到重复关键字,验证错误,怎么一键删除多余的

(***Key points***) Flink common memory problems and tuning guide (1)

A new generation of free open source terminal tool, so cool

shell script
随机推荐
BERT pre-training model series summary
Paper reading: SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
(文字)无框按钮设置
Online target drone prompt.ml
[100个Solidity使用技巧]1、合约重入攻击
在机器人行业的专业人士眼里,机器人行业目前的情况如何?
[AGC] Growth Service 2 - In-App Message Example
Re17: Read the paper Challenges for Information Extraction from Dialogue in Criminal Law
Study Notes 10--Main Methods of Local Trajectory Generation
Flink_CDC construction and simple use
梅科尔工作室-看鸿蒙设备开发实战笔记六—无线联网开发
Nacos configuration in the project of battle
[Deep Learning] (Problem Record)
- Linear Regression - Small Batch Stochastic Gradient Descent PyQt5-绘制不同类型的直线
线上靶机prompt.ml
OC-关于alloc和dealloc(还没开始写)
Meikle Studio-Look at the actual combat notes of Hongmeng device development six-wireless networking development
4、yolov5-6.0 ERROR: AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘ 解决方案
百度推广助手遇到重复关键字,验证错误,怎么一键删除多余的
梅科尔工作室-看鸿蒙设备开发实战笔记五——驱动子系统开发