-
Notifications
You must be signed in to change notification settings - Fork 3
/
SPI_display.vhd
189 lines (175 loc) · 4.49 KB
/
SPI_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
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
----------------------------------------------------------------------------------
--Code by: Zachary Rauen
--Date: 10/30/14
--Last Modified: 11/2/14
--
--Description: This takes in 16 bit data and displays them on an external display
-- using GPIO and SPI communication.
--
--Version: 1.1
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity SPI_display is
Generic (constant BoardClockSpeed : integer := 100000000;
constant SCKSpeed : integer := 250000);
Port ( BoardClock : in STD_LOGIC;
Data : in STD_LOGIC_VECTOR (15 downto 0);
SCK : out STD_LOGIC;
SS : out STD_LOGIC;
MOSI : out STD_LOGIC
);
end SPI_display;
architecture Behavioral of SPI_display is
signal clkMax : integer := (BoardClockSpeed/SCKSpeed)-1;
signal clkCnt : integer := 0;
signal StateClock : std_logic :='0';
type state_type is (state0,state1,state2,state3,state4,state5,state6,state7,state8,state9,
state10,state11,state12,state13,state14,state15,state16,state17,state18);
signal currentState : state_type :=state0;
signal nextState : state_type;
signal dataSection : std_logic_vector(7 downto 0);
signal byteChoice: integer :=0;
signal byteMax: integer :=8;
begin
ClkEnable : process(BoardClock)
begin
if rising_edge(BoardClock) then
if clkCnt = clkMax then
StateClock <= '1';
clkCnt <= 0;
else
clkCnt<=clkCnt+1;
StateClock <= '0';
end if;
end if;
end process ClkEnable;
StateChange: process (BoardClock,StateClock)
begin
if (rising_edge(BoardClock) and StateClock='1') then
if currentState = state18 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 state0=>
SCK<='0';
SS<='1';
MOSI<='Z';
nextState<=state1;
when state1=>
SCK<='0';
SS<='0';
MOSI<=dataSection(7);
nextState<=state2;
when state2=>
SCK<='1';
SS<='0';
MOSI<=dataSection(7);
nextState<=state3;
when state3=>
SCK<='0';
SS<='0';
MOSI<=dataSection(6);
nextState<=state4;
when state4=>
SCK<='1';
SS<='0';
MOSI<=dataSection(6);
nextState<=state5;
when state5=>
SCK<='0';
SS<='0';
MOSI<=dataSection(5);
nextState<=state6;
when state6=>
SCK<='1';
SS<='0';
MOSI<=dataSection(5);
nextState<=state7;
when state7=>
SCK<='0';
SS<='0';
MOSI<=dataSection(4);
nextState<=state8;
when state8=>
SCK<='1';
SS<='0';
MOSI<=dataSection(4);
nextState<=state9;
when state9=>
SCK<='0';
SS<='0';
MOSI<=dataSection(3);
nextState<=state10;
when state10=>
SCK<='1';
SS<='0';
MOSI<=dataSection(3);
nextState<=state11;
when state11=>
SCK<='0';
SS<='0';
MOSI<=dataSection(2);
nextState<=state12;
when state12=>
SCK<='1';
SS<='0';
MOSI<=dataSection(2);
nextState<=state13;
when state13=>
SCK<='0';
SS<='0';
MOSI<=dataSection(1);
nextState<=state14;
when state14=>
SCK<='1';
SS<='0';
MOSI<=dataSection(1);
nextState<=state15;
when state15=>
SCK<='0';
SS<='0';
MOSI<=dataSection(0);
nextState<=state16;
when state16=>
SCK<='1';
SS<='0';
MOSI<=dataSection(0);
nextState<=state17;
when state17=>
SCK<='0';
SS<='0';
MOSI<=datasection(0);
nextState<=state18;
when state18=>
SCK<='0';
SS<='1';
MOSI<='Z';
nextState<=state1;
end case;
end process States;
ByteSelection: process(byteChoice)
begin
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"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 ByteSelection;
end Behavioral;