//P5-24 4-2 encoder using bitwise operators
module Encoder4x2 (SW, LEDR, LEDG);
input [17:0] SW; // toggle switches
output [17:0] LEDR; // red LEDS
output [7:0] LEDG; // green LEDs
//set original program input , output
wire [1:0] y;
wire [3:0] I;
//mapping to hardware
assign LEDR = SW;
assign I=SW[3:0];
//Assign y[1:0] with truth table states
assign y[1] = ((((~I[3]) & (I[2])) | ((I[3]) & (~I[2]))) & (~I[1]) & (~I[0])),
y[0] = ((~I[2]) & (~I[0]) & (((~I[3]) & (I[1])) | ((I[3]) & (~I[1]))));
assign LEDG[1:0]=y;
endmodule
/* original program
//-----------------------------------------------
//Filename : encod4_2.v
//-----------------------------------------------
module encod4_2(y, I3, I2, I1, I0);
output [1:0] y;
input I3, I2, I1,I0;
//Assign y[1:0] with truth table states
assign y[1] = ((((~I3) & (I2)) | ((I3) & (~I2))) & (~I1) & (~I0)),
y[0] = ((~I2) & (~I0) & (((~I3) & (I1)) | ((I3) & (~I1))));
endmodule
*/
沒有留言:
張貼留言