通过开关在7段指示灯上输出字

问题描述 投票:0回答:1

我想输出到一个七段显示器,这样当按下按钮时,显示某个段上的字母,当打开开关时,显示整个单词。七段单元采用动态显示。 当开关切换到有效状态时,位置总线连接到移位寄存器,7 段开关应根据它进行切换。 在波形上,当将开关切换到活动状态时,总线“位置”不会改变并保持等于移位寄存器的初始值(?)。按钮发出信号时的值是正确的

模块---

module mux_decoder(
    input btn_fir,
    input btn_sec,
    input btn_thi,
    input btn_fou,
    input sw_for_fullword,
    input clk,
    input rst,
    //input BTNC,
    //input SW[9],
    
    output logic [3:0] place,
    output [7:0] segments
    );
    
    typedef enum bit [7:0]
    {
        D     = 8'b0111_1010,
        N     = 8'b1110_1100,
        Y     = 8'b0111_0110,
        A     = 8'b1110_1110,
        space = 8'b0000_0000
    }
    seven_seg;
    seven_seg letter;
    
    logic [31:0] cnt;
    always_ff@(posedge clk,posedge rst)begin
        if(rst) cnt <= '0;
        else cnt <= cnt+1'b1;
    end
    
    logic enable = (cnt[2:0] == '0);
    
    logic [3:0]shift_reg;
    
    always_ff@(posedge clk, posedge rst)begin
        if (rst) shift_reg <= 4'b1;
        else if(enable) shift_reg <= {shift_reg[0], shift_reg[3:1]};
    end
    
   always_comb begin
        if(sw_for_fullword) place = shift_reg;
        else place = {btn_fir, btn_sec,btn_thi,btn_fou};
     end
     
    always_comb begin
        case (place)
        4'b1000: letter = D;
        4'b0100: letter = A;
        4'b0010: letter = N;
        4'b0001: letter = Y;
        default: letter = space;
        endcase        
    end
    
    assign segments = letter;
    
endmodule

TB--------

module tb( );
    logic[3:0] x;
    logic[7:0] letter;
    logic[3:0] place;
    logic sw;
    bit clk;
    bit rst;
    
    mux_decoder ms(.btn_fou(x[0]),.btn_fir(x[3]),.btn_sec(x[2]), .btn_thi(x[1]),.sw_for_fullword(sw),
    .place(place), .segments(letter), .clk(clk), .rst(rst));
    
    parameter CLK_PERIOD = 10;
  

    always #(CLK_PERIOD/2) clk = ! clk;
    

    initial begin
      rst <= 1'b1;
      repeat (2) @ (posedge clk);
      rst <= 1'b0;      
      

      
      x = 4'b0001;
      #20
      x = 4'b0010;
      #20
      x=4'b0100;
      #20;
      x = 4'b1000;
      #20
      x='0; 
      sw = '1;  
      repeat (50) @ (posedge clk);
      $finish;
    end
  

timing diagram

verilog system-verilog test-bench
1个回答
0
投票

仅查看测试台中的信号是不够的。您还需要查看

mux_decoder
模块内的波形。

当我查看

enable
信号的波形时,它是未知的(
x
)。变化:

logic enable = (cnt[2:0] == '0);

至:

wire enable = (cnt[2:0] == '0);

现在,我看到

enable
变得众所周知:

© www.soinside.com 2019 - 2024. All rights reserved.