-
Notifications
You must be signed in to change notification settings - Fork 0
/
MouseProject.circ
868 lines (747 loc) · 23 KB
/
MouseProject.circ
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project source="3.7.2" version="1.0">
This file is intended to be loaded by Logisim-evolution v3.7.2(https://github.com/logisim-evolution/).
<lib desc="#Wiring" name="0">
<tool name="Pin">
<a name="appearance" val="classic"/>
</tool>
</lib>
<lib desc="#Gates" name="1"/>
<lib desc="#Plexers" name="2"/>
<lib desc="#Arithmetic" name="3"/>
<lib desc="#Memory" name="4"/>
<lib desc="#I/O" name="5"/>
<lib desc="#TTL" name="6"/>
<lib desc="#TCL" name="7"/>
<lib desc="#Base" name="8"/>
<lib desc="#BFH-Praktika" name="9"/>
<lib desc="#Input/Output-Extra" name="10"/>
<lib desc="#Soc" name="11"/>
<main name="main"/>
<options>
<a name="gateUndefined" val="ignore"/>
<a name="simlimit" val="1000"/>
<a name="simrand" val="0"/>
</options>
<mappings>
<tool lib="8" map="Button2" name="Menu Tool"/>
<tool lib="8" map="Button3" name="Menu Tool"/>
<tool lib="8" map="Ctrl Button1" name="Menu Tool"/>
</mappings>
<toolbar>
<tool lib="8" name="Poke Tool"/>
<tool lib="8" name="Edit Tool"/>
<tool lib="8" name="Wiring Tool"/>
<tool lib="8" name="Text Tool"/>
<sep/>
<tool lib="0" name="Pin"/>
<tool lib="0" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
</tool>
<sep/>
<tool lib="1" name="NOT Gate"/>
<tool lib="1" name="AND Gate"/>
<tool lib="1" name="OR Gate"/>
<tool lib="1" name="XOR Gate"/>
<tool lib="1" name="NAND Gate"/>
<tool lib="1" name="NOR Gate"/>
<sep/>
<tool lib="4" name="D Flip-Flop"/>
<tool lib="4" name="Register"/>
</toolbar>
<circuit name="main">
<a name="appearance" val="logisim_evolution"/>
<a name="circuit" val="main"/>
<a name="circuitnamedboxfixedsize" val="true"/>
<a name="downloadBoard" val="BASYS3_CB17"/>
<a name="downloadFrequency" val="2.0"/>
<a name="simulationFrequency" val="64.0"/>
<boardmap boardname="BASYS3_CB17">
<mc key="/ANODES" pmap="273_234_0,225_234_0,180_234_0,130_234_0"/>
<mc key="/CATODES" pmap="138_258_0,130_249_0,130_263_0,136_274_0,154_262_0,154_248_0,136_245_0"/>
<mc key="/CLOCK" map="321,237"/>
<mc key="/IS_LEFT" map="92,295"/>
<mc key="/PCLOCK" map="527,86"/>
<mc key="/PDATA" map="544,104"/>
<mc key="/RESET" map="78,323"/>
<mc key="/REVERSE" map="117,323"/>
</boardmap>
<comp lib="0" loc="(110,150)" name="Pin">
<a name="appearance" val="NewPins"/>
<a name="label" val="CLOCK"/>
</comp>
<comp lib="0" loc="(110,170)" name="Pin">
<a name="appearance" val="NewPins"/>
<a name="label" val="RESET"/>
</comp>
<comp lib="0" loc="(110,190)" name="Pin">
<a name="appearance" val="NewPins"/>
<a name="label" val="REVERSE"/>
</comp>
<comp lib="0" loc="(1450,270)" name="Pin">
<a name="appearance" val="NewPins"/>
<a name="facing" val="west"/>
<a name="label" val="ANODES"/>
<a name="output" val="true"/>
<a name="width" val="4"/>
</comp>
<comp lib="0" loc="(1450,290)" name="Pin">
<a name="appearance" val="NewPins"/>
<a name="facing" val="west"/>
<a name="label" val="CATODES"/>
<a name="output" val="true"/>
<a name="width" val="7"/>
</comp>
<comp lib="0" loc="(210,430)" name="Pin">
<a name="appearance" val="NewPins"/>
<a name="label" val="PCLOCK"/>
</comp>
<comp lib="0" loc="(210,450)" name="Pin">
<a name="appearance" val="NewPins"/>
<a name="label" val="PDATA"/>
</comp>
<comp lib="0" loc="(880,80)" name="Pin">
<a name="appearance" val="NewPins"/>
<a name="facing" val="west"/>
<a name="label" val="IS_LEFT"/>
<a name="output" val="true"/>
</comp>
<comp loc="(1130,150)" name="COUNTER">
<a name="appearance" val="logisim_evolution"/>
<a name="label" val="counter_1"/>
</comp>
<comp loc="(1450,270)" name="SSD_MANAGER">
<a name="appearance" val="logisim_evolution"/>
<a name="label" val="ssd_manager_1"/>
</comp>
<comp loc="(600,390)" name="PS2_READER">
<a name="appearance" val="logisim_evolution"/>
<a name="label" val="ps2_reader_1"/>
</comp>
<comp loc="(770,150)" name="CONTROL_UNIT">
<a name="appearance" val="logisim_evolution"/>
<a name="label" val="control_unit_1"/>
</comp>
<wire from="(110,150)" to="(360,150)"/>
<wire from="(110,170)" to="(330,170)"/>
<wire from="(110,190)" to="(550,190)"/>
<wire from="(1130,150)" to="(1160,150)"/>
<wire from="(1160,150)" to="(1160,310)"/>
<wire from="(1160,310)" to="(1230,310)"/>
<wire from="(1230,110)" to="(1230,270)"/>
<wire from="(210,430)" to="(380,430)"/>
<wire from="(210,450)" to="(380,450)"/>
<wire from="(330,170)" to="(330,410)"/>
<wire from="(330,170)" to="(530,170)"/>
<wire from="(330,410)" to="(380,410)"/>
<wire from="(360,150)" to="(360,390)"/>
<wire from="(360,150)" to="(510,150)"/>
<wire from="(360,390)" to="(380,390)"/>
<wire from="(510,110)" to="(510,150)"/>
<wire from="(510,110)" to="(860,110)"/>
<wire from="(510,150)" to="(550,150)"/>
<wire from="(520,210)" to="(520,300)"/>
<wire from="(520,210)" to="(550,210)"/>
<wire from="(520,300)" to="(630,300)"/>
<wire from="(530,130)" to="(530,170)"/>
<wire from="(530,130)" to="(850,130)"/>
<wire from="(530,170)" to="(550,170)"/>
<wire from="(540,230)" to="(540,280)"/>
<wire from="(540,230)" to="(550,230)"/>
<wire from="(540,280)" to="(650,280)"/>
<wire from="(600,390)" to="(630,390)"/>
<wire from="(600,410)" to="(650,410)"/>
<wire from="(630,300)" to="(630,390)"/>
<wire from="(650,280)" to="(650,410)"/>
<wire from="(770,170)" to="(830,170)"/>
<wire from="(770,190)" to="(810,190)"/>
<wire from="(770,80)" to="(770,150)"/>
<wire from="(770,80)" to="(880,80)"/>
<wire from="(810,190)" to="(810,210)"/>
<wire from="(810,210)" to="(910,210)"/>
<wire from="(830,170)" to="(830,190)"/>
<wire from="(830,190)" to="(910,190)"/>
<wire from="(850,130)" to="(850,170)"/>
<wire from="(850,170)" to="(890,170)"/>
<wire from="(860,110)" to="(1230,110)"/>
<wire from="(860,110)" to="(860,150)"/>
<wire from="(860,150)" to="(910,150)"/>
<wire from="(890,170)" to="(890,290)"/>
<wire from="(890,170)" to="(910,170)"/>
<wire from="(890,290)" to="(1230,290)"/>
</circuit>
<vhdl name="PS2_READER">library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity PS2_READER is
port (
CLOCK : in std_logic;
RESET : in std_logic;
PS2_CLOCK : in std_logic;
PS2_DATA : in std_logic;
LEFT_CLICK : out std_logic;
RIGHT_CLICK : out std_logic
);
end PS2_READER;
architecture Behavioral of PS2_READER is
signal MOUSE_REGISTER : std_logic_vector(42 downto 0) := (others => '0');
signal MOUSE_BITS : std_logic_vector(5 downto 0) := (others => '0');
signal REGISTER_FULL : std_logic;
signal IS_LEFT_PRESSED : std_logic := '0';
signal IS_RIGHT_PRESSED : std_logic := '0';
signal IDLE : std_logic := '1';
begin
BIT_COUNT_PROCESS : process (PS2_CLOCK, RESET)
begin
if RESET = '0' then
MOUSE_BITS <= (others => '0');
elsif falling_edge(PS2_CLOCK) then
if MOUSE_BITS <= 42 then
MOUSE_BITS <= MOUSE_BITS + 1;
else
MOUSE_BITS <= (others => '0');
end if;
end if;
end process;
REGISTER_PROCESS : process (PS2_CLOCK, RESET)
begin
REGISTER_FULL <= '0';
if RESET = '0' then
MOUSE_REGISTER <= (others => '0');
elsif falling_edge(PS2_CLOCK) then
MOUSE_REGISTER <= MOUSE_REGISTER(41 downto 0) & PS2_DATA;
if MOUSE_BITS = 42 then
REGISTER_FULL <= '1';
end if;
end if;
end process;
SIGNAL_PROCESS: process (CLOCK)
begin
if rising_edge(CLOCK) then
LEFT_CLICK <= '0';
RIGHT_CLICK <= '0';
if REGISTER_FULL = '1' then
if MOUSE_REGISTER(41) = '1' and IS_LEFT_PRESSED = '0' then
LEFT_CLICK <= '1';
elsif MOUSE_REGISTER(40) = '1' and IS_RIGHT_PRESSED = '0' then
RIGHT_CLICK <= '1';
end if;
IS_LEFT_PRESSED <= MOUSE_REGISTER(41);
IS_RIGHT_PRESSED <= MOUSE_REGISTER(40);
end if;
end if;
end process;
-- COUNTER_PROCESS : process (CLOCK, RESET)
-- begin
-- if RESET = '0' then
-- CLICK_COUNT <= (others => '0');
-- elsif rising_edge(CLOCK) then
-- if REGISTER_FULL = '1' then
-- if MOUSE_REGISTER(41) = '1' and IS_LEFT_PRESSED = '0' then
-- CLICK_COUNT <= CLICK_COUNT + 1;
-- elsif MOUSE_REGISTER(40) = '1' and IS_RIGHT_PRESSED = '0' then
-- CLICK_COUNT <= CLICK_COUNT - 1;
-- end if;
-- IS_LEFT_PRESSED <= MOUSE_REGISTER(41);
-- IS_RIGHT_PRESSED <= MOUSE_REGISTER(40);
-- end if;
-- end if;
--
-- TEST <= CLICK_COUNT;
-- end process;
end Behavioral;
</vhdl>
<vhdl name="COUNTER">LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
ENTITY COUNTER IS
PORT (
CLOCK: in std_logic;
RESET: in std_logic;
INCREMENT, DECREMENT: in std_logic;
OUTNUMBER: out std_logic_vector(15 downto 0)
);
END COUNTER;
ARCHITECTURE Behavioral OF COUNTER IS
signal NUMBER: std_logic_vector(15 downto 0) := (others => '0');
BEGIN
CLOCK_ACTIVE: process (CLOCK, RESET)
begin
if RESET = '0' then
NUMBER <= (others => '0');
elsif rising_edge(CLOCK) then
if INCREMENT = '1' then
if NUMBER < 9999 then
NUMBER <= NUMBER + 1;
else
NUMBER <= "0010011100001111"; --9999
end if;
elsif DECREMENT = '1' then
if NUMBER > 0 then
NUMBER <= NUMBER - 1;
else
NUMBER <= (others => '0');
end if;
end if;
end if;
OUTNUMBER <= NUMBER;
end process;
END Behavioral;
</vhdl>
<vhdl name="CONTROL_UNIT">LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY CONTROL_UNIT IS
PORT (
CLOCK: in std_logic;
RESET: in std_logic;
REVERSE: in std_logic;
LEFT_CLICK, RIGHT_CLICK: in std_logic;
IS_LEFT, INC, DEC: out std_logic
);
END CONTROL_UNIT;
ARCHITECTURE Behavioral OF CONTROL_UNIT IS
BEGIN
CONTROL_UNIT: process (CLOCK, RESET)
begin
if RESET = '0' then
INC <= '0';
DEC <= '0';
elsif rising_edge(CLOCK) then
INC <= '0';
DEC <= '0';
if REVERSE = '0' then
IS_LEFT <= '1';
if LEFT_CLICK = '1' then
INC <= '1';
elsif RIGHT_CLICK = '1' then
DEC <= '1';
end if;
else
IS_LEFT <= '0';
if LEFT_CLICK = '1' then
DEC <= '1';
elsif RIGHT_CLICK = '1' then
INC <= '1';
end if;
end if;
end if;
end process;
END Behavioral;
</vhdl>
<vhdl name="BCD7SGT">LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY BCD7SGT IS
PORT (
INPUT: in std_logic_vector(3 downto 0);
OUTPUT: out std_logic_vector(6 downto 0)
);
END BCD7SGT;
ARCHITECTURE Behavioral OF BCD7SGT IS
BEGIN
with INPUT select OUTPUT <=
"1111110" when "0000",
"0110000" when "0001",
"1101101" when "0010",
"1111001" when "0011",
"0110011" when "0100",
"1011011" when "0101",
"1011111" when "0110",
"1110000" when "0111",
"1111111" when "1000",
"1111011" when "1001",
"1110111" when "1010",
"0011111" when "1011",
"1001110" when "1100",
"0111101" when "1101",
"1001111" when "1110",
"1000111" when "1111",
"0000000" when others;
END Behavioral;
</vhdl>
<vhdl name="RING_SHIFTER">LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
ENTITY RING_SHIFTER IS
PORT (
CLOCK: in std_logic;
RESET: in std_logic;
OUTPUT: out std_logic_vector(3 downto 0)
);
END RING_SHIFTER;
ARCHITECTURE TypeArchitecture OF RING_SHIFTER IS
signal CONTENT: std_logic_vector(3 downto 0) := "0001";
BEGIN
CLOCK_SIGNAL: process (CLOCK, RESET)
begin
if RESET = '0' then
CONTENT <= "0001";
elsif rising_edge(CLOCK) then
CONTENT <= CONTENT(0) & CONTENT(3 downto 1);
end if;
OUTPUT <= CONTENT;
end process;
END TypeArchitecture;
</vhdl>
<vhdl name="MUX4TO1">LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
ENTITY MUX4TO1 IS
PORT (
INPUT1: in std_logic_vector(3 downto 0);
INPUT2: in std_logic_vector(3 downto 0);
INPUT3: in std_logic_vector(3 downto 0);
INPUT4: in std_logic_vector(3 downto 0);
SELECTION: in std_logic_vector(1 downto 0);
OUTPUT: out std_logic_vector(3 downto 0)
);
END MUX4TO1;
ARCHITECTURE Behavioral OF MUX4TO1 IS
BEGIN
OUTPUT <= INPUT1 when SELECTION = "00" else
INPUT2 when SELECTION = "01" else
INPUT3 when SELECTION = "10" else
INPUT4 when SELECTION = "11";
END Behavioral;
</vhdl>
<vhdl name="PRIORITY_ENCODER">LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY PRIORITY_ENCODER IS
PORT (
INPUT: in std_logic_vector(3 downto 0);
OUTPUT: out std_logic_vector(1 downto 0)
);
END PRIORITY_ENCODER;
ARCHITECTURE Behavioral OF PRIORITY_ENCODER IS
BEGIN
OUTPUT <= "11" when INPUT(3) = '1' else
"10" when INPUT(3 downto 2) = "01" else
"01" when INPUT(3 downto 1) = "001" else
"00" when INPUT(3 downto 0) = "0001";
END Behavioral;
</vhdl>
<vhdl name="DIGIT_SPLITTER">LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
ENTITY DIGIT_SPLITTER IS
PORT (
NUMBER: in std_logic_vector(15 downto 0);
D1, D2, D3, D4: out std_logic_vector(3 downto 0)
);
END DIGIT_SPLITTER;
ARCHITECTURE Behavioral OF DIGIT_SPLITTER IS
BEGIN
SPLIT: process(NUMBER)
variable DECIMAL : integer := 0;
variable N: integer := 0;
begin
N := conv_integer(NUMBER);
DECIMAL := N rem 10;
D1 <= std_logic_vector(to_unsigned(DECIMAL, 4));
N := N / 10;
DECIMAL := N rem 10;
D2 <= std_logic_vector(to_unsigned(DECIMAL, 4));
N := N / 10;
DECIMAL := N rem 10;
D3 <= std_logic_vector(to_unsigned(DECIMAL, 4));
N := N / 10;
DECIMAL := N rem 10;
D4 <= std_logic_vector(to_unsigned(DECIMAL, 4));
end process;
END Behavioral;
</vhdl>
<vhdl name="FREQUENCY_DIVIDER">LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
ENTITY FREQUENCY_DIVIDER IS
PORT (
CLOCK_100: in std_logic;
RESET: in std_logic;
CLK_DIVIDED: out std_logic
);
END FREQUENCY_DIVIDER;
ARCHITECTURE Behavioral OF FREQUENCY_DIVIDER IS
BEGIN
process(CLOCK_100)
variable nr: std_logic_vector (15 downto 0) := (others => '0');
begin
if RESET = '0' then
nr := (others => '0');
elsif rising_edge(CLOCK_100) then
nr := nr + 1;
end if;
CLK_DIVIDED <= nr(15);
end process;
END Behavioral;
</vhdl>
<vhdl name="SSD_MANAGER">LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY SSD_MANAGER IS
PORT (
CLOCK: in std_logic;
RESET: in std_logic;
NUMBER: in std_logic_vector(15 downto 0);
ANODES: out std_logic_vector(3 downto 0);
CATODES: out std_logic_vector(6 downto 0)
);
END SSD_MANAGER;
ARCHITECTURE Structural OF SSD_MANAGER IS
COMPONENT FREQUENCY_DIVIDER IS
PORT (
CLOCK_100: in std_logic;
RESET: in std_logic;
CLK_DIVIDED: out std_logic
);
END component;
component RING_SHIFTER IS
PORT (
CLOCK: in std_logic;
RESET: in std_logic;
OUTPUT: out std_logic_vector(3 downto 0)
);
END component;
component PRIORITY_ENCODER IS
PORT (
INPUT: in std_logic_vector(3 downto 0);
OUTPUT: out std_logic_vector(1 downto 0)
);
END component;
component DIGIT_SPLITTER IS
PORT (
NUMBER: in std_logic_vector(15 downto 0);
D1, D2, D3, D4: out std_logic_vector(3 downto 0)
);
END component;
component MUX4TO1 IS
PORT (
INPUT1: in std_logic_vector(3 downto 0);
INPUT2: in std_logic_vector(3 downto 0);
INPUT3: in std_logic_vector(3 downto 0);
INPUT4: in std_logic_vector(3 downto 0);
SELECTION: in std_logic_vector(1 downto 0);
OUTPUT: out std_logic_vector(3 downto 0)
);
END component;
component BCD7SGT IS
PORT (
INPUT: in std_logic_vector(3 downto 0);
OUTPUT: out std_logic_vector(6 downto 0)
);
END component;
signal CLOCK_DIVIDED: std_logic;
signal ANODES_SIGNAL: std_logic_vector(3 downto 0);
signal ANODE_SELECT: std_logic_vector(1 downto 0);
signal DIGIT_SELECT: std_logic_vector(3 downto 0);
signal DIGIT1, DIGIT2, DIGIT3, DIGIT4: std_logic_vector(3 downto 0);
BEGIN
FREQ_DIV: FREQUENCY_DIVIDER port map(CLOCK, RESET, CLOCK_DIVIDED);
RING_SHIFT: RING_SHIFTER port map(CLOCK_DIVIDED, RESET, ANODES_SIGNAL);
ANODES <= ANODES_SIGNAL;
PRIORITY_ENC: PRIORITY_ENCODER port map(ANODES_SIGNAL, ANODE_SELECT);
DIGIT_SPLT: DIGIT_SPLITTER port map(NUMBER, DIGIT1, DIGIT2, DIGIT3, DIGIT4);
MUX: MUX4TO1 port map(DIGIT1, DIGIT2, DIGIT3, DIGIT4, ANODE_SELECT, DIGIT_SELECT);
DIGIT_DEC: BCD7SGT port map(DIGIT_SELECT, CATODES);
END Structural;
-------------------------------------------------------
------------------ FREQUENCY DIVIDER ------------------
-------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
ENTITY FREQUENCY_DIVIDER IS
PORT (
CLOCK_100: in std_logic;
RESET: in std_logic;
CLK_DIVIDED: out std_logic
);
END FREQUENCY_DIVIDER;
ARCHITECTURE Behavioral OF FREQUENCY_DIVIDER IS
BEGIN
process(CLOCK_100)
variable nr: std_logic_vector (15 downto 0) := (others => '0');
begin
if RESET = '0' then
nr := (others => '0');
elsif rising_edge(CLOCK_100) then
nr := nr + 1;
end if;
--CHANGE TO 15
CLK_DIVIDED <= nr(15);
end process;
END Behavioral;
-------------------------------------------------------
--------------------- RING SHIFTER --------------------
-------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
ENTITY RING_SHIFTER IS
PORT (
CLOCK: in std_logic;
RESET: in std_logic;
OUTPUT: out std_logic_vector(3 downto 0)
);
END RING_SHIFTER;
ARCHITECTURE TypeArchitecture OF RING_SHIFTER IS
signal CONTENT: std_logic_vector(3 downto 0) := "0001";
BEGIN
CLOCK_SIGNAL: process (CLOCK)
begin
if RESET = '0' then
CONTENT <= "0001";
elsif rising_edge(CLOCK) then
CONTENT <= CONTENT(0) & CONTENT(3 downto 1);
end if;
OUTPUT <= CONTENT;
end process;
END TypeArchitecture;
-------------------------------------------------------
------------------- PROPRITY ENCODER ------------------
-------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY PRIORITY_ENCODER IS
PORT (
INPUT: in std_logic_vector(3 downto 0);
OUTPUT: out std_logic_vector(1 downto 0)
);
END PRIORITY_ENCODER;
ARCHITECTURE Behavioral OF PRIORITY_ENCODER IS
BEGIN
OUTPUT <= "11" when INPUT(3) = '1' else
"10" when INPUT(3 downto 2) = "01" else
"01" when INPUT(3 downto 1) = "001" else
"00" when INPUT(3 downto 0) = "0001";
END Behavioral;
-------------------------------------------------------
------------------- DIGIT_SPLITTER --------------------
-------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
ENTITY DIGIT_SPLITTER IS
PORT (
NUMBER: in std_logic_vector(15 downto 0);
D1, D2, D3, D4: out std_logic_vector(3 downto 0)
);
END DIGIT_SPLITTER;
ARCHITECTURE Behavioral OF DIGIT_SPLITTER IS
BEGIN
SPLIT: process(NUMBER)
variable DECIMAL : integer := 0;
variable N: integer := 0;
begin
N := conv_integer(NUMBER);
DECIMAL := N rem 10;
D1 <= std_logic_vector(to_unsigned(DECIMAL, 4));
N := N / 10;
DECIMAL := N rem 10;
D2 <= std_logic_vector(to_unsigned(DECIMAL, 4));
N := N / 10;
DECIMAL := N rem 10;
D3 <= std_logic_vector(to_unsigned(DECIMAL, 4));
N := N / 10;
DECIMAL := N rem 10;
D4 <= std_logic_vector(to_unsigned(DECIMAL, 4));
end process;
END Behavioral;
-------------------------------------------------------
------------------ MUX 4 TO 1 4BIT --------------------
-------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
ENTITY MUX4TO1 IS
PORT (
INPUT1: in std_logic_vector(3 downto 0);
INPUT2: in std_logic_vector(3 downto 0);
INPUT3: in std_logic_vector(3 downto 0);
INPUT4: in std_logic_vector(3 downto 0);
SELECTION: in std_logic_vector(1 downto 0);
OUTPUT: out std_logic_vector(3 downto 0)
);
END MUX4TO1;
ARCHITECTURE Behavioral OF MUX4TO1 IS
BEGIN
OUTPUT <= INPUT1 when SELECTION = "00" else
INPUT2 when SELECTION = "01" else
INPUT3 when SELECTION = "10" else
INPUT4 when SELECTION = "11";
END Behavioral;
-------------------------------------------------------
------------------- BCD TO 7 SEGMENT ------------------
-------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY BCD7SGT IS
PORT (
INPUT: in std_logic_vector(3 downto 0);
OUTPUT: out std_logic_vector(6 downto 0)
);
END BCD7SGT;
ARCHITECTURE Behavioral OF BCD7SGT IS
BEGIN
with INPUT select OUTPUT <=
"1111110" when "0000",
"0110000" when "0001",
"1101101" when "0010",
"1111001" when "0011",
"0110011" when "0100",
"1011011" when "0101",
"1011111" when "0110",
"1110000" when "0111",
"1111111" when "1000",
"1111011" when "1001",
"1110111" when "1010",
"0011111" when "1011",
"1001110" when "1100",
"0111101" when "1101",
"1001111" when "1110",
"1000111" when "1111",
"0000000" when others;
END Behavioral;
</vhdl>
<vhdl name="Debouncer">library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Debouncer is
Port (
clk : in STD_LOGIC;
button : in STD_LOGIC;
debounced_button : out STD_LOGIC
);
end Debouncer;
architecture Behavioral of Debouncer is
signal shift_reg : STD_LOGIC_VECTOR(9 downto 0);
signal debounced_button_reg : STD_LOGIC;
begin
process (clk)
begin
if falling_edge(clk) then
shift_reg <= shift_reg(8 downto 0) & button;
if shift_reg = "1111111111" then
debounced_button_reg <= '0';
else
debounced_button_reg <= '1';
end if;
end if;
end process;
debounced_button <= debounced_button_reg;
end Behavioral;
</vhdl>
</project>