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