一个问题:六位八段数码管(Verilog)
【基本信息】需求:verilog程序,显示任意六位字符或数值,包含点号,且能够按需点亮位数。(学习篇)
芯片型号:cyclone Ⅳ EP4CE10F17C8
数码管属性:六位、八段
【最终成果图】
https://img2024.cnblogs.com/blog/3025061/202406/3025061-20240602132841046-931594629.jpg
经过多轮测试,最后代码程序满足设计要求,但结合仿真发现了一个问题,仿真和上机不匹配,当然还是要以上机为准。
【模块例化图】
https://img2024.cnblogs.com/blog/3025061/202406/3025061-20240602132902555-168785457.jpg
这里就是简单地赋个初始值,来测试digital模块,最终是要seg_led和seg_sel的显示变化。
【verilog程序】
1、digital模块
模块化设计,六个位上的值直接拆开做处理,分析起来清晰。sel_cnt表示目前要显示的位数(从右往左),即sel_cnt = 6代表全亮。dp_cnt表示点号所在位数,若dp_cnt=0则代表没有点号。clk_2khz为数码管的刷新信号。
module digital( input sys_clk , input sys_rst , input clk_2khz , input num6, input num5, input num4, input num3, input num2, input num1, input sel_cnt , input dp_cnt , output reg seg_sel , output reg seg_led );reg sel_cnt_tran;reg num;reg tran1;//endmodule定义了几个变量,sel_cnt_tran用来根据数码管刷新信号更替数码管的位选,而num用来接引各位上的值,数码管根据num编号段选信号。tran1在过程讨论部分做解释。
always @(posedge sys_clk or negedge sys_rst)begin if(!sys_rst) sel_cnt_tran = 3'd0; else if(clk_2khz)begin if(sel_cnt_tran < sel_cnt)begin tran1 = sel_cnt_tran; sel_cnt_tran = sel_cnt_tran + 1'b1; end else begin tran1 = sel_cnt_tran; sel_cnt_tran = 3'd0; end endend上述代码就是位选更替,可以直观得到,tran1比sel_cnt_tran要晚上一个数码管刷新周期。
always @(posedge sys_clk or negedge sys_rst)begin if(!sys_rst) seg_sel
页:
[1]