-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputer.vhd
More file actions
195 lines (159 loc) · 5.07 KB
/
Computer.vhd
File metadata and controls
195 lines (159 loc) · 5.07 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Computer is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR(7 downto 0);
an : out STD_LOGIC_VECTOR(3 downto 0);
JB : out STD_LOGIC_VECTOR(7 downto 0);
lcd_rs, lcd_rw, lcd_en : out STD_LOGIC);
end Computer;
architecture Behavioral of Computer is
--Internal signals
signal mem_en : STD_LOGIC;
signal cpu_rw : STD_LOGIC;
signal dataBus : STD_LOGIC_VECTOR(7 downto 0);
signal addrBus : STD_LOGIC_VECTOR(7 downto 0);
signal romEnable : STD_LOGIC;
signal ramEnable : STD_LOGIC;
--Stuf for IO/LCD screen
signal load_io_a, load_io_b : STD_LOGIC;
signal lcd_a, lcd_b : STD_LOGIC_VECTOR(7 downto 0);
--Seven segments display on Basys3
signal hexDisp : STD_LOGIC_VECTOR(15 downto 0);
--Slower clock for all of the components
signal global_clk : STD_LOGIC;
Component CPU
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
rw : out STD_LOGIC;
mem_en : out STD_LOGIC;
addr : out STD_LOGIC_VECTOR (7 downto 0);
dataBus : inout STD_LOGIC_VECTOR (7 downto 0));
end Component;
Component ROM
Generic(AddrSize : Integer := 7;
DataSize : Integer := 8);
Port ( addr : in STD_LOGIC_VECTOR (AddrSize-1 downto 0);
en : in STD_LOGIC;
dataOut : out STD_LOGIC_VECTOR (Datasize-1 downto 0));
end Component;
Component RAM
Generic( AddrSize : Integer := 7;
DataSize : Integer := 8);
Port ( clk : in STD_LOGIC;
load : in STD_LOGIC;
en : in STD_LOGIC;
addr : in STD_LOGIC_VECTOR (AddrSize-1 downto 0);
dataBus : inout STD_LOGIC_VECTOR (DataSize-1 downto 0));
end Component;
--Sevensegments display on basys3
Component SixteenBitDisplay
Port ( sw : in STD_LOGIC_VECTOR (15 downto 0);
clk : in STD_LOGIC;
rst : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR (7 downto 0);
an : out STD_LOGIC_VECTOR(3 downto 0));
end Component;
--Counter for slowing down clock, set to a million down below
Component ModMCounter
Generic(N : integer := 7;
M : Integer := 100);
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
q : out STD_LOGIC_VECTOR(N-1 downto 0);
max_tick : out STD_LOGIC);
end Component;
--IO registers
Component IO
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
en_load : in STD_LOGIC;
load_a : in STD_LOGIC;
load_b : in STD_LOGIC;
dataBus : in STD_LOGIC_VECTOR(7 downto 0);
Z_a : out STD_LOGIC_VECTOR(7 downto 0);
Z_b : out STD_LOGIC_VECTOR(7 downto 0));
end Component;
begin
--Rom is enabled when mem_en is high and were in the lower address space
romEnable <= '1' when (mem_en = '1' and addrBus(7) = '0') else
'0';
--Ram is enabled when mem_en is high and were in the upper address space
ramEnable <= '1' when (mem_en = '1' and addrBus(7) = '1') else
'0';
--Display address bus and data bus on seven segment display
hexDisp(15 downto 8) <= addrBus(7 downto 0);
hexDisp(7 downto 0) <= dataBus(7 downto 0);
--Io is currently setup to only work as output, to interface with an lcd display:
load_io_a <= '1' when addrBus = "11111111" else
'0';
load_io_b <= '1' when addrBus = "11111110" else
'0';
JB <= lcd_b;
lcd_rs <= lcd_a(5);
lcd_rw <= lcd_a(6);
lcd_en <= lcd_a(7);
processor : CPU
port map
(
clk => global_clk,
rst => rst,
rw => cpu_rw,
mem_en => mem_en,
addr => addrBus,
dataBus => dataBus
);
readOnlyMem : ROM
port map
(
addr => addrBus(6 downto 0),
en => romEnable,
dataOut => dataBus
);
writeMem : RAM
port map
(
clk => global_clk,
load => cpu_rw,
en => ramEnable,
addr => addrBus(6 downto 0),
dataBus => dataBus
);
sseg: SixteenBitDisplay
port map
(
sw => hexDisp,
clk => clk,
rst => rst,
seg => seg,
an => an
);
modMillionCounter : ModMCounter
generic map
(
N => 27,
M => 1000000
)
port map
(
clk => clk,
rst => rst,
q => open,
max_tick => global_clk --set as open for simulation, as we don't want a slow clock in that case
);
--Uncomment for simulation
--global_clk <= clk;
io_reg : IO
port map
(
clk => global_clk,
rst => rst,
en_load => cpu_rw,
load_a => load_io_a,
load_b => load_io_b,
dataBus => dataBus,
Z_a => lcd_a,
Z_b => lcd_b
);
end Behavioral;