diff options
author | Michael Abed <michaelabed@gmail.com> | 2012-03-28 09:58:28 -0400 |
---|---|---|
committer | Michael Abed <michaelabed@gmail.com> | 2012-03-28 09:58:28 -0400 |
commit | 5d32d4ca9aaf2000e05503457bed1b8f04ca6d62 (patch) | |
tree | 1b1d1ff3a6645fd208ae19918d064e2056777e52 /Bin2BCD.v | |
download | ec311-lab5-5d32d4ca9aaf2000e05503457bed1b8f04ca6d62.tar.gz ec311-lab5-5d32d4ca9aaf2000e05503457bed1b8f04ca6d62.tar.bz2 ec311-lab5-5d32d4ca9aaf2000e05503457bed1b8f04ca6d62.zip |
initial commit
Diffstat (limited to 'Bin2BCD.v')
-rw-r--r-- | Bin2BCD.v | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Bin2BCD.v b/Bin2BCD.v new file mode 100644 index 0000000..7af8725 --- /dev/null +++ b/Bin2BCD.v @@ -0,0 +1,57 @@ +`timescale 1ns / 1ps +////////////////////////////////////////////////////////////////////////////////// +// Company: +// Engineer: +// +// Create Date: 10:16:12 03/16/2012 +// Design Name: +// Module Name: Bin2BCD +// Project Name: +// Target Devices: +// Tool versions: +// Description: +// +// Dependencies: +// +// Revision: +// Revision 0.01 - File Created +// Additional Comments: +// +////////////////////////////////////////////////////////////////////////////////// +module Bin2BCD( + input [15:0] bin, + output [3:0] one, + output [3:0] ten, + output [3:0] hun, + output [3:0] thous + ); + +reg [3:0] one, ten, hun, thous; +reg [31:0] work; +reg [3:0] i; + +always @( bin ) begin + hun = 0; ten = 0; one = 0; + work = {thous, hun, ten, one, bin}; + + for (i = 0; i < 15; i = i +1) begin + work = work << 1; + if (work[31:28] >= 5) + work[31:28] = work[31:28] + 4'd3; + if (work[27:24] >= 5) + work[27:24] = work[27:24] + 4'd3; + if (work[23:20] >= 5) + work[23:20] = work[23:20] + 4'd3; + if (work[19:16] >= 5) + work[19:16] = work[19:16] + 4'd3; + end + + work = work << 1; + + thous = work[31:28]; + hun = work[27:24]; + ten = work[23:20]; + one = work[19:16]; +end + +endmodule |