diff options
author | Vasil Zlatanov <v@skozl.com> | 2016-12-12 21:51:10 +0000 |
---|---|---|
committer | Vasil Zlatanov <v@skozl.com> | 2016-12-12 21:51:10 +0000 |
commit | 4b6e0102d20d9ab060ce930e4b846c8be446bb06 (patch) | |
tree | e475eab3716738f2928f0b2063956e9b155f94ab /part_1/mylib | |
download | e2-verilab-4b6e0102d20d9ab060ce930e4b846c8be446bb06.tar.gz e2-verilab-4b6e0102d20d9ab060ce930e4b846c8be446bb06.tar.bz2 e2-verilab-4b6e0102d20d9ab060ce930e4b846c8be446bb06.zip |
public push
Diffstat (limited to 'part_1/mylib')
-rw-r--r-- | part_1/mylib/bin2bcd_10.v | 59 | ||||
-rw-r--r-- | part_1/mylib/hex_2_7seg.v | 28 |
2 files changed, 87 insertions, 0 deletions
diff --git a/part_1/mylib/bin2bcd_10.v b/part_1/mylib/bin2bcd_10.v new file mode 100644 index 0000000..970d330 --- /dev/null +++ b/part_1/mylib/bin2bcd_10.v @@ -0,0 +1,59 @@ +module ex4_top (
+ input [9:0] SW,
+ output [6:0] HEX0,
+ output [6:0] HEX1,
+ output [6:0] HEX2,
+ output [6:0] HEX3
+ );
+
+
+ reg [3:0] BCD0;
+ reg [3:0] BCD1;
+ reg [3:0] BCD2;
+ reg [3:0] BCD3;
+
+ integer i;
+ always @ (*)
+ begin
+ BCD0 = 4'd0;
+ BCD1 = 4'd0;
+ BCD2 = 4'd0;
+ BCD3 = 4'd0;
+
+ for (i=9; i>=0; i=i-1)
+ begin
+ if (BCD3 >= 5)
+ BCD3 = BCD3 +3;
+ if (BCD2 >= 5)
+ BCD2 = BCD2 +3;
+ if (BCD1 >= 5)
+ BCD1 = BCD1 +3;
+ if (BCD0 >= 5)
+ BCD0 = BCD0 +3;
+
+ // shift each digit
+ BCD3 = BCD3 << 1;
+ BCD3[0] = BCD2[3];
+
+ BCD2 = BCD2 << 1;
+ BCD2[0] = BCD1[3];
+
+ BCD1 = BCD1 << 1;
+ BCD1[0] = BCD0[3];
+
+ BCD0 = BCD0 << 1;
+ BCD0[0] = SW[i];
+ end
+
+ end
+
+ hex_to_7seg SEG3 (HEX3, BCD3);
+ hex_to_7seg SEG2 (HEX2, BCD2);
+ hex_to_7seg SEG1 (HEX1, BCD1);
+ hex_to_7seg SEG0 (HEX0, BCD0);
+endmodule
+
+
+
+
+
\ No newline at end of file diff --git a/part_1/mylib/hex_2_7seg.v b/part_1/mylib/hex_2_7seg.v new file mode 100644 index 0000000..6b476e3 --- /dev/null +++ b/part_1/mylib/hex_2_7seg.v @@ -0,0 +1,28 @@ +module hex_to_7seg (out,in);
+ output [6:0] out;
+ input [3:0] in;
+
+ reg [6:0] out;
+
+ always @ (*)
+ case (in)
+ 4'h0: out = 7'b1000000;
+ 4'h1: out = 7'b1111001;
+ 4'h2: out = 7'b0100100;
+ 4'h3: out = 7'b0110000;
+ 4'h4: out = 7'b0011001;
+ 4'h5: out = 7'b0010010;
+ 4'h6: out = 7'b0000010;
+ 4'h7: out = 7'b1111000;
+ 4'h8: out = 7'b0000000;
+ 4'h9: out = 7'b0011000;
+ 4'hA: out = 7'b0001000;
+ 4'hB: out = 7'b0000011;
+ 4'hC: out = 7'b1000110;
+ 4'hD: out = 7'b0100001;
+ 4'hE: out = 7'b0000110;
+ 4'hF: out = 7'b0001110;
+ endcase
+endmodule
+
+
\ No newline at end of file |