Sunteți pe pagina 1din 2

M QUINA DE ESTADOS: GENERAR 1543

module generator1543
( input CLK, CLK_ENA, RSTn, // KEY[1], SW[0], KEY[0],
output [6:0] Unidades ); // HEX[0]

// Declare state register


reg [1:0] state;
reg [2:0] out;
// Declare states
parameter S0 = 0, S1 = 1, S2 = 2, S3 = 3;

// Output depends only on the state


always @ (state) begin
case (state)
S0: out = 1;
S1: out = 5;
S2: out = 4;
S3: out = 3;
default:
out = 0;
endcase
end

// Determine the next state


always @ (posedge CLK or negedge RSTn) // Reset as ncrono!
begin
if (!RSTn)
state <= S0;
else if (CLK_ENA) // Es mejor aqui que para cada state
case (state)
S0:
// if (CLK_ENA)
state <= S1;
// else
// state <= S0;
S1:
// if (CLK_ENA)
state <= S2;
S2:
// if (CLK_ENA)
state <= S3;
S3:
// if (CLK_ENA)
state <= S0;
default:
state <= S0;
endcase
end

hex7seg hex0 // Instancia hex7seg


( .hex_digit({ 1'b0, out }), // Ver que hex_digit tiene 4 bits, no los 3 de out...
.oSEG(Unidades) );

endmodule

PROGRAMA QUE MUESTRA EN EL CACHARRO LOS N MEROS

module hex7seg (hex_digit, oSEG, seg_g, seg_f, seg_e, seg_d, seg_c, seg_b, seg_a);
input [3:0] hex_digit; //
output reg [6:0] oSEG; // oSEG = {seg_g, seg_f, seg_e, seg_d, seg_c, seg_b, seg_a}.
// Cuando use oSEG, actuar asignando sus bits en consecuencia.
output seg_g, seg_f, seg_e, seg_d,
seg_c, seg_b, seg_a;

always @(hex_digit)
begin
case(hex_digit)
4'h0: oSEG = 7'b1000000;
4'h1: oSEG = 7'b1111001; // --A---
4'h2: oSEG = 7'b0100100; // | |
4'h3: oSEG = 7'b0110000; // F B
4'h4: oSEG = 7'b0011001; // | |
4'h5: oSEG = 7'b0010010; // --G---
4'h6: oSEG = 7'b0000010; // | |
4'h7: oSEG = 7'b1111000; // E C
4'h8: oSEG = 7'b0000000; // | |
4'h9: oSEG = 7'b0011000; // --D---
4'ha: oSEG = 7'b0001000;
4'hb: oSEG = 7'b0000011;
4'hc: oSEG = 7'b1000110;
4'hd: oSEG = 7'b0100001;
4'he: oSEG = 7'b0000110;
4'hf: oSEG = 7'b0001110;
endcase
end
assign {seg_g, seg_f, seg_e, seg_d, seg_c, seg_b, seg_a} = oSEG;
endmodule

S-ar putea să vă placă și