if(!rst_n)begin hex1 <= ALL_LIGHT; hex2 <= ALL_LIGHT; hex3 <= ALL_LIGHT; 这里是什么意思
时间: 2024-04-05 19:35:28 浏览: 91
这里是一个异步复位逻辑,当复位信号 rst_n 为低电平时,表示系统需要进行复位操作,此时将三个七段数码管的输出信号都设置为 ALL_LIGHT,即全灭状态,以确保系统复位后数码管不会显示错误的数据。当 rst_n 信号为高电平时,表示复位信号已经结束,系统可以开始正常工作,此时会根据输入信号的数据进行计算和显示。
相关问题
module seg( input wire clk , //100MHz input wire rst_n , //low valid input wire [17:0] data_in , //待显示数据 output reg [6:0] hex1 , // -共阳极,低电平有效 output reg [6:0] hex2 , // - output reg [6:0] hex3 , // - output reg [6:0] hex4 //熄灭 ); //parameter define localparam NUM_0 = 8'b1100_0000, NUM_1 = 8'b1111_1001, NUM_2 = 8'b1010_0100, NUM_3 = 8'b1011_0000, NUM_4 = 8'b1001_1001, NUM_5 = 8'b1001_0010, NUM_6 = 8'b1000_0010, NUM_7 = 8'b1111_1000, NUM_8 = 8'b1000_0000, NUM_9 = 8'b1001_0000, NUM_A = 8'b1000_1000, NUM_B = 8'b1000_0011, NUM_C = 8'b1100_0110, NUM_D = 8'b1010_0001, NUM_E = 8'b1000_0110, NUM_F = 8'b1000_1110, ALL_LIGHT = 8'b0000_0000, LIT_OUT = 8'b1111_1111; //reg 、wire define reg [3:0] cm_hund ;//100cm reg [3:0] cm_ten ;//10cm reg [3:0] cm_unit ;//1cm always @(posedge clk or negedge rst_n)begin if(!rst_n)begin cm_hund <= 'd0; cm_ten <= 'd0; cm_unit <= 'd0; end else begin cm_hund <= data_in / 10 ** 2; cm_ten <= data_in / 10**1 % 10; cm_unit <= data_in/10**0 % 10; end end always @(posedge clk or negedge rst_n)begin if(!rst_n)begin hex1 <= ALL_LIGHT; hex2 <= ALL_LIGHT; hex3 <= ALL_LIGHT; hex4 <= ALL_LIGHT; end else begin hex1 <= hex_data(cm_unit); hex2 <= hex_data(cm_ten); hex3 <= hex_data(cm_hund); hex4 <= LIT_OUT; end end //always end function [6:0] hex_data; //函数不含时序逻辑相关 input [03:00] data_i;//至少一个输入 begin case(data_i) 'd0:hex_data = NUM_0; 'd1:hex_data = NUM_1; 'd2:hex_data = NUM_2; 'd3:hex_data = NUM_3; 'd4:hex_data = NUM_4; 'd5:hex_data = NUM_5; 'd6:hex_data = NUM_6; 'd7:hex_data = NUM_7; 'd8:hex_data = NUM_8; 'd9:hex_data = NUM_9; default:hex_data = ALL_LIGHT; endcase end endfunction endmodule
这是一个Verilog HDL写的模块,可以实现数字显示器的功能。其中,模块的输入包括时钟信号clk、复位信号rst_n和待显示的数据data_in,输出包括4个七段数码管的控制信号hex1、hex2、hex3和hex4。模块中使用了parameter定义常量和reg、wire定义寄存器和线网,同时使用了always块和function函数实现时序逻辑和数字转换功能。具体实现是将待显示的数据转换为3个数字,然后通过函数将数字转换为对应的七段数码管控制信号。
module seg( input wire clk , //100MHz input wire rst_n , //low valid input wire [9:0] data_in , //待显示数据 output reg [6:0] hex1 , // -共阳极,低电平有效 output reg [6:0] hex2 , // - output reg [6:0] hex3 // - ); //parameter define localparam NUM_0 = 8'b1100_0000, NUM_1 = 8'b1111_1001, NUM_2 = 8'b1010_0100, NUM_3 = 8'b1011_0000, NUM_4 = 8'b1001_1001, NUM_5 = 8'b1001_0010, NUM_6 = 8'b1000_0010, NUM_7 = 8'b1111_1000, NUM_8 = 8'b1000_0000, NUM_9 = 8'b1001_0000, NUM_A = 8'b1000_1000, NUM_B = 8'b1000_0011, NUM_C = 8'b1100_0110, NUM_D = 8'b1010_0001, NUM_E = 8'b1000_0110, NUM_F = 8'b1000_1110, ALL_LIGHT = 8'b0000_0000, LIT_OUT = 8'b1111_1111; //reg 、wire define reg [3:0] cm_hund ;//100cm reg [3:0] cm_ten ;//10cm reg [3:0] cm_unit ;//1cm always @(posedge clk or negedge rst_n)begin if(!rst_n)begin cm_hund <= 'd0; cm_ten <= 'd0; cm_unit <= 'd0; end else begin cm_hund <= data_in / 10 ** 5; cm_ten <= data_in / 10 ** 4 % 10; cm_unit <= data_in / 10 ** 3 % 10; end end always @(posedge clk or negedge rst_n)begin if(!rst_n)begin hex1 <= ALL_LIGHT; hex2 <= ALL_LIGHT; hex3 <= ALL_LIGHT; end else begin hex1 <= hex_data(cm_unit); hex2 <= hex_data(cm_ten); hex3 <= hex_data(cm_hund); end end //always end function [6:0] hex_data; //函数不含时序逻辑相关 input [03:00] data_i;//至少一个输入 begin case(data_i) 'd0:hex_data = NUM_0; 'd1:hex_data = NUM_1; 'd2:hex_data = NUM_2; 'd3:hex_data = NUM_3; 'd4:hex_data = NUM_4; 'd5:hex_data = NUM_5; 'd6:hex_data = NUM_6; 'd7:hex_data = NUM_7; 'd8:hex_data = NUM_8; 'd9:hex_data = NUM_9; default:hex_data = ALL_LIGHT; endcase end endfunction endmodule
这是一个Verilog代码模块,用于将输入的十进制数字转换为三个七段数码管的显示,其中包括一个时序逻辑相关的always块和一个不含时序逻辑相关的函数hex_data。在时序逻辑相关的always块中,使用一个三位数字将输入数据进行分离,并将对应的七段数码管的显示码存储到对应的寄存器中。在函数hex_data中,使用case语句将输入的四位数字转换为对应的七段数码管的显示码。
阅读全文