DE2-115 開發 以 8bit comparator (Verilog behavioral modeling )
module Comparator_8bit(SW, LEDR, LEDG , CLOCK_50 ,KEY,HEX0 ,HEX1 ,HEX2,HEX3 ,HEX4 ,HEX5 ,HEX6 ,HEX7 );
input [17:0] SW; // toggle switches
input [3:0] KEY; // Push bottom
input CLOCK_50; //Clock 27MHz , 50Mhz
output [17:0] LEDR; // red LEDS
output [8:0] LEDG; // green LEDs
output [6:0] HEX0,HEX1,HEX2,HEX3,HEX4,HEX5,HEX6,HEX7 ; //7-segment display
assign HEX0=7'b111_1111; //off 7-segment Display
assign HEX1=7'b111_1111;
assign HEX2=7'b111_1111; //off 7-segment Display
assign HEX3=7'b111_1111;
assign HEX4=7'b111_1111;
assign HEX5=7'b111_1111;
assign HEX6=7'b111_1111;
assign HEX7=7'b111_1111;
Comparator8Bit (SW[7:0],SW[15:8],LEDR[0],LEDR[1],LEDR[2]);
endmodule
module Comparator8Bit(
input[7:0] a,
input[7:0] b,
output eq,
output lt,
output gt);
wire[3:0] a1, a2, b1, b2;
wire eq1, eq2, lt1, lt2, gt1, gt2;
assign a1 = {a[3:0]};
assign a2 = {a[7:4]};
assign b1 = {b[3:0]};
assign b2 = {b[7:4]};
Comparator4Bit BC_1(a1, b1, eq1, lt1, gt1);
Comparator4Bit BC_2(a2, b2, eq2, lt2, gt2);
assign eq = (eq1 & eq2);
assign lt = (lt2 | (eq2 & lt1 ));
assign gt = (~lt & ~eq);
endmodule
module Comparator4Bit(
input[3:0] a,
input[3:0] b,
output eq,
output lt,
output gt);
assign eq = a == b;
assign lt = a < b;
assign gt = a > b;
endmodule
沒有留言:
張貼留言