0
votes

I'm creating a basys2 board in verilog for a seven segment display to show in binary. I am using switches 0-3 and want to use the 4 buttons so that when button[0] is pushed, the binary number of the switches (up for 1, down for 0) displays. However, I'm stuck on how to integrate the buttons with the binary and the led. I'm new to verilog and having some trouble. Any suggestions?

module final(btn,clk,sw,cathodes,anodes,led,rst);

    input clk,rst;
    output [6:0] cathodes;
    output [7:0] led;
    output [3:0] anodes;
    input [3:0] sw;
    input [3:0] btn;

    reg [6:0] cathodes;
    reg [15:0] dig;
    reg [3:0] anodes;
    reg slow_clock;
    integer count;
    reg [7:0] led;

    always @ (posedge clk)
        create_slow_clock(clk, slow_clock);

Stuck here at how to assign led:

always @(posedge clk)
        begin
            if (btn[0:3]);
                begin
                    led[0]
                    led[1]
                    led[2]
                    led[3]

Also not sure this is correct:

always @ (posedge slow_clock)
            begin
                led=~led;
                if (rst == 0) anodes = 4'b1111;
                else
                    begin
                        case (btn)
                            0: anodes = 4'b0111;
                            1: anodes = 4'b1011;
                            2: anodes = 4'b1101;
                            3: anodes = 4'b1110;
                            default: anodes = 4'b1111;



                    endcase
                    cathodes = calc_cathode_value(dig);
                    end
                end

.

function[6:0] calc_cathode_value;
    input [15:0] dig;
    begin
        case (dig)
            0: calc_cathode_value = 8'b00000011;
            1: calc_cathode_value = 8'b10011111;
            2: calc_cathode_value = 8'b00100101;
            3: calc_cathode_value = 8'b00001101;
            4: calc_cathode_value = 8'b10011001;
            5: calc_cathode_value = 8'b01001001;
            6: calc_cathode_value = 8'b01000001;
            7: calc_cathode_value = 8'b00011111;
            8: calc_cathode_value = 8'b00000001; 
            9: calc_cathode_value = 8'b00001001;
            'hA: calc_cathode_value = 8'b00010001;
            'hb: calc_cathode_value = 8'b11000001;
            'hC: calc_cathode_value = 8'b01100011;
            'hd: calc_cathode_value = 8'b10000101;
            'hE: calc_cathode_value = 8'b01100001;
            'hF: calc_cathode_value = 8'b01110001;
            default: calc_cathode_value = 8'b0000001;
        endcase
    end
endfunction

task create_slow_clock;
    input clock;
    inout slow_clock;
    integer count;

        begin
            if (count > 250000)
            begin
                count = 0;
                slow_clock = ~slow_clock;
            end
            count = count + 1;
        end
    endtask

endmodule

1
I suggest you to start with a single LED. Then with a single switch. Then with a LED and a switch. After you feel comfortable with it, try something more complex.Eugene Sh.
I've done that, but still have not figured out how to add more. I've tried some different things, but can't seem to get it to workuser6754289

1 Answers

0
votes

you signal btn is defined as 4-bit meaning that the case statement needs to represent all 16 possibilities from 0 to F. Think about what needs to happen when more then one button is pushed at the same time. If you only care about cases where 1 of the buttons is pushed then your case values would need to be 0,1,2,4 as each bit position represents another 2^n value.