-
Notifications
You must be signed in to change notification settings - Fork 1
/
Backup 5 Working with Variables.txt
164 lines (143 loc) · 3.95 KB
/
Backup 5 Working with Variables.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
----------------------------------------------------------------------------------
-- 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 NUMBER
signal CLK_COUNTER : natural range 0 to 50000000 := 0;
-- which AN port to trigger
signal COUNTER: natural range 0 to 3 := 0;
-- AN ports
signal AN : std_logic_vector(3 downto 0);
-- BCD of digits
--signal HR2
--signal HR1
signal MIN2 : STD_LOGIC_VECTOR(3 downto 0) := "0100";
signal MIN1 : STD_LOGIC_VECTOR(3 downto 0) := "0011";
signal SEC2 : STD_LOGIC_VECTOR(3 downto 0) := "0010";
signal SEC1 : STD_LOGIC_VECTOR(3 downto 0) := "0001";
-- counter of number to display
signal NUMBER : STD_LOGIC_VECTOR(3 downto 0);
-- information for 7 segment display
signal DISPLAY : std_logic_vector(6 downto 0);
begin
-- do stuff every 1 ms, dividing clock signal
Clock_Divider2 : process (CLK)
begin
if (rising_edge(CLK)) then
CLK_COUNTER <= CLK_COUNTER + 1;
-- every 8000 ticks, so every 1 ms for a 8 MHz clock
if (CLK_COUNTER >= 8000) then
CLK_COUNTER <= 0;
-- increment COUNTER from 1 to 3
COUNTER <= COUNTER + 1;
if (COUNTER > 3) then
COUNTER <= 0;
end if;
end if;
end if;
end process;
-- use COUNTER to modify which AN port is on
Change_AN : process (COUNTER)
begin
case COUNTER is
when 0 => AN <= "1110";
when 1 => AN <= "1101";
when 2 => AN <= "1011";
when 3 => AN <= "0111";
end case;
-- turn AN ports on or off accordingly
AN1 <= AN(3);
AN2 <= AN(2);
AN3 <= AN(1);
AN4 <= AN(0);
end process;
-- change counter (number displayed) based on COUNTER
Change_Counter : process (COUNTER)
begin
case COUNTER is
when 0 => NUMBER <= SEC1;
when 1 => NUMBER <= SEC2;
when 2 => NUMBER <= MIN1;
when 3 => NUMBER <= MIN2;
end case;
end process;
-- display numbers
Display_LED : process(NUMBER)
begin
case NUMBER is
when "0000" =>
DISPLAY <= "0000001"; -- 0
when "0001" =>
DISPLAY <= "1001111"; -- 1
when "0010" =>
DISPLAY <= "0010010"; -- 2
when "0011" =>
DISPLAY <= "0000110"; -- 3
when "0100" =>
DISPLAY <= "1001100"; -- 4
when "0101" =>
DISPLAY <= "0100100"; -- 5
when "0110" =>
DISPLAY <= "0100000"; -- 6
when "0111" =>
DISPLAY <= "0001111"; -- 7
when "1000" =>
DISPLAY <= "0000000"; -- 8
when "1001" =>
DISPLAY <= "0000100"; -- 9
when others =>
DISPLAY <= "1111111"; -- blank when not a digit
end case;
-- send information to board
C_A <= DISPLAY(6);
C_B <= DISPLAY(5);
C_C <= DISPLAY(4);
C_D <= DISPLAY(3);
C_E <= DISPLAY(2);
C_F <= DISPLAY(1);
C_G <= DISPLAY(0);
end process;
end Behavioral;