-
Notifications
You must be signed in to change notification settings - Fork 3
/
Serial_TTL_Display.vhd
127 lines (107 loc) · 3.13 KB
/
Serial_TTL_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
119
120
121
122
123
124
125
126
127
----------------------------------------------------------------------------------
--Code by: Zachary Rauen
--Date: 10/28/14
--Last Modified: 11/2/14
--
--Description: This takes in 16 bit data and displays them on an external display
-- using GPIO and serial ttl communication.
--
--Version: 1.3
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Serial_TTL_display is
Generic (BaudSpeed : integer :=9600;
Boardspeed : integer :=100000000);
Port ( Clock : in STD_LOGIC;
Data : in STD_LOGIC_VECTOR (15 downto 0);
RX : out STD_LOGIC);
end Serial_TTL_display;
architecture Behavioral of Serial_TTL_display is
signal DataSection : std_logic_vector(7 downto 0);
type state_type is (bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7,bit8,bit9);
signal nextState : state_type;
signal currentState : state_type := bit0;
signal bitEnableCnt,ByteChoice : integer:=0;
signal ByteMax : integer :=8;
signal BitEnable : std_logic :='0';
signal BaudClockEnableMax : integer := Boardspeed/BaudSpeed-1;
begin
BitEnabler: process(Clock)
begin
if rising_edge(Clock) then
if bitEnableCnt = BaudClockEnableMax then
BitEnable <= '1';
bitEnableCnt <= 0;
else
bitEnableCnt<=bitEnableCnt+1;
BitEnable <= '0';
end if;
end if;
end process BitEnabler;
StateChange: process (Clock,BitEnable)
begin
if (rising_edge(Clock) and BitEnable='1') then
if currentState = bit9 then
if ByteChoice = ByteMax then
ByteChoice <= Bytechoice-3;
else
ByteChoice<=ByteChoice+1;
end if;
end if;
currentState <= nextState;
end if;
end process StateChange;
States: process(currentState)
begin
case currentState is
when bit0=>
RX<='0';
nextState<=bit1;
when bit1=>
RX<=DataSection(0);
nextState<=bit2;
when bit2=>
RX<=DataSection(1);
nextState<=bit3;
when bit3=>
RX<=DataSection(2);
nextState<=bit4;
when bit4=>
RX<=DataSection(3);
nextState<=bit5;
when bit5=>
RX<=DataSection(4);
nextState<=bit6;
when bit6=>
RX<=DataSection(5);
nextState<=bit7;
when bit7=>
RX<=DataSection(6);
nextState<=bit8;
when bit8=>
RX<=DataSection(7);
nextState<=bit9;
when bit9=>
RX<='1';
nextState<=bit0;
end case;
case ByteChoice is
when 0 => DataSection<=x"76";
when 1 => DataSection<=x"76";
when 2 => DataSection<=x"76";
when 3 => DataSection<=x"76";
when 4 => DataSection<=x"76";
-- when 5 => DataSection<=x"7A";
-- when 6 => DataSection<=std_logic_vector(to_unsigned(0, 8));
-- when 6 => DataSection<=x"79";
-- when 7 => DataSection<=std_logic_vector(to_unsigned(0, 8));
when 5 => DataSection <=x"0" & Data(15 downto 12);
when 6 => DataSection <=x"0" & Data(11 downto 8);
when 7 => DataSection <=x"0" & Data(7 downto 4);
when 8 => DataSection <=x"0" & Data(3 downto 0);
when others => DataSection <="11111111";
end case;
end process States;
end Behavioral;