-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryToBCDConverter2
65 lines (57 loc) · 1.71 KB
/
BinaryToBCDConverter2
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
//-----------------------------------------------------------------------------
// University: Oregon Institute of Technology – CSET Department
// Class: CST 231
// Author: Luis Solis
// Lab: Lab 3
// Project: Multiplexed Display
// File Name: BinToBCDConversion.v
// List of other files used: Clock_Divider.v, my12bit_upd_couner.v,Lab3.v
// myMuxDisplay.v, my7Seg.v
//-----------------------------------------------------------------------------
// Description of the Code (1 - 5 lines)
// Lab Description: Will change our binary numbers to BCD
//-----------------------------------------------------------------------------
// Date: 01/04/2022
// Version: 1.0
// Revision:
// 1/24/2022
// 1/26/2022
//-----------------------------------------------------------------------------
module BinToBCDConversion (
input [11:0] binary,
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
Thousands = 4'b0;
Hundreds = 4'b0;
Tens = 4'b0;
Ones = 4'b0;
for (i=11;i>=0; i=i-1)
begin
if (Thousands >= 5)
Thousands = Thousands + 3;
if (Hundreds >= 5)
Hundreds = Hundreds + 3;
if (Tens >= 5)
Tens = Tens + 3;
if (Ones >= 5)
Ones = Ones + 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