【基本信息】
需求: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
- end
- end
复制代码 上述代码就是位选更替,可以直观得到,tran1比sel_cnt_tran要晚上一个数码管刷新周期。
[code]always @(posedge sys_clk or negedge sys_rst)begin if(!sys_rst) seg_sel |