-
Notifications
You must be signed in to change notification settings - Fork 1
/
Backup 1.txt
167 lines (140 loc) · 4.33 KB
/
Backup 1.txt
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
----------------------------------------------------------------------------------
-- Company: LeTourneau University
-- Engineer:
--
-- Create Date: 19:46:40 04/11/2021
-- Design Name:
-- Module Name: FinalDisplay - Behavioral
-- Project Name: Digital Electronics Clock Display
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity FinalDisplay is
Port ( --SEC_0 : in STD_LOGIC_VECTOR(3 downto 0);
-- clock signal
CLK : in STD_LOGIC;
-- 4 digits on board
AN1 : out STD_LOGIC;
AN2 : out STD_LOGIC;
AN3 : out STD_LOGIC;
AN4 : out STD_LOGIC;
-- 7 outputs for 7 segment display
C_A : out STD_LOGIC;
C_B : out STD_LOGIC;
C_C : out STD_LOGIC;
C_D : out STD_LOGIC;
C_E : out STD_LOGIC;
C_F : out STD_LOGIC;
C_G : out STD_LOGIC);
end FinalDisplay;
architecture Behavioral of FinalDisplay is
-- clock counter
signal CLK_DIV : STD_LOGIC_VECTOR (23 downto 0);
-- clock counter divided by 2^15, 244 Hz
signal CLOCK : STD_LOGIC;
-- BCD of digits
--signal MIN_2 : STD_LOGIC_VECTOR(3 downto 0);
--signal MIN_1 : STD_LOGIC_VECTOR(3 downto 0);
--signal SEC_2 : STD_LOGIC_VECTOR(3 downto 0);
signal SEC_1 : STD_LOGIC_VECTOR(3 downto 0);
-- representation of 7 segment display output
signal SEC_1_DISPLAY : STD_LOGIC_VECTOR(6 downto 0);
-- 2 bits for counter, default should be 00
signal COUNTER : STD_LOGIC_VECTOR(1 downto 0);
-- which digit is being displayed
signal AN : STD_LOGIC_VECTOR(3 downto 0);
begin
-- set digits to 4321
--MIN_2 <= "0100"; -- 4
--MIN_1 <= "0011"; -- 3
--SEC_2 <= "0010"; -- 2
SEC_1 <= "0001"; -- 1
15-- process to set up a clock divider and allow use of divided clock
Clock_Divider : process (CLK)
begin
-- set up a new clock that is incremented based on the built in clock of 8 MHz
-- if clock changes to 1, add 1 to CLK_DIV
if (CLK'Event and CLK = '1') then
CLK_DIV <= std_logic_vector(to_unsigned(to_integer(unsigned(CLK_DIV)) + 1, 4));
end if;
end process;
-- the 16th digit divides the frequency of the 8 MHz clock by 2^15 so that it has a frequency of 244 Hz, so the period as 4 ms
-- (it works this way becuase of how it is set up to increment CLK_DIV)
Clock <= CLK_DIV(15);
Multiplexed_Display : process (Clock)
begin
-- depending on counter, select which digit is on
case COUNTER is
when "00" =>
AN <= "0111";
when "01" =>
AN <= "1011";
when "10" =>
AN <= "1101";
when "11" =>
AN <= "1110";
when others =>
AN <= "1111"; -- default all off
end case;
-- reset counter if 3, otherwise increment
if (COUNTER = "11") then
COUNTER <= "00";
else
COUNTER <= std_logic_vector(to_unsigned(to_integer(unsigned(COUNTER)) + 1, 4));
end if;
-- turn digits on
AN1 <= AN(3);
AN2 <= AN(2);
AN3 <= AN(1);
AN4 <= AN(0);
-- map BCD input to desired output segments
case SEC_1 is
when =>
SEC_1_DISPLAY <= "0000001"; -- 0
when "0001" =>
SEC_1_DISPLAY <= "1001111"; -- 1
when "0010" =>
SEC_1_DISPLAY <= "0010010"; -- 2
when "0011" =>
SEC_1_DISPLAY <= "0000110"; -- 3
when "0100" =>
SEC_1_DISPLAY <= "1001100"; -- 4
when "0101" =>
SEC_1_DISPLAY <= "0100100"; -- 5
when "0110" =>
SEC_1_DISPLAY <= "0100000"; -- 6
when "0111" =>
SEC_1_DISPLAY <= "0001111"; -- 7
when "1000" =>
SEC_1_DISPLAY <= "0000000"; -- 8
when "1001" =>
SEC_1_DISPLAY <= "0000100"; -- 9
when others =>
SEC_1_DISPLAY <= "1111111"; -- blank when not a digit
end case;
C_A <= SEC_1_DISPLAY(6);
C_B <= SEC_1_DISPLAY(5);
C_C <= SEC_1_DISPLAY(4);
C_D <= SEC_1_DISPLAY(3);
C_E <= SEC_1_DISPLAY(2);
C_F <= SEC_1_DISPLAY(1);
C_G <= SEC_1_DISPLAY(0);
end process;
end Behavioral;