Skip to content
Browse files

更新decoder2to4:改良

  • Loading branch information...
1 parent 164aeee commit 41a1b5339d793402f8198c171abf2a2f5762e21c @Vdragon committed
View
16 decoder2to4/GNU_toolchain/Makefile 100755 → 100644
@@ -1,6 +1,12 @@
+#Makefile of 2 to 4 line decoder
+ #author:Vdragon(pika1021@gmail.com)
+ #this file is licensed under LGPL 3 or later
build:
- iverilog -o Simulation/decoder2to4.executable Source_code/test.tbw
-
-test:
- Simulation/decoder2to4.executable
- gtkwave Simulation/decoder2to4.vcd
+ mkdir --parents Simulation
+ iverilog -o Simulation/decoder2to4_tb.executable Source_code/decoder2to4_tb.v
+
+simulate:
+ Simulation/decoder2to4_tb.executable
+
+wave:
+ gtkwave Simulation/decoder2to4_tb.vcd
View
35 decoder2to4/GNU_toolchain/Source_code/decoder2to4/decoder2to4.v
@@ -1,20 +1,23 @@
/* 模組名稱: 2 to 4 line decoder
著作權宣告:copyright 2012 林博仁(pika1021@gmail.com)
*/
-`timescale 1ns / 1ps
-`include "Source_code/decoder1to2/decoder1to2.v"
+`ifndef DECODER2TO4_V_INCLUDED
+ `define DECODER2TO4_V_INCLUDED
+ `timescale 1ns / 100ps
+ `include "Source_code/decoder1to2/decoder1to2.v"
-module decoder2to4(o0, o1, o2, o3, i1, i0);
- input i1, i0;
- output o0, o1, o2, o3;
- wire a0, a1, b0, b1;
- decoder1to2
- dec12a(a1, a0, i0),
- dec12b(b1, b0, i1);
- and
- and00(o0, b0, a0),
- and01(o1, b0, a1),
- and10(o2, b1, a0),
- and11(o3, b1, a1);
-
-endmodule
+ module decoder2to4(o, i);
+ output [3:0]o;
+ input [1:0]i;
+ wire a0, a1, b0, b1;
+ decoder1to2
+ dec12a(a1, a0, i[0]),
+ dec12b(b1, b0, i[1]);
+ and
+ and00(o[0], b0, a0),
+ and01(o[1], b0, a1),
+ and10(o[2], b1, a0),
+ and11(o[3], b1, a1);
+
+ endmodule
+`endif
View
26 decoder2to4/GNU_toolchain/Source_code/decoder2to4_tb.v
@@ -0,0 +1,26 @@
+//2對4解碼器的testbench
+`timescale 1ns / 1ps
+`include "Source_code/decoder2to4/decoder2to4.v"
+module decoder2to4Test;
+ reg [1:0] i;
+ wire [3:0] o;
+
+ //D.U.T.實體化
+ decoder2to4 dec24(o, i);
+
+ initial
+ begin
+ $dumpfile("Simulation/decoder2to4_tb.vcd");
+ $dumpvars;
+ $monitor($time, " i=%2b -> o=%4b", i, o);
+ i = 2'b00;
+
+ #10 i = 2'b01;
+ #10 i = 2'b10;
+ #10 i = 2'b11;
+
+ #10;
+ end
+
+
+endmodule
View
21 decoder2to4/GNU_toolchain/Source_code/test.tbw
@@ -1,21 +0,0 @@
-`timescale 1ns / 1ps
-`include "Source_code/decoder2to4/decoder2to4.v"
-module decoder2to4Test;
- reg i1, i0;
- wire o0, o1, o2, o3;
- initial /*stimulus*/
- begin
- $dumpfile("Simulation/decoder2to4.vcd");
- $dumpvars;
-
- i1 = 0;i0 = 0;
- #10 i1 = 0;i0 = 1;
- #10 i1 = 1;i0 = 0;
- #10 i1 = 1;i0 = 1;
-
- #10;
- end
-
- decoder2to4 dec24(o0, o1, o2, o3, i1, i0);
-
-endmodule

0 comments on commit 41a1b53

Please sign in to comment.
Something went wrong with that request. Please try again.