1 |
175 |
jshamlet |
-- VHDL Entity: o8_hd44780_4b
|
2 |
|
|
-- Description: Provides low-level access to a "standard" character LCD using
|
3 |
|
|
-- the ST/HD44780(U) control ASIC wired in reduced (4-bit) mode.
|
4 |
|
|
-- All low-level timing of the control signals are handled by this
|
5 |
|
|
-- module, allowing client firmware to use a simple register
|
6 |
|
|
-- interface to program the LCD panel.
|
7 |
|
|
-- Init routine initializes the display and displays a single
|
8 |
|
|
-- character to demonstrate correct function, then listens for
|
9 |
|
|
-- user data on its external interface.
|
10 |
|
|
|
11 |
|
|
library ieee;
|
12 |
|
|
use ieee.std_logic_1164.all;
|
13 |
|
|
use ieee.std_logic_unsigned.all;
|
14 |
|
|
use ieee.std_logic_arith.all;
|
15 |
|
|
|
16 |
|
|
library work;
|
17 |
|
|
use work.open8_pkg.all;
|
18 |
|
|
|
19 |
|
|
entity o8_hd44780_4b is
|
20 |
|
|
generic(
|
21 |
|
|
Use_Contrast : boolean;
|
22 |
|
|
Default_Contrast : std_logic_vector(7 downto 0);
|
23 |
|
|
Use_Backlight : boolean;
|
24 |
|
|
Default_Brightness : std_logic_vector(7 downto 0);
|
25 |
|
|
Address : ADDRESS_TYPE;
|
26 |
|
|
Reset_Level : std_logic;
|
27 |
|
|
Sys_Freq : real
|
28 |
|
|
);
|
29 |
|
|
port(
|
30 |
|
|
Clock : in std_logic;
|
31 |
|
|
Reset : in std_logic;
|
32 |
|
|
--
|
33 |
|
|
uSec_Tick : in std_logic;
|
34 |
|
|
--
|
35 |
|
|
Bus_Address : in ADDRESS_TYPE;
|
36 |
|
|
Wr_Enable : in std_logic;
|
37 |
|
|
Wr_Data : in DATA_TYPE;
|
38 |
|
|
Rd_Enable : in std_logic;
|
39 |
|
|
Rd_Data : out DATA_TYPE;
|
40 |
|
|
Interrupt : out std_logic;
|
41 |
|
|
--
|
42 |
|
|
LCD_E : out std_logic;
|
43 |
|
|
LCD_RW : out std_logic;
|
44 |
|
|
LCD_RS : out std_logic;
|
45 |
|
|
LCD_D : out std_logic_vector(7 downto 4);
|
46 |
|
|
LCD_CN : out std_logic;
|
47 |
|
|
LCD_BL : out std_logic
|
48 |
|
|
);
|
49 |
|
|
end entity;
|
50 |
|
|
|
51 |
|
|
architecture behave of o8_hd44780_4b is
|
52 |
|
|
|
53 |
|
|
constant User_Addr : std_logic_vector(15 downto 2)
|
54 |
|
|
:= Address(15 downto 2);
|
55 |
|
|
alias Comp_Addr is Bus_Address(15 downto 2);
|
56 |
|
|
signal Addr_Match : std_logic;
|
57 |
|
|
|
58 |
|
|
alias Reg_Addr is Bus_Address(1 downto 0);
|
59 |
|
|
signal Reg_Addr_q : std_logic_vector(1 downto 0);
|
60 |
|
|
|
61 |
|
|
signal Wr_En : std_logic;
|
62 |
|
|
signal Wr_Data_q : DATA_TYPE;
|
63 |
|
|
signal Rd_En : std_logic;
|
64 |
|
|
|
65 |
|
|
signal Reg_Valid : std_logic;
|
66 |
|
|
signal Reg_Sel : std_logic;
|
67 |
|
|
signal Reg_Data : std_logic_vector(7 downto 0);
|
68 |
|
|
|
69 |
|
|
signal Tx_Ready : std_logic;
|
70 |
|
|
|
71 |
|
|
--------------------------------------------------------------------------------
|
72 |
|
|
-- LCD Controller
|
73 |
|
|
--------------------------------------------------------------------------------
|
74 |
|
|
|
75 |
|
|
-- Register Map
|
76 |
|
|
-- Address Function
|
77 |
|
|
-- Offset Bitfield Description Read/Write
|
78 |
|
|
-- 0x0 AAAAAAAA LCD Register Write (Write-only)
|
79 |
|
|
-- 0x1 AAAAAAAA LCD Data Write (Write-only)
|
80 |
|
|
-- 0x2 AAAAAAAA LCD Contrast (Read-Write)
|
81 |
|
|
-- 0x3 AAAAAAAA LCD Backlight (Read-Write)
|
82 |
|
|
|
83 |
|
|
-- LCD Instruction Set
|
84 |
|
|
-- Instruction RS RW D7 D6 D5 D4 D3 D2 D1 D0 Time
|
85 |
|
|
------------------------------------------------------------------------
|
86 |
|
|
-- Clear Display | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1.52mS
|
87 |
|
|
-- Return Home | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | x | 1.52mS
|
88 |
|
|
-- Entry Mode | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ID| S | 37uS
|
89 |
|
|
-- Display Pwr | 0 | 0 | 0 | 0 | 0 | 0 | 1 | D | C | B | 37uS
|
90 |
|
|
-- Cursor/Display Shift | 0 | 0 | 0 | 0 | 0 | 1 | SC| RL| x | x | 37uS
|
91 |
|
|
-- Function Set | 0 | 0 | 0 | 0 | 1 | DL| N | F | x | x | 37uS
|
92 |
|
|
-- Set CGRAM Address | 0 | 0 | 0 | 1 | A | A | A | A | A | A | 37uS
|
93 |
|
|
-- Set DDRAM Address | 0 | 0 | 1 | A | A | A | A | A | A | A | 37uS
|
94 |
|
|
|
95 |
|
|
-- Notes:
|
96 |
|
|
-- ID = Increment/Decrement DDRAM Address (1 = increment, 0 = decrement)
|
97 |
|
|
-- S = Shift Enable (1 = Shift display according to ID, 0 = Don't shift)
|
98 |
|
|
-- D = Display On/Off (1 = on, 0 = off)
|
99 |
|
|
-- C = Cursor On/Off (1 = on, 0 = off)
|
100 |
|
|
-- B = Cursor Blink (1 = block cursor, 0 = underline cursor)
|
101 |
|
|
-- SC / RL = Shift Cursor/Display Right/Left (see data sheet - not needed for init)
|
102 |
|
|
-- F = Font (0 = 5x8, 1 = 5x11) Ignored on 2-line displays (N = 1)
|
103 |
|
|
-- N = Number of Lines (0 = 1 lines, 1 = 2 lines)
|
104 |
|
|
-- DL = Data Length (0 = 4-bit bus, 1 = 8-bit bus) This is fixed at 0 in this module
|
105 |
|
|
-- A = Address (see data sheet for usage)
|
106 |
|
|
|
107 |
|
|
constant LCD_CONFIG1 : std_logic_vector(7 downto 4) := x"3"; -- Init to 4-bit mode
|
108 |
|
|
constant LCD_CONFIG2 : std_logic_vector(7 downto 0) := x"28"; -- Set 4-bit, 2-line mode
|
109 |
|
|
constant LCD_CONFIG3 : std_logic_vector(7 downto 0) := x"0C"; -- Turn display on, no cursor
|
110 |
|
|
constant LCD_CONFIG4 : std_logic_vector(7 downto 0) := x"01"; -- Clear display
|
111 |
|
|
constant LCD_CONFIG5 : std_logic_vector(7 downto 0) := x"06"; -- Positive increment, no shift
|
112 |
|
|
constant LCD_CONFIG6 : std_logic_vector(7 downto 0) := x"2A"; -- Print a "*"
|
113 |
|
|
constant LCD_CONFIG7 : std_logic_vector(7 downto 0) := x"02"; -- Reset the cursor
|
114 |
|
|
|
115 |
|
|
signal init_count : std_logic_vector(2 downto 0);
|
116 |
|
|
|
117 |
|
|
constant INIT_40MS : integer := 40000;
|
118 |
|
|
constant INIT_BITS : integer := ceil_log2(INIT_40MS);
|
119 |
|
|
constant INIT_DELAY : std_logic_vector(INIT_BITS-1 downto 0) :=
|
120 |
|
|
conv_std_logic_vector(INIT_40MS,INIT_BITS);
|
121 |
|
|
|
122 |
|
|
-- For "long" instructions, such as clear display and return home, we need to wait for more
|
123 |
|
|
-- than 1.52mS. Experimentally, 2mS seems to work ideally, and for init this isn't an issue
|
124 |
|
|
constant CLDSP_2MS : integer := 2000;
|
125 |
|
|
constant CLDSP_DELAY : std_logic_vector(INIT_BITS-1 downto 0) :=
|
126 |
|
|
conv_std_logic_vector(CLDSP_2MS,INIT_BITS);
|
127 |
|
|
|
128 |
|
|
-- For some reason, we are required to wait 80uS before checking the busy flag, despite
|
129 |
|
|
-- most instructions completing in 37uS. No clue as to why, but it works
|
130 |
|
|
constant BUSY_50US : integer := 50;
|
131 |
|
|
constant BUSY_DELAY : std_logic_vector(INIT_BITS-1 downto 0) :=
|
132 |
|
|
conv_std_logic_vector(BUSY_50US-1, INIT_BITS);
|
133 |
|
|
|
134 |
|
|
signal busy_timer : std_logic_vector(INIT_BITS-1 downto 0);
|
135 |
|
|
|
136 |
|
|
constant SNH_600NS : integer := integer(Sys_Freq * 0.000000600);
|
137 |
|
|
constant SNH_BITS : integer := ceil_log2(SNH_600NS);
|
138 |
|
|
constant SNH_DELAY : std_logic_vector(SNH_BITS-1 downto 0) :=
|
139 |
|
|
conv_std_logic_vector(SNH_600NS-1, SNH_BITS);
|
140 |
|
|
|
141 |
|
|
signal io_timer : std_logic_vector(SNH_BITS - 1 downto 0);
|
142 |
|
|
|
143 |
|
|
type IO_STATES is (INIT, PWR_WAIT, INIT_S1, INIT_H1,
|
144 |
|
|
INIT_WAIT, FN_JUMP, IDLE,
|
145 |
|
|
WR_PREP, WR_SETUP_UB, WR_HOLD_UB, WR_SETUP_LB, WR_HOLD_LB,
|
146 |
|
|
BUSY_PREP, BUSY_WAIT,
|
147 |
|
|
ISSUE_INT );
|
148 |
|
|
|
149 |
|
|
signal io_state : IO_STATES;
|
150 |
|
|
|
151 |
|
|
signal LCD_Data : std_logic_vector(7 downto 0);
|
152 |
|
|
signal LCD_Addr : std_logic;
|
153 |
|
|
|
154 |
|
|
--------------------------------------------------------------------------------
|
155 |
|
|
-- Backlight signals
|
156 |
|
|
--------------------------------------------------------------------------------
|
157 |
|
|
|
158 |
|
|
-- Do not adjust alone! DELTA constants must be
|
159 |
|
|
-- changed as well.
|
160 |
|
|
constant DAC_Width : integer := 8;
|
161 |
|
|
|
162 |
|
|
constant DELTA_1_I : integer := 1;
|
163 |
|
|
constant DELTA_2_I : integer := 5;
|
164 |
|
|
constant DELTA_3_I : integer := 25;
|
165 |
|
|
constant DELTA_4_I : integer := 75;
|
166 |
|
|
constant DELTA_5_I : integer := 125;
|
167 |
|
|
constant DELTA_6_I : integer := 195;
|
168 |
|
|
|
169 |
|
|
constant DELTA_1 : std_logic_vector(DAC_Width-1 downto 0) :=
|
170 |
|
|
conv_std_logic_vector(DELTA_1_I, DAC_Width);
|
171 |
|
|
constant DELTA_2 : std_logic_vector(DAC_Width-1 downto 0) :=
|
172 |
|
|
conv_std_logic_vector(DELTA_2_I, DAC_Width);
|
173 |
|
|
constant DELTA_3 : std_logic_vector(DAC_Width-1 downto 0) :=
|
174 |
|
|
conv_std_logic_vector(DELTA_3_I, DAC_Width);
|
175 |
|
|
constant DELTA_4 : std_logic_vector(DAC_Width-1 downto 0) :=
|
176 |
|
|
conv_std_logic_vector(DELTA_4_I, DAC_Width);
|
177 |
|
|
constant DELTA_5 : std_logic_vector(DAC_Width-1 downto 0) :=
|
178 |
|
|
conv_std_logic_vector(DELTA_5_I, DAC_Width);
|
179 |
|
|
constant DELTA_6 : std_logic_vector(DAC_Width-1 downto 0) :=
|
180 |
|
|
conv_std_logic_vector(DELTA_6_I, DAC_Width);
|
181 |
|
|
|
182 |
|
|
constant MAX_PERIOD : integer := 2**DAC_Width;
|
183 |
|
|
constant DIV_WIDTH : integer := DAC_Width * 2;
|
184 |
|
|
|
185 |
|
|
constant PADJ_1_I : integer := DELTA_1_I * MAX_PERIOD;
|
186 |
|
|
constant PADJ_2_I : integer := DELTA_2_I * MAX_PERIOD;
|
187 |
|
|
constant PADJ_3_I : integer := DELTA_3_I * MAX_PERIOD;
|
188 |
|
|
constant PADJ_4_I : integer := DELTA_4_I * MAX_PERIOD;
|
189 |
|
|
constant PADJ_5_I : integer := DELTA_5_I * MAX_PERIOD;
|
190 |
|
|
constant PADJ_6_I : integer := DELTA_6_I * MAX_PERIOD;
|
191 |
|
|
|
192 |
|
|
constant PADJ_1 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
193 |
|
|
conv_std_logic_vector(PADJ_1_I,DIV_WIDTH);
|
194 |
|
|
constant PADJ_2 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
195 |
|
|
conv_std_logic_vector(PADJ_2_I,DIV_WIDTH);
|
196 |
|
|
constant PADJ_3 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
197 |
|
|
conv_std_logic_vector(PADJ_3_I,DIV_WIDTH);
|
198 |
|
|
constant PADJ_4 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
199 |
|
|
conv_std_logic_vector(PADJ_4_I,DIV_WIDTH);
|
200 |
|
|
constant PADJ_5 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
201 |
|
|
conv_std_logic_vector(PADJ_5_I,DIV_WIDTH);
|
202 |
|
|
constant PADJ_6 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
203 |
|
|
conv_std_logic_vector(PADJ_6_I,DIV_WIDTH);
|
204 |
|
|
|
205 |
|
|
constant CB : integer := ceil_log2(DIV_WIDTH);
|
206 |
|
|
|
207 |
|
|
signal LCD_Contrast : std_logic_vector(7 downto 0);
|
208 |
|
|
|
209 |
|
|
signal CN_DACin : std_logic_vector(DAC_WIDTH-1 downto 0);
|
210 |
|
|
|
211 |
|
|
signal CN_Divisor : std_logic_vector(DIV_WIDTH-1 downto 0);
|
212 |
|
|
signal CN_Dividend : std_logic_vector(DIV_WIDTH-1 downto 0);
|
213 |
|
|
|
214 |
|
|
signal CN_q : std_logic_vector(DIV_WIDTH*2-1 downto 0);
|
215 |
|
|
signal CN_diff : std_logic_vector(DIV_WIDTH downto 0);
|
216 |
|
|
|
217 |
|
|
signal CN_count : std_logic_vector(CB-1 downto 0);
|
218 |
|
|
|
219 |
|
|
signal CN_Next_Wdt : std_logic_vector(DAC_Width-1 downto 0);
|
220 |
|
|
signal CN_Next_Per : std_logic_vector(DAC_Width-1 downto 0);
|
221 |
|
|
|
222 |
|
|
signal CN_PWM_Wdt : std_logic_vector(DAC_Width-1 downto 0);
|
223 |
|
|
signal CN_PWM_Per : std_logic_vector(DAC_Width-1 downto 0);
|
224 |
|
|
|
225 |
|
|
signal CN_Wdt_Ctr : std_logic_vector(DAC_Width-1 downto 0);
|
226 |
|
|
signal CN_Per_Ctr : std_logic_vector(DAC_Width-1 downto 0);
|
227 |
|
|
|
228 |
|
|
signal LCD_Bright : std_logic_vector(7 downto 0);
|
229 |
|
|
|
230 |
|
|
signal BL_DACin : std_logic_vector(DAC_WIDTH-1 downto 0);
|
231 |
|
|
|
232 |
|
|
signal BL_Divisor : std_logic_vector(DIV_WIDTH-1 downto 0);
|
233 |
|
|
signal BL_Dividend : std_logic_vector(DIV_WIDTH-1 downto 0);
|
234 |
|
|
|
235 |
|
|
signal BL_q : std_logic_vector(DIV_WIDTH*2-1 downto 0);
|
236 |
|
|
signal BL_diff : std_logic_vector(DIV_WIDTH downto 0);
|
237 |
|
|
|
238 |
|
|
signal BL_count : std_logic_vector(CB-1 downto 0);
|
239 |
|
|
|
240 |
|
|
signal BL_Next_Wdt : std_logic_vector(DAC_Width-1 downto 0);
|
241 |
|
|
signal BL_Next_Per : std_logic_vector(DAC_Width-1 downto 0);
|
242 |
|
|
|
243 |
|
|
signal BL_PWM_Wdt : std_logic_vector(DAC_Width-1 downto 0);
|
244 |
|
|
signal BL_PWM_Per : std_logic_vector(DAC_Width-1 downto 0);
|
245 |
|
|
|
246 |
|
|
signal BL_Wdt_Ctr : std_logic_vector(DAC_Width-1 downto 0);
|
247 |
|
|
signal BL_Per_Ctr : std_logic_vector(DAC_Width-1 downto 0);
|
248 |
|
|
begin
|
249 |
|
|
|
250 |
|
|
--------------------------------------------------------------------------------
|
251 |
|
|
-- Open8 Register interface
|
252 |
|
|
--------------------------------------------------------------------------------
|
253 |
|
|
|
254 |
|
|
Addr_Match <= '1' when Comp_Addr = User_Addr else '0';
|
255 |
|
|
|
256 |
|
|
io_reg: process( Clock, Reset )
|
257 |
|
|
begin
|
258 |
|
|
if( Reset = Reset_Level )then
|
259 |
|
|
Reg_Addr_q <= (others => '0');
|
260 |
|
|
Wr_Data_q <= (others => '0');
|
261 |
|
|
Wr_En <= '0';
|
262 |
|
|
Rd_En <= '0';
|
263 |
|
|
Rd_Data <= (others => '0');
|
264 |
|
|
|
265 |
|
|
Reg_Valid <= '0';
|
266 |
|
|
Reg_Sel <= '0';
|
267 |
|
|
Reg_Data <= x"00";
|
268 |
|
|
|
269 |
|
|
LCD_Contrast <= Default_Contrast;
|
270 |
|
|
LCD_Bright <= Default_Brightness;
|
271 |
|
|
elsif( rising_edge( Clock ) )then
|
272 |
|
|
Reg_Addr_q <= Reg_Addr;
|
273 |
|
|
|
274 |
|
|
Wr_Data_q <= Wr_Data;
|
275 |
|
|
Wr_En <= Addr_Match and Wr_Enable;
|
276 |
|
|
|
277 |
|
|
Reg_Valid <= '0';
|
278 |
|
|
|
279 |
|
|
if( Wr_En = '1' )then
|
280 |
|
|
case( Reg_Addr_q )is
|
281 |
|
|
when "00" | "01" =>
|
282 |
|
|
Reg_Valid <= '1';
|
283 |
|
|
Reg_Sel <= Reg_Addr_q(0);
|
284 |
|
|
Reg_Data <= Wr_Data_q;
|
285 |
|
|
when "10" =>
|
286 |
|
|
LCD_Contrast<= Wr_Data_q;
|
287 |
|
|
when "11" =>
|
288 |
|
|
LCD_Bright <= Wr_Data_q;
|
289 |
|
|
when others => null;
|
290 |
|
|
end case;
|
291 |
|
|
end if;
|
292 |
|
|
|
293 |
|
|
Rd_Data <= (others => '0');
|
294 |
|
|
Rd_En <= Addr_Match and Rd_Enable;
|
295 |
|
|
if( Rd_En = '1' )then
|
296 |
|
|
case( Reg_Addr_q )is
|
297 |
|
|
when "00" | "01" =>
|
298 |
|
|
Rd_Data(7) <= Tx_Ready;
|
299 |
|
|
when "10" =>
|
300 |
|
|
Rd_Data <= LCD_Contrast;
|
301 |
|
|
when "11" =>
|
302 |
|
|
Rd_Data <= LCD_Bright;
|
303 |
|
|
when others => null;
|
304 |
|
|
end case;
|
305 |
|
|
end if;
|
306 |
|
|
end if;
|
307 |
|
|
end process;
|
308 |
|
|
|
309 |
|
|
--------------------------------------------------------------------------------
|
310 |
|
|
-- LCD and Register logic
|
311 |
|
|
--------------------------------------------------------------------------------
|
312 |
|
|
|
313 |
|
|
LCD_RW <= '0'; -- Permanently wire the RW line low
|
314 |
|
|
|
315 |
|
|
LCD_IO: process( Clock, Reset )
|
316 |
|
|
begin
|
317 |
|
|
if( Reset = Reset_Level )then
|
318 |
|
|
io_state <= INIT;
|
319 |
|
|
init_count <= (others => '0');
|
320 |
|
|
io_timer <= (others => '0');
|
321 |
|
|
busy_timer <= (others => '0');
|
322 |
|
|
LCD_Data <= (others => '0');
|
323 |
|
|
LCD_Addr <= '0';
|
324 |
|
|
LCD_E <= '0';
|
325 |
|
|
LCD_RS <= '0';
|
326 |
|
|
LCD_D <= (others => '0');
|
327 |
|
|
Tx_Ready <= '0';
|
328 |
|
|
Interrupt <= '0';
|
329 |
|
|
elsif( rising_edge(Clock) )then
|
330 |
|
|
LCD_E <= '0';
|
331 |
|
|
LCD_RS <= '0';
|
332 |
|
|
LCD_D <= (others => '0');
|
333 |
|
|
Tx_Ready <= '0';
|
334 |
|
|
Interrupt <= '0';
|
335 |
|
|
io_timer <= io_timer - 1;
|
336 |
|
|
busy_timer <= busy_timer - uSec_Tick;
|
337 |
|
|
case( io_state )is
|
338 |
|
|
|
339 |
|
|
when INIT =>
|
340 |
|
|
busy_timer <= INIT_DELAY;
|
341 |
|
|
init_count <= (others => '1');
|
342 |
|
|
io_state <= PWR_WAIT;
|
343 |
|
|
|
344 |
|
|
-- We wait for at least 40mS before continuing initalization.
|
345 |
|
|
when PWR_WAIT =>
|
346 |
|
|
if( busy_timer = 0 )then
|
347 |
|
|
io_timer <= SNH_DELAY;
|
348 |
|
|
io_state <= INIT_S1;
|
349 |
|
|
end if;
|
350 |
|
|
|
351 |
|
|
-- We write out the first init byte as if we were using an 8-bit
|
352 |
|
|
-- data bus, with a single cycle. This is an exception, and the
|
353 |
|
|
-- rest of the commands are sent using 2-cycle transfers.
|
354 |
|
|
when INIT_S1 =>
|
355 |
|
|
LCD_D <= LCD_CONFIG1;
|
356 |
|
|
LCD_E <= '1';
|
357 |
|
|
if( io_timer = 0 )then
|
358 |
|
|
io_timer <= SNH_DELAY;
|
359 |
|
|
io_state <= INIT_H1;
|
360 |
|
|
end if;
|
361 |
|
|
|
362 |
|
|
when INIT_H1 =>
|
363 |
|
|
LCD_D <= LCD_CONFIG1;
|
364 |
|
|
if( io_timer = 0 )then
|
365 |
|
|
busy_timer <= BUSY_DELAY;
|
366 |
|
|
io_state <= INIT_WAIT;
|
367 |
|
|
end if;
|
368 |
|
|
|
369 |
|
|
when INIT_WAIT =>
|
370 |
|
|
if( busy_timer = 0 )then
|
371 |
|
|
io_state <= FN_JUMP;
|
372 |
|
|
end if;
|
373 |
|
|
|
374 |
|
|
when FN_JUMP =>
|
375 |
|
|
io_state <= WR_PREP;
|
376 |
|
|
case( init_count )is
|
377 |
|
|
when "000" =>
|
378 |
|
|
io_state <= IDLE;
|
379 |
|
|
when "001" =>
|
380 |
|
|
LCD_Addr <= '0';
|
381 |
|
|
LCD_Data <= LCD_CONFIG7; -- Reset the Cursor
|
382 |
|
|
when "010" =>
|
383 |
|
|
LCD_Addr <= '1'; -- Print a "*", and
|
384 |
|
|
LCD_Data <= LCD_CONFIG6; -- set RS to 1
|
385 |
|
|
when "011" =>
|
386 |
|
|
LCD_Data <= LCD_CONFIG5; -- Entry mode
|
387 |
|
|
when "100" =>
|
388 |
|
|
LCD_Data <= LCD_CONFIG4; -- Clear Display
|
389 |
|
|
when "101" =>
|
390 |
|
|
LCD_Data <= LCD_CONFIG3; -- Display control
|
391 |
|
|
when "110" | "111" =>
|
392 |
|
|
LCD_Addr <= '0';
|
393 |
|
|
LCD_Data <= LCD_CONFIG2; -- Function set
|
394 |
|
|
when others => null;
|
395 |
|
|
end case;
|
396 |
|
|
|
397 |
|
|
when IDLE =>
|
398 |
|
|
Tx_Ready <= '1';
|
399 |
|
|
if( Reg_Valid = '1' )then
|
400 |
|
|
LCD_Addr <= Reg_Sel;
|
401 |
|
|
LCD_Data <= Reg_Data;
|
402 |
|
|
io_state <= WR_PREP;
|
403 |
|
|
end if;
|
404 |
|
|
|
405 |
|
|
when WR_PREP =>
|
406 |
|
|
io_timer <= SNH_DELAY;
|
407 |
|
|
io_state <= WR_SETUP_UB;
|
408 |
|
|
|
409 |
|
|
when WR_SETUP_UB =>
|
410 |
|
|
LCD_RS <= LCD_Addr;
|
411 |
|
|
LCD_D <= LCD_Data(7 downto 4);
|
412 |
|
|
LCD_E <= '1';
|
413 |
|
|
if( io_timer = 0 )then
|
414 |
|
|
io_timer <= SNH_DELAY;
|
415 |
|
|
io_state <= WR_HOLD_UB;
|
416 |
|
|
end if;
|
417 |
|
|
|
418 |
|
|
when WR_HOLD_UB =>
|
419 |
|
|
LCD_RS <= LCD_Addr;
|
420 |
|
|
LCD_D <= LCD_Data(7 downto 4);
|
421 |
|
|
if( io_timer = 0 )then
|
422 |
|
|
LCD_E <= '0';
|
423 |
|
|
io_timer <= SNH_DELAY;
|
424 |
|
|
io_state <= WR_SETUP_LB;
|
425 |
|
|
end if;
|
426 |
|
|
|
427 |
|
|
when WR_SETUP_LB =>
|
428 |
|
|
LCD_RS <= LCD_Addr;
|
429 |
|
|
LCD_D <= LCD_Data(3 downto 0);
|
430 |
|
|
LCD_E <= '1';
|
431 |
|
|
if( io_timer = 0 )then
|
432 |
|
|
io_timer <= SNH_DELAY;
|
433 |
|
|
io_state <= WR_HOLD_LB;
|
434 |
|
|
end if;
|
435 |
|
|
|
436 |
|
|
when WR_HOLD_LB =>
|
437 |
|
|
LCD_RS <= LCD_Addr;
|
438 |
|
|
LCD_D <= LCD_Data(3 downto 0);
|
439 |
|
|
if( io_timer = 0 )then
|
440 |
|
|
io_state <= BUSY_WAIT;
|
441 |
|
|
end if;
|
442 |
|
|
|
443 |
|
|
when BUSY_PREP =>
|
444 |
|
|
busy_timer <= BUSY_DELAY;
|
445 |
|
|
if( LCD_Addr = '0' and LCD_Data < 4 )then
|
446 |
|
|
busy_timer <= CLDSP_DELAY;
|
447 |
|
|
end if;
|
448 |
|
|
io_state <= BUSY_WAIT;
|
449 |
|
|
|
450 |
|
|
when BUSY_WAIT =>
|
451 |
|
|
if( busy_timer = 0 )then
|
452 |
|
|
io_state <= ISSUE_INT;
|
453 |
|
|
if( init_count > 0 )then
|
454 |
|
|
init_count<= init_count - 1;
|
455 |
|
|
io_state <= FN_JUMP;
|
456 |
|
|
end if;
|
457 |
|
|
end if;
|
458 |
|
|
|
459 |
|
|
when ISSUE_INT =>
|
460 |
|
|
Interrupt <= '1';
|
461 |
|
|
io_state <= IDLE;
|
462 |
|
|
|
463 |
|
|
when others => null;
|
464 |
|
|
|
465 |
|
|
end case;
|
466 |
|
|
|
467 |
|
|
end if;
|
468 |
|
|
end process;
|
469 |
|
|
|
470 |
|
|
--------------------------------------------------------------------------------
|
471 |
|
|
-- Contrast control logic (optional)
|
472 |
|
|
--------------------------------------------------------------------------------
|
473 |
|
|
|
474 |
|
|
Contrast_Disabled: if( not Use_Contrast )generate
|
475 |
|
|
LCD_CN <= '0';
|
476 |
|
|
end generate;
|
477 |
|
|
|
478 |
|
|
Contrast_Enabled: if( Use_Contrast )generate
|
479 |
|
|
|
480 |
|
|
CN_diff <= ('0' & CN_q(DIV_WIDTH*2-2 downto DIV_WIDTH-1)) -
|
481 |
|
|
('0' & CN_Divisor);
|
482 |
|
|
|
483 |
|
|
CN_Dividend<= PADJ_2 when CN_DACin >= DELTA_2_I and CN_DACin < DELTA_3_I else
|
484 |
|
|
PADJ_3 when CN_DACin >= DELTA_3_I and CN_DACin < DELTA_4_I else
|
485 |
|
|
PADJ_4 when CN_DACin >= DELTA_4_I and CN_DACin < DELTA_5_I else
|
486 |
|
|
PADJ_5 when CN_DACin >= DELTA_5_I and CN_DACin < DELTA_6_I else
|
487 |
|
|
PADJ_6 when CN_DACin >= DELTA_6_I else
|
488 |
|
|
PADJ_1;
|
489 |
|
|
|
490 |
|
|
CN_Next_Wdt<= DELTA_1 when CN_DACin >= DELTA_1_I and CN_DACin < DELTA_2_I else
|
491 |
|
|
DELTA_2 when CN_DACin >= DELTA_2_I and CN_DACin < DELTA_3_I else
|
492 |
|
|
DELTA_3 when CN_DACin >= DELTA_3_I and CN_DACin < DELTA_4_I else
|
493 |
|
|
DELTA_4 when CN_DACin >= DELTA_4_I and CN_DACin < DELTA_5_I else
|
494 |
|
|
DELTA_5 when CN_DACin >= DELTA_5_I and CN_DACin < DELTA_6_I else
|
495 |
|
|
DELTA_6 when CN_DACin >= DELTA_6_I else
|
496 |
|
|
(others => '0');
|
497 |
|
|
|
498 |
|
|
CN_Next_Per <= BL_q(7 downto 0) - 1;
|
499 |
|
|
|
500 |
|
|
CN_vDSM_proc: process( Clock, Reset )
|
501 |
|
|
begin
|
502 |
|
|
if( Reset = Reset_Level )then
|
503 |
|
|
CN_q <= (others => '0');
|
504 |
|
|
CN_count <= (others => '1');
|
505 |
|
|
CN_Divisor <= (others => '0');
|
506 |
|
|
CN_DACin <= (others => '0');
|
507 |
|
|
CN_PWM_Wdt <= (others => '0');
|
508 |
|
|
CN_PWM_Per <= (others => '0');
|
509 |
|
|
CN_Per_Ctr <= (others => '0');
|
510 |
|
|
CN_Wdt_Ctr <= (others => '0');
|
511 |
|
|
LCD_CN <= '0';
|
512 |
|
|
elsif( rising_edge(Clock) )then
|
513 |
|
|
CN_q <= CN_diff(DIV_WIDTH-1 downto 0) &
|
514 |
|
|
CN_q(DIV_WIDTH-2 downto 0) & '1';
|
515 |
|
|
if( CN_diff(DIV_WIDTH) = '1' )then
|
516 |
|
|
CN_q <= CN_q(DIV_WIDTH*2-2 downto 0) & '0';
|
517 |
|
|
end if;
|
518 |
|
|
|
519 |
|
|
CN_count <= CN_count + 1;
|
520 |
|
|
if( CN_count = DIV_WIDTH )then
|
521 |
|
|
CN_PWM_Wdt <= CN_Next_Wdt;
|
522 |
|
|
CN_PWM_Per <= CN_Next_Per;
|
523 |
|
|
CN_DACin <= LCD_Contrast;
|
524 |
|
|
CN_Divisor <= (others => '0');
|
525 |
|
|
CN_Divisor(DAC_Width-1 downto 0) <= CN_DACin;
|
526 |
|
|
CN_q <= conv_std_logic_vector(0,DIV_WIDTH) & CN_Dividend;
|
527 |
|
|
CN_count <= (others => '0');
|
528 |
|
|
end if;
|
529 |
|
|
|
530 |
|
|
CN_Per_Ctr <= CN_Per_Ctr - 1;
|
531 |
|
|
CN_Wdt_Ctr <= CN_Wdt_Ctr - 1;
|
532 |
|
|
|
533 |
|
|
LCD_CN <= '1';
|
534 |
|
|
if( CN_Wdt_Ctr = 0 )then
|
535 |
|
|
LCD_CN <= '0';
|
536 |
|
|
CN_Wdt_Ctr <= (others => '0');
|
537 |
|
|
end if;
|
538 |
|
|
|
539 |
|
|
if( CN_Per_Ctr = 0 )then
|
540 |
|
|
CN_Per_Ctr <= CN_PWM_Per;
|
541 |
|
|
CN_Wdt_Ctr <= CN_PWM_Wdt;
|
542 |
|
|
end if;
|
543 |
|
|
|
544 |
|
|
end if;
|
545 |
|
|
end process;
|
546 |
|
|
end generate;
|
547 |
|
|
|
548 |
|
|
--------------------------------------------------------------------------------
|
549 |
|
|
-- Backlight control logic (optional)
|
550 |
|
|
--------------------------------------------------------------------------------
|
551 |
|
|
|
552 |
|
|
Backlight_Disabled: if( not Use_Backlight )generate
|
553 |
|
|
LCD_BL <= '0';
|
554 |
|
|
end generate;
|
555 |
|
|
|
556 |
|
|
Backlight_Enabled: if( Use_Backlight )generate
|
557 |
|
|
|
558 |
|
|
BL_diff <= ('0' & BL_q(DIV_WIDTH*2-2 downto DIV_WIDTH-1)) -
|
559 |
|
|
('0' & BL_Divisor);
|
560 |
|
|
|
561 |
|
|
BL_Dividend<= PADJ_2 when BL_DACin >= DELTA_2_I and BL_DACin < DELTA_3_I else
|
562 |
|
|
PADJ_3 when BL_DACin >= DELTA_3_I and BL_DACin < DELTA_4_I else
|
563 |
|
|
PADJ_4 when BL_DACin >= DELTA_4_I and BL_DACin < DELTA_5_I else
|
564 |
|
|
PADJ_5 when BL_DACin >= DELTA_5_I and BL_DACin < DELTA_6_I else
|
565 |
|
|
PADJ_6 when BL_DACin >= DELTA_6_I else
|
566 |
|
|
PADJ_1;
|
567 |
|
|
|
568 |
|
|
BL_Next_Wdt<= DELTA_1 when BL_DACin >= DELTA_1_I and BL_DACin < DELTA_2_I else
|
569 |
|
|
DELTA_2 when BL_DACin >= DELTA_2_I and BL_DACin < DELTA_3_I else
|
570 |
|
|
DELTA_3 when BL_DACin >= DELTA_3_I and BL_DACin < DELTA_4_I else
|
571 |
|
|
DELTA_4 when BL_DACin >= DELTA_4_I and BL_DACin < DELTA_5_I else
|
572 |
|
|
DELTA_5 when BL_DACin >= DELTA_5_I and BL_DACin < DELTA_6_I else
|
573 |
|
|
DELTA_6 when BL_DACin >= DELTA_6_I else
|
574 |
|
|
(others => '0');
|
575 |
|
|
|
576 |
|
|
BL_Next_Per <= BL_q(7 downto 0) - 1;
|
577 |
|
|
|
578 |
|
|
BL_vDSM_proc: process( Clock, Reset )
|
579 |
|
|
begin
|
580 |
|
|
if( Reset = Reset_Level )then
|
581 |
|
|
BL_q <= (others => '0');
|
582 |
|
|
BL_count <= (others => '1');
|
583 |
|
|
BL_Divisor <= (others => '0');
|
584 |
|
|
BL_DACin <= (others => '0');
|
585 |
|
|
BL_PWM_Wdt <= (others => '0');
|
586 |
|
|
BL_PWM_Per <= (others => '0');
|
587 |
|
|
BL_Per_Ctr <= (others => '0');
|
588 |
|
|
BL_Wdt_Ctr <= (others => '0');
|
589 |
|
|
LCD_BL <= '0';
|
590 |
|
|
elsif( rising_edge(Clock) )then
|
591 |
|
|
BL_q <= BL_diff(DIV_WIDTH-1 downto 0) &
|
592 |
|
|
BL_q(DIV_WIDTH-2 downto 0) & '1';
|
593 |
|
|
if( BL_diff(DIV_WIDTH) = '1' )then
|
594 |
|
|
BL_q <= BL_q(DIV_WIDTH*2-2 downto 0) & '0';
|
595 |
|
|
end if;
|
596 |
|
|
|
597 |
|
|
BL_count <= BL_count + 1;
|
598 |
|
|
if( BL_count = DIV_WIDTH )then
|
599 |
|
|
BL_PWM_Wdt <= BL_Next_Wdt;
|
600 |
|
|
BL_PWM_Per <= BL_Next_Per;
|
601 |
|
|
BL_DACin <= LCD_Bright;
|
602 |
|
|
BL_Divisor <= (others => '0');
|
603 |
|
|
BL_Divisor(DAC_Width-1 downto 0) <= BL_DACin;
|
604 |
|
|
BL_q <= conv_std_logic_vector(0,DIV_WIDTH) & BL_Dividend;
|
605 |
|
|
BL_count <= (others => '0');
|
606 |
|
|
end if;
|
607 |
|
|
|
608 |
|
|
BL_Per_Ctr <= BL_Per_Ctr - 1;
|
609 |
|
|
BL_Wdt_Ctr <= BL_Wdt_Ctr - 1;
|
610 |
|
|
|
611 |
|
|
LCD_BL <= '1';
|
612 |
|
|
if( BL_Wdt_Ctr = 0 )then
|
613 |
|
|
LCD_BL <= '0';
|
614 |
|
|
BL_Wdt_Ctr <= (others => '0');
|
615 |
|
|
end if;
|
616 |
|
|
|
617 |
|
|
if( BL_Per_Ctr = 0 )then
|
618 |
|
|
BL_Per_Ctr <= BL_PWM_Per;
|
619 |
|
|
BL_Wdt_Ctr <= BL_PWM_Wdt;
|
620 |
|
|
end if;
|
621 |
|
|
|
622 |
|
|
end if;
|
623 |
|
|
end process;
|
624 |
|
|
|
625 |
|
|
end generate;
|
626 |
|
|
|
627 |
|
|
end architecture;
|