-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay.vhd
119 lines (97 loc) · 2.68 KB
/
Display.vhd
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
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 11:42:52 12/08/2019
-- Design Name:
-- Module Name: DisplayViewer - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
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 DisplayViewer is
Port ( SYSCLK : in STD_LOGIC;
NUM_L : in integer range 0 to 2047;
NUM_R : in integer range 0 to 2047;
Q : out STD_LOGIC_VECTOR (0 to 15));
end DisplayViewer;
architecture Behavioral of DisplayViewer is
component DigitToCathodes
port ( D : in integer;
CA : out STD_LOGIC_VECTOR(0 to 7));
end component;
component CLK_DIV
generic (N: integer := 16);
port (
CLK: in STD_LOGIC;
Q: out STD_LOGIC
);
end component;
type digits_arr is array (natural range <>) of integer range 0 to 9;
subtype num_digits is digits_arr(0 to 3);
subtype full_digits_arr is digits_arr(0 to 7);
signal clk: std_logic := '0';
signal disp_anode: std_logic_vector (0 to 7) := "11111111";
signal disp_cathod: std_logic_vector (0 to 7) := "11111111";
signal curr_digit: integer range 0 to 9 := 0;
signal curr_digit_index: integer range 0 to 7 := 0;
signal digits: full_digits_arr := (8, 7, 6, 5, 4, 3, 2, 1);
function IntToDigits (NUM: in integer range 0 to 2047) return num_digits is
variable x : integer range 0 to 2047;
variable digits : num_digits;
begin
x := NUM;
for i in 0 to 3 loop
digits(i) := x mod 10;
x := x / 10;
end loop;
return digits;
end;
begin
clk_div_proc: CLK_DIV port map (
CLK => SYSCLK,
Q => clk
);
cathodes: DigitToCathodes port map (
D => curr_digit,
CA => disp_cathod
);
anodes: process(curr_digit_index, clk)
begin
if rising_edge(clk) then
disp_anode <= (others => '1');
disp_anode(curr_digit_index) <= '0';
else
disp_anode <= (others => '1');
end if;
end process;
converter_to_digits: process(NUM_L, NUM_R)
begin
digits <= IntToDigits(NUM_R) & IntToDigits(NUM_L);
end process;
clk_proc: process(clk)
variable next_index: integer range 0 to 7;
begin
if rising_edge(clk) then
next_index := (curr_digit_index + 1) mod 8;
curr_digit <= digits(curr_digit_index);
curr_digit_index <= next_index;
end if;
end process;
Q <= disp_anode & disp_cathod;
end Behavioral;