-
Notifications
You must be signed in to change notification settings - Fork 1
/
FinalDisplay.vhd
595 lines (519 loc) · 15.1 KB
/
FinalDisplay.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
----------------------------------------------------------------------------------
-- 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;
-- LED 0 for clock 2 indicator
LD0 : out STD_LOGIC;
--Reset button
RESET : in STD_LOGIC;
-- clock 2 from 555 timer
clk2 : in STD_LOGIC;
-- set switch
set : in STD_LOGIC;
-- set buttons
set_min : in STD_LOGIC;
set_hour : in STD_LOGIC;
set_day : in STD_LOGIC;
set_month : in 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) := "0000";
signal MIN1 : STD_LOGIC_VECTOR(3 downto 0) := "0000";
signal SEC2 : STD_LOGIC_VECTOR(3 downto 0) := "0000";
signal SEC1 : STD_LOGIC_VECTOR(3 downto 0) := "0000";
-- 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);
-- contains the numbers to be displayed (1 = left, 2 = right)
signal hour1 : std_logic_vector(3 downto 0);
signal hour2 : std_logic_vector(3 downto 0);
-- if 24 hour or not
signal hour24: std_logic_vector(0 downto 0);
-- PM/AM dot
signal dot: std_logic_vector(0 downto 0); -- AM & PM
-- this one contains 8 bits for the switch statement, it is one 4 bit
-- number and another 4 bit number, not an 8 bit number
signal month : std_logic_vector(7 downto 0);
signal day1 : std_logic_vector(3 downto 0);
signal day2 : std_logic_vector(3 downto 0);
-- extra variables to know when to increment the month
signal maxday1 : std_logic_vector(3 downto 0);
signal maxday2 : std_logic_vector(3 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;
-----process clock-----
divide: process(clk2)
begin
if(rising_edge(clk2) AND set = '0') then
if(sec1 = "1001") then
sec1 <= "0000";
if(sec2 = "0101") then
sec2 <= "0000";
if(min1 = "1001") then
min1 <= "0000";
if(min2 = "0101") then
min2 <= "0000";
if(hour24 = "1") then
--24 hour time
if(hour1 = "1001" AND (hour2 = "0000" OR hour2 = "0001")) then
hour1 <= "0000";
hour2 <= std_logic_vector(to_unsigned(to_integer(unsigned( hour2 )) + 1, 4));
elsif (hour1 = "0011" AND hour2 = "0010") then
hour1 <= "0000";
hour2 <= "0000";
case month is
--january
when "00000001" =>
maxday1 <= "0001";
maxday2 <= "0011";
--february
when "00000010" =>
maxday1 <= "1000";
maxday2 <= "0010";
--march
when "00000011" =>
maxday1 <= "0001";
maxday2 <= "0011";
--april
when "00000100" =>
maxday1 <= "0000";
maxday2 <= "0011";
--may
when "00000101" =>
maxday1 <= "0001";
maxday2 <= "0011";
--june
when "00000110" =>
maxday1 <= "0000";
maxday2 <= "0011";
--july
when "00000111" =>
maxday1 <= "0001";
maxday2 <= "0011";
--august
when "00001000" =>
maxday1 <= "0001";
maxday2 <= "0011";
--september
when "00001001" =>
maxday1 <= "0000";
maxday2 <= "0011";
--october
when "00010000" =>
maxday1 <= "0001";
maxday2 <= "0011";
--november
when "00010001" =>
maxday1 <= "0000";
maxday2 <= "0011";
--december
when "00010010" =>
maxday1 <= "0001";
maxday2 <= "0011";
when others =>
maxday1 <= "0000";
maxday2 <= "0000";
end case;
if(day1 = maxday1 AND day2 = maxday2) then
day1 <= "0001";
day2 <= "0000";
if(month < "00001010") then
month <= std_logic_vector(to_unsigned(to_integer(unsigned( month )) +1, 8));
elsif(month = "00001010") then
month <= "00010000";
elsif(month = "00010000") then
month <= "00010001";
elsif(month = "00010001") then
month <= "00010010";
elsif(month = "00010010") then
month <= "00000000";
end if;
else
if(day1 = "1001") then
day1 <= "0000";
day2 <= std_logic_vector(to_unsigned(to_integer(unsigned( day2 )) +1, 4));
else
day1 <= std_logic_vector(to_unsigned(to_integer(unsigned( day1 )) +1, 4));
end if;
end if;
else
hour1 <= std_logic_vector(to_unsigned(to_integer(unsigned( hour1 )) + 1, 4));
end if;
else
--not 24
if(hour1 = "1001" AND hour2 = "0000") then
hour1 <= "0000";
hour2 <= std_logic_vector(to_unsigned(to_integer(unsigned( hour2 )) +1, 4));
elsif (hour1 = "0010" AND hour2 = "0001") then
hour1 <= "0001";
hour2 <= "0000";
if (dot = "0")then
dot <= "1";
else
dot <= "0";
case month is
--january
when "00000001" =>
maxday1 <= "0001";
maxday2 <= "0011";
--february
when "00000010" =>
maxday1 <= "1000";
maxday2 <= "0010";
--march
when "00000011" =>
maxday1 <= "0001";
maxday2 <= "0011";
--april
when "00000100" =>
maxday1 <= "0000";
maxday2 <= "0011";
--may
when "00000101" =>
maxday1 <= "0001";
maxday2 <= "0011";
--june
when "00000110" =>
maxday1 <= "0000";
maxday2 <= "0011";
--july
when "00000111" =>
maxday1 <= "0001";
maxday2 <= "0011";
--august
when "00001000" =>
maxday1 <= "0001";
maxday2 <= "0011";
--september
when "00001001" =>
maxday1 <= "0000";
maxday2 <= "0011";
--october
when "00010000" =>
maxday1 <= "0001";
maxday2 <= "0011";
--november
when "00010001" =>
maxday1 <= "0000";
maxday2 <= "0011";
--december
when "00010010" =>
maxday1 <= "0001";
maxday2 <= "0011";
when others =>
maxday1 <= "0000";
maxday2 <= "0000";
end case;
if(day1 = maxday1 AND day2 = maxday2) then
day1 <= "0001";
day2 <= "0000";
if(month < "00001010") then
month <= std_logic_vector(to_unsigned(to_integer(unsigned( month )) +1, 8));
elsif(month = "00001010") then
month <= "00010000";
elsif(month = "00010000") then
month <= "00010001";
elsif(month = "00010001") then
month <= "00010010";
elsif(month = "00010010") then
month <= "00000000";
end if;
else
if(day1 = "1001") then
day1 <= "0000";
day2 <= std_logic_vector(to_unsigned(to_integer(unsigned( day2 )) +1, 4));
else
day1 <= std_logic_vector(to_unsigned(to_integer(unsigned( day1 )) +1, 4));
end if;
end if;
end if;
else
hour1 <= std_logic_vector(to_unsigned(to_integer(unsigned( hour1 )) + 1, 4));
end if;
end if;
else
min2 <= std_logic_vector(to_unsigned(to_integer(unsigned( min2 )) + 1, 4));
end if;
else
min1 <= std_logic_vector(to_unsigned(to_integer(unsigned( min1 )) + 1, 4));
end if;
else
sec2 <= std_logic_vector(to_unsigned(to_integer(unsigned( sec2 )) + 1, 4));
end if;
else
sec1 <= std_logic_vector(to_unsigned(to_integer(unsigned( sec1 )) + 1, 4));
end if;
end if;
if(set = '1') then
sec1 <= "0000";
sec2 <= "0000";
if(set_min = '1') then
if(min1 = "1001") then
if(min2 = "0101") then
min2 <= "0000";
min1 <= "0000";
else
min2 <= std_logic_vector(to_unsigned(to_integer(unsigned( min2 )) + 1, 4));
end if;
else
min1 <= std_logic_vector(to_unsigned(to_integer(unsigned( min1 )) + 1, 4));
end if;
end if;
if(set_hour = '1') then
if(hour24 = "1") then
--24 hour time
if(hour1 = "1001" AND (hour2 = "0000" OR hour2 = "0001")) then
hour1 <= "0000";
hour2 <= std_logic_vector(to_unsigned(to_integer(unsigned( hour2 )) +1, 4));
elsif(hour1 = "0011" AND hour2 = "0010") then
hour1 <= "0000";
hour2 <= "0000";
elsif(hour2 > "0010" OR hour1 > "1001") then
hour2 <= "0000";
hour1 <= "0000";
else
hour1 <= std_logic_vector(to_unsigned(to_integer(unsigned( hour1 )) + 1, 4));
end if;
else
--not 24
if(hour1 = "1001" AND hour2 = "0000") then
hour1 <= "0000";
hour2 <= "0001";
elsif (hour1 = "0010" AND hour2 > "0000") then
hour1 <= "0001";
hour2 <= "0000";
if (dot = "0")then
dot <= "1";
else
dot <= "0";
end if;
elsif(hour2 > "0001" OR hour1 > "1001") then
hour2 <= "0000";
hour1 <= "0000";
else
hour1 <= std_logic_vector(to_unsigned(to_integer(unsigned( hour1 )) + 1, 4));
end if;
end if;
end if;
if(set_day = '1') then
case month is
--january
when "00000001" =>
maxday1 <= "0001";
maxday2 <= "0011";
--february
when "00000010" =>
maxday1 <= "1000";
maxday2 <= "0010";
--march
when "00000011" =>
maxday1 <= "0001";
maxday2 <= "0011";
--april
when "00000100" =>
maxday1 <= "0000";
maxday2 <= "0011";
--may
when "00000101" =>
maxday1 <= "0001";
maxday2 <= "0011";
--june
when "00000110" =>
maxday1 <= "0000";
maxday2 <= "0011";
--july
when "00000111" =>
maxday1 <= "0001";
maxday2 <= "0011";
--august
when "00001000" =>
maxday1 <= "0001";
maxday2 <= "0011";
--september
when "00001001" =>
maxday1 <= "0000";
maxday2 <= "0011";
--october
when "00010000" =>
maxday1 <= "0001";
maxday2 <= "0011";
--november
when "00010001" =>
maxday1 <= "0000";
maxday2 <= "0011";
--december
when "00010010" =>
maxday1 <= "0001";
maxday2 <= "0011";
when others =>
maxday1 <= "0000";
maxday2 <= "0000";
end case;
if(day1 = maxday1 AND day2 = maxday2) then
day1 <= "0001";
day2 <= "0000";
elsif(day1 = "1001") then
day1 <= "0000";
day2 <= std_logic_vector(to_unsigned(to_integer(unsigned( day2 )) + 1, 4));
else
day1 <= std_logic_vector(to_unsigned(to_integer(unsigned( day1 )) + 1, 4));
end if;
end if;
if(set_month = '1') then
if(month < "00001010") then
month <= std_logic_vector(to_unsigned(to_integer(unsigned( month )) + 1, 8));
elsif(month = "00001010") then
month <= "00010000";
elsif(month = "00010000") then
month <= "00010001";
elsif(month = "00010001") then
month <= "00010010";
elsif(month = "00010010") then
month <= "00000000";
else
month <= "00000000";
end if;
end if;
end if;
if(RESET = '0') then
sec1 <= "0000";
sec2 <= "0000";
min1 <= "0000";
min2 <= "0000";
hour1 <= "0000";
hour2 <= "0000";
month <= "00000000";
day1 <= "0000";
day2 <= "0000";
end if;
end process divide;
-- use LED 0 as output for clock
LD0 <= clk2;
end Behavioral;