【基本信息】
需求:verilog程序,显示任意六位字符或数值,包含点号,且能够按需点亮位数。(学习篇)
芯片型号:cyclone Ⅳ EP4CE10F17C8
数码管属性:六位、八段
【最终成果图】
经过多轮测试,最后代码程序满足设计要求,但结合仿真发现了一个问题,仿真和上机不匹配,当然还是要以上机为准。
【模块例化图】
这里就是简单地赋个初始值,来测试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 [3:0] num6, input [3:0] num5, input [3:0] num4, input [3:0] num3, input [3:0] num2, input [3:0] num1, input [2:0] sel_cnt , input [2:0] dp_cnt , output reg[5:0] seg_sel , output reg[7:0] seg_led );reg[2:0] sel_cnt_tran;reg[3:0] num;reg[2:0] 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要晚上一个数码管刷新周期。
[code]always @(posedge sys_clk or negedge sys_rst)begin if(!sys_rst) seg_sel |