適用於DE2-70
Even 時HEX3..HEX0 Display EVEN (相近於)
Odd 時HEX3..HEX0 Display Odd (相近於)
//--------------------------------------------------------------------------------
// 16-bit even-parity generator modified from ex.7-2 using function call
// Filename : even_parity_16.v
//--------------------------------------------------------------------------------
module enev_16f_funcall_fun(SW, LEDR, LEDG , CLOCK_27 ,KEY ,HEX0 ,HEX1 ,HEX2,HEX3 );
input [17:0] SW; // toggle switches
input [3:0] KEY; // Push bottom
input CLOCK_27; //Clock 27MHz , 50Mhz
output [17:0] LEDR; // red LEDS
output [8:0] LEDG; // green LEDs
output [6:0] HEX0,HEX1,HEX2,HEX3; //7-segment display
//set original program input , output
//even_parity_16(Din, Pout);
//input [15:0] Din;
//output Pout;
wire [15:0] Din;
reg [6:0] HEX0,HEX1,HEX2,HEX3;
reg [7:0] High_byte; // Hight byte of input data
reg [7:0] Low_byte; // Low byte of input data
reg High, Low; // Parities of high and low byte
reg Pout; // Parity output
assign LWDR=SW;
assign Din=SW[15:0];
always @(Din)
begin
High_byte = Din[15:8];
Low_byte = Din[7:0];
High = even8(High_byte); //Call function even8
Low = even8(Low_byte);
Pout = High ^ Low; //Bitwise xor
end
always @(Pout)
begin
case (Pout)
1'b0 :
begin
HEX3=7'b0000110; //e
HEX2=7'b1100011; //v
HEX1=7'b0000110; //e
HEX0=7'b0101011; //n
end
1'b1 :
begin
HEX3=7'b1111111; //
HEX2=7'b1000000; //o
HEX1=7'b0100001; //d
HEX0=7'b0100001; //d
end
default :
begin
HEX3=7'b1111111; //
HEX2=7'b1111111; //
HEX1=7'b1111111; //
HEX0=7'b1111111; //
end
endcase
end
//==========================================
function even8;
input [7:0] I8;
begin
even8 = even4(I8[7:4]) ^ even4(I8[3:0]); // xor operation
end
endfunction
//==========================================
function even4;
input [3:0] I4;
begin
even4 = ^ I4; // reduction xor operation
end
endfunction
endmodule
沒有留言:
張貼留言