Skip to content

Reptile: I/O in verilog

 

module ilk_cpu(grounds, display, clk, pushbutton);

    input   pushbutton; 
    output  [3:0] grounds;
    output  [6:0] display;
    input   clk; 


    //memory map is defined here
    localparam     BEGINMEM=12'h000,
                   ENDMEM=12'h6ff,
                   KEYPAD=12'h900,
                   SEVENSEG=12'hb00;

//.dış(iç)

    //  memory chip
    logic   [15:0] memory [0:511]; 

    // cpu's input-output pins
    logic   [15:0] pc;
    logic   [15:0] data_out, data_in;
    logic   [11:0] address;
    logic    memwt;

    // input-output devices's pins
    logic     [15:0] keypadregs [1:0];
    logic     [15:0] ss7;


    //instantiation of cpu
    cpu cpu1(.clk(pushbutton), .data_out(data_out), data_in(data_in), 
                                        .address(address), .memwt(memwt));
    //instantiation of monitor
    monitor monitor1( .grounds(grounds), .display(display), .clk(clk),  .info(pc));
    //instantiation of keypad
    keypad keypad1(.rowwrite(rowwrite), .colread(colread), .dataout(keypaddataout),
                                        .readyclr(readyclr),.a0(a0), .clk(clk))

    //multiplexer for cpu input
    always @*  
        if ( (BEGINMEM<=address) && (address<=ENDMEM) )
            data_in=memory[address];
        else if ( (KEYPAD<=address) && (address<=KEYPAD+1) )
            data_in=keypaddataout;
        else
            data_in=16'hf345;    


    //multiplexer for cpu output            
    always_ff @(posedge clk) //data output port of the cpu
        if (memwt)
            if ( (BEGINMEM<=address) && (address<=ENDMEM) )
                memory[address]<=data_out;
            else if ( SEVENSEG1==address) 
                 ss7<=data_out;


    initial begin
            memory[0]=16'h7e80;
            memory[1]=16'h5ffe;
            for (i=2;i<512;i=i+1)
            begin
                memory[i]=16'h0;  //eğer doğru hatırlıyorsam 128 lokasyonun tümünü (sıfır olsalar bile) 
            end                       // initialize etmek lazım..
//            $readmemh("prog.txt", memory);
          end

endmodule

Nice articles on keypad:

https://appcodelabs.com/read-matrix-keypad-using-arduino