// Ch5.13 BCD to 7segment display circuit
module EX5_13( w,x,y,z,a,b,c,d,e,f,g);
input w,x,y,z; // 1位元輸入
output reg a,b,c,d,e,f,g ; // Output 1位元輸出
always@ (w,x,y,z) begin
case ({w,x,y,z})
4'b0000: {a,b,c,d,e,f,g}=7'b111_0111;
4'b0001: {a,b,c,d,e,f,g}=7'b010_0100;
4'b0010: {a,b,c,d,e,f,g}=7'b101_1101;
4'b0011: {a,b,c,d,e,f,g}=7'b101_1011;
4'b0100: {a,b,c,d,e,f,g}=7'b011_1010;
4'b0101: {a,b,c,d,e,f,g}=7'b110_1011;
4'b0110: {a,b,c,d,e,f,g}=7'b110_1111;
4'b0111: {a,b,c,d,e,f,g}=7'b101_0010;
4'b1000: {a,b,c,d,e,f,g}=7'b111_1111;
4'b1001: {a,b,c,d,e,f,g}=7'b111_1010;
4'b1010: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1011: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1100: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1101: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1110: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
4'b1111: {a,b,c,d,e,f,g}=7'bzzz_zzzz;
endcase
end
endmodule
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps
module Test_bench;
// Inputs
reg w,x,y,z;
// Outputs
wire a,b,c,d,e,f,g ;
// Instantiate the Unit Under Test (UUT)
// ex5.10 F(a,b,c,d) circuit
EX5_13 UUT (
.w(w),
.x(x),
.y(y),
.z(z),
.a(a),
.b(b),
.c(c),
.d(d),
.e(e),
.f(f),
.g(g)
);
initial begin
$monitor( w,x,y,z,a,b,c,d,e,f,g);
//Apply inputs
w=1'b0; x=1'b0; y=1'b0; z=1'b0;
#100;
{w,x,y,z}=4'b0001;
#100;
{w,x,y,z}=4'b0010;
#100;
{w,x,y,z}=4'b0011;
#100;
{w,x,y,z}=4'b0100;
#100;
{w,x,y,z}=4'b0101;
#100;
{w,x,y,z}=4'b0110;
#100;
{w,x,y,z}=4'b0111;
#100;
{w,x,y,z}=4'b1000;
#100;
{w,x,y,z}=4'b1001;
#100;
{w,x,y,z}=4'b1010;
#100;
{w,x,y,z}=4'b1011;
#100;
{w,x,y,z}=4'b1100;
#100;
{w,x,y,z}=4'b1101;
#100;
{w,x,y,z}=4'b1110;
#100;
{w,x,y,z}=4'b1111;
#100;
end
initial begin
#1600 $stop;
end
沒有留言:
張貼留言