-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryToBCDConverter
74 lines (66 loc) · 1.99 KB
/
BinaryToBCDConverter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//-----------------------------------------------------------------------------
// University: Oregon Institute of Technology – CSET Department
// Class: CST 231
// Author: Luis Solis
// Lab: Lab 2
// Project: Intro to Hierarchical
// File Name: BinToBCDConversion.v
// List of other files used: Lab2.v,myClockDivider.v,my16BitCounter.v,
// my7Seg.v
//-----------------------------------------------------------------------------
// Description of the Code (1 - 5 lines)
// Lab Description:
//-----------------------------------------------------------------------------
// Date: 01/04/2022
// Version: 1.0
// Revision:
// 01/13/2022 Create the lab
// 01/14/2022 present the lab
//-----------------------------------------------------------------------------
module BinToBCDConversion (
input [15:0] binary,
output reg [3:0] Ten_Thousands,
output reg [3:0] Thousands,
output reg [3:0] Hundreds,
output reg [3:0] Tens,
output reg [3:0] Ones
);
//-----------------------------------------------------------
// Interger Declarations: Interger
//-----------------------------------------------------------
integer i;
always @(binary)
begin
//set 100,000's,10,000's, 1,000's 100's 10's 0's
Ten_Thousands = 4'b0;
Thousands = 4'b0;
Hundreds = 4'b0;
Tens = 4'b0;
Ones = 4'b0;
for (i=15;i>=0; i=i-1)
begin
//add 3 to columns >=5
if (Ten_Thousands >= 5)
Ten_Thousands = Ten_Thousands + 3;
if (Thousands >= 5)
Thousands = Thousands + 3;
if (Hundreds >= 5)
Hundreds = Hundreds + 3;
if (Tens >= 5)
Tens = Tens + 3;
if (Ones >= 5)
Ones = Ones + 3;
//shifts left one
Ten_Thousands = Ten_Thousands << 1;
Ten_Thousands[0] = Thousands[3];
Thousands = Thousands << 1;
Thousands[0] = Hundreds[3];
Hundreds = Hundreds << 1;
Hundreds[0] = Tens[3];
Tens = Tens << 1;
Tens[0] = Ones[3];
Ones = Ones << 1;
Ones[0] = binary[i];
end
end
endmodule