You are on page 1of 2

`timescale 1ns / 1ps

//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 22:28:54 05/17/2017
// Design Name:
// Module Name: penc_tb
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module penc_tb();
reg [7:0]a;
wire [2:0]y;
integer i;

penc DUT(.a(a),.y(y));

/*task reset();
begin
{a}=0;
end
endtask

task inputs(input [7:0]j);


begin
{a}=j;
end
endtask

initial
begin
reset;
for(i=0;i<256;i=i+1)
begin
inputs(i);
#10;
end
end

*/

initial begin
a = 8'hff;
#10 a= 8'h7f;
#10 a= 8'h1f;
#10 a= 8'h1f;
#10 a= 8'h0f;
#10 a= 8'h07;
#10 a= 8'h03;
#10 a= 8'h01;
end

endmodule

`timescale 1ns / 1ps


//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 21:54:26 05/17/2017
// Design Name:
// Module Name: penc
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module penc(input [7:0]a,output reg[2:0]y);

always@(a)
begin
if(a[7]==1)
y=3'b111;
else if(a[6]==1)
y=3'b110;
else if(a[5]==1)
y=3'b101;
else if(a[4]==1)
y=3'b100;
else if(a[3]==1)
y=3'b011;
else if(a[2]==1)
y=3'b010;
else if(a[1]==1)
y=3'b001;
else if(a[0]==1)
y=3'b000;
else
y=3'bxxx;
end
endmodule

You might also like