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 |
213 |
jshamlet |
-- (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 |
194 |
jshamlet |
--
|
24 |
175 |
jshamlet |
-- VHDL Entity: o8_hd44780_8b
|
25 |
|
|
-- Description: Provides low-level access to a "standard" character LCD using
|
26 |
|
|
-- the ST/HD44780(U) control ASIC wired in full (8-bit) mode.
|
27 |
213 |
jshamlet |
-- All low-level timing of the control signals are handled by
|
28 |
|
|
-- this module, allowing client firmware to use a simple
|
29 |
|
|
-- register interface to program the LCD panel.
|
30 |
175 |
jshamlet |
-- 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_8b 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 |
|
|
uSec_Tick : in std_logic;
|
98 |
|
|
--
|
99 |
|
|
Bus_Address : in ADDRESS_TYPE;
|
100 |
|
|
Wr_Enable : in std_logic;
|
101 |
|
|
Wr_Data : in DATA_TYPE;
|
102 |
|
|
Rd_Enable : in std_logic;
|
103 |
|
|
Rd_Data : out DATA_TYPE;
|
104 |
|
|
Interrupt : out std_logic;
|
105 |
|
|
--
|
106 |
|
|
LCD_E : out std_logic;
|
107 |
|
|
LCD_RW : out std_logic;
|
108 |
|
|
LCD_RS : out std_logic;
|
109 |
|
|
LCD_D : out std_logic_vector(7 downto 0);
|
110 |
|
|
LCD_CN : out std_logic;
|
111 |
|
|
LCD_BL : out std_logic
|
112 |
|
|
);
|
113 |
|
|
end entity;
|
114 |
|
|
|
115 |
|
|
architecture behave of o8_hd44780_8b is
|
116 |
|
|
|
117 |
|
|
constant User_Addr : std_logic_vector(15 downto 2)
|
118 |
|
|
:= Address(15 downto 2);
|
119 |
|
|
alias Comp_Addr is Bus_Address(15 downto 2);
|
120 |
191 |
jshamlet |
signal Addr_Match : std_logic := '0';
|
121 |
175 |
jshamlet |
|
122 |
|
|
alias Reg_Addr is Bus_Address(1 downto 0);
|
123 |
191 |
jshamlet |
signal Reg_Addr_q : std_logic_vector(1 downto 0) := (others => '0');
|
124 |
175 |
jshamlet |
|
125 |
191 |
jshamlet |
signal Wr_En : std_logic := '0';
|
126 |
|
|
signal Wr_Data_q : DATA_TYPE := x"00";
|
127 |
|
|
signal Rd_En : std_logic := '0';
|
128 |
175 |
jshamlet |
|
129 |
191 |
jshamlet |
signal Reg_Valid : std_logic := '0';
|
130 |
|
|
signal Reg_Sel : std_logic := '0';
|
131 |
|
|
signal Reg_Data : DATA_TYPE := x"00";
|
132 |
175 |
jshamlet |
|
133 |
213 |
jshamlet |
signal Tx_Ready : std_logic := '0';
|
134 |
175 |
jshamlet |
|
135 |
|
|
constant LCD_CONFIG1 : std_logic_vector(7 downto 0) := x"38"; -- Set 4-bit, 2-line mode
|
136 |
|
|
constant LCD_CONFIG2 : std_logic_vector(7 downto 0) := x"0C"; -- Turn display on, no cursor
|
137 |
|
|
constant LCD_CONFIG3 : std_logic_vector(7 downto 0) := x"01"; -- Clear display
|
138 |
|
|
constant LCD_CONFIG4 : std_logic_vector(7 downto 0) := x"06"; -- Positive increment, no shift
|
139 |
|
|
constant LCD_CONFIG5 : std_logic_vector(7 downto 0) := x"2A"; -- Print a "*"
|
140 |
|
|
constant LCD_CONFIG6 : std_logic_vector(7 downto 0) := x"02"; -- Reset the cursor
|
141 |
|
|
|
142 |
191 |
jshamlet |
signal init_count : std_logic_vector(2 downto 0) := (others => '0');
|
143 |
175 |
jshamlet |
|
144 |
|
|
constant INIT_40MS : integer := 40000;
|
145 |
|
|
constant INIT_BITS : integer := ceil_log2(INIT_40MS);
|
146 |
|
|
constant INIT_DELAY : std_logic_vector(INIT_BITS-1 downto 0) :=
|
147 |
|
|
conv_std_logic_vector(INIT_40MS,INIT_BITS);
|
148 |
|
|
|
149 |
|
|
-- For "long" instructions, such as clear display and return home, we need to wait for more
|
150 |
|
|
-- than 1.52mS. Experimentally, 2mS seems to work ideally, and for init this isn't an issue
|
151 |
|
|
constant CLDSP_2MS : integer := 2000;
|
152 |
|
|
constant CLDSP_DELAY : std_logic_vector(INIT_BITS-1 downto 0) :=
|
153 |
|
|
conv_std_logic_vector(CLDSP_2MS,INIT_BITS);
|
154 |
|
|
|
155 |
|
|
-- For some reason, we are required to wait 80uS before checking the busy flag, despite
|
156 |
|
|
-- most instructions completing in 37uS. No clue as to why, but it works
|
157 |
|
|
constant BUSY_50US : integer := 50;
|
158 |
|
|
constant BUSY_DELAY : std_logic_vector(INIT_BITS-1 downto 0) :=
|
159 |
|
|
conv_std_logic_vector(BUSY_50US-1, INIT_BITS);
|
160 |
|
|
|
161 |
191 |
jshamlet |
signal busy_timer : std_logic_vector(INIT_BITS-1 downto 0) := (others => '0');
|
162 |
175 |
jshamlet |
|
163 |
|
|
constant SNH_600NS : integer := integer(Sys_Freq * 0.000000600);
|
164 |
|
|
constant SNH_BITS : integer := ceil_log2(SNH_600NS);
|
165 |
|
|
constant SNH_DELAY : std_logic_vector(SNH_BITS-1 downto 0) :=
|
166 |
|
|
conv_std_logic_vector(SNH_600NS-1, SNH_BITS);
|
167 |
|
|
|
168 |
191 |
jshamlet |
signal io_timer : std_logic_vector(SNH_BITS - 1 downto 0) := (others => '0');
|
169 |
175 |
jshamlet |
|
170 |
|
|
type IO_STATES is (INIT, FN_JUMP, IDLE,
|
171 |
|
|
WR_PREP, WR_SETUP, WR_HOLD,
|
172 |
|
|
BUSY_PREP, BUSY_WAIT,
|
173 |
|
|
ISSUE_INT );
|
174 |
|
|
signal io_state : IO_STATES;
|
175 |
|
|
|
176 |
191 |
jshamlet |
signal LCD_Data : std_logic_vector(7 downto 0) := x"00";
|
177 |
|
|
signal LCD_Addr : std_logic := '0';
|
178 |
175 |
jshamlet |
|
179 |
|
|
--------------------------------------------------------------------------------
|
180 |
|
|
-- Backlight & Contrast signals
|
181 |
|
|
--------------------------------------------------------------------------------
|
182 |
|
|
|
183 |
|
|
-- Do not adjust alone! DELTA constants must be
|
184 |
|
|
-- changed as well.
|
185 |
|
|
constant DAC_Width : integer := 8;
|
186 |
|
|
|
187 |
|
|
constant DELTA_1_I : integer := 1;
|
188 |
|
|
constant DELTA_2_I : integer := 5;
|
189 |
|
|
constant DELTA_3_I : integer := 25;
|
190 |
|
|
constant DELTA_4_I : integer := 75;
|
191 |
|
|
constant DELTA_5_I : integer := 125;
|
192 |
|
|
constant DELTA_6_I : integer := 195;
|
193 |
|
|
|
194 |
|
|
constant DELTA_1 : std_logic_vector(DAC_Width-1 downto 0) :=
|
195 |
|
|
conv_std_logic_vector(DELTA_1_I, DAC_Width);
|
196 |
|
|
constant DELTA_2 : std_logic_vector(DAC_Width-1 downto 0) :=
|
197 |
|
|
conv_std_logic_vector(DELTA_2_I, DAC_Width);
|
198 |
|
|
constant DELTA_3 : std_logic_vector(DAC_Width-1 downto 0) :=
|
199 |
|
|
conv_std_logic_vector(DELTA_3_I, DAC_Width);
|
200 |
|
|
constant DELTA_4 : std_logic_vector(DAC_Width-1 downto 0) :=
|
201 |
|
|
conv_std_logic_vector(DELTA_4_I, DAC_Width);
|
202 |
|
|
constant DELTA_5 : std_logic_vector(DAC_Width-1 downto 0) :=
|
203 |
|
|
conv_std_logic_vector(DELTA_5_I, DAC_Width);
|
204 |
|
|
constant DELTA_6 : std_logic_vector(DAC_Width-1 downto 0) :=
|
205 |
|
|
conv_std_logic_vector(DELTA_6_I, DAC_Width);
|
206 |
|
|
|
207 |
|
|
constant MAX_PERIOD : integer := 2**DAC_Width;
|
208 |
|
|
constant DIV_WIDTH : integer := DAC_Width * 2;
|
209 |
|
|
|
210 |
|
|
constant PADJ_1_I : integer := DELTA_1_I * MAX_PERIOD;
|
211 |
|
|
constant PADJ_2_I : integer := DELTA_2_I * MAX_PERIOD;
|
212 |
|
|
constant PADJ_3_I : integer := DELTA_3_I * MAX_PERIOD;
|
213 |
|
|
constant PADJ_4_I : integer := DELTA_4_I * MAX_PERIOD;
|
214 |
|
|
constant PADJ_5_I : integer := DELTA_5_I * MAX_PERIOD;
|
215 |
|
|
constant PADJ_6_I : integer := DELTA_6_I * MAX_PERIOD;
|
216 |
|
|
|
217 |
|
|
constant PADJ_1 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
218 |
|
|
conv_std_logic_vector(PADJ_1_I,DIV_WIDTH);
|
219 |
|
|
constant PADJ_2 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
220 |
|
|
conv_std_logic_vector(PADJ_2_I,DIV_WIDTH);
|
221 |
|
|
constant PADJ_3 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
222 |
|
|
conv_std_logic_vector(PADJ_3_I,DIV_WIDTH);
|
223 |
|
|
constant PADJ_4 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
224 |
|
|
conv_std_logic_vector(PADJ_4_I,DIV_WIDTH);
|
225 |
|
|
constant PADJ_5 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
226 |
|
|
conv_std_logic_vector(PADJ_5_I,DIV_WIDTH);
|
227 |
|
|
constant PADJ_6 : std_logic_vector(DIV_WIDTH-1 downto 0) :=
|
228 |
|
|
conv_std_logic_vector(PADJ_6_I,DIV_WIDTH);
|
229 |
|
|
|
230 |
|
|
constant CB : integer := ceil_log2(DIV_WIDTH);
|
231 |
|
|
|
232 |
191 |
jshamlet |
signal LCD_Contrast : std_logic_vector(7 downto 0) := x"00";
|
233 |
175 |
jshamlet |
|
234 |
191 |
jshamlet |
signal CN_DACin_q : std_logic_vector(DAC_WIDTH-1 downto 0) := (others => '0');
|
235 |
175 |
jshamlet |
|
236 |
191 |
jshamlet |
signal CN_Divisor : std_logic_vector(DIV_WIDTH-1 downto 0) := (others => '0');
|
237 |
|
|
signal CN_Dividend : std_logic_vector(DIV_WIDTH-1 downto 0) := (others => '0');
|
238 |
175 |
jshamlet |
|
239 |
191 |
jshamlet |
signal CN_q : std_logic_vector(DIV_WIDTH*2-1 downto 0) := (others => '0');
|
240 |
|
|
signal CN_diff : std_logic_vector(DIV_WIDTH downto 0) := (others => '0');
|
241 |
175 |
jshamlet |
|
242 |
191 |
jshamlet |
signal CN_count : std_logic_vector(CB-1 downto 0) := (others => '0');
|
243 |
175 |
jshamlet |
|
244 |
191 |
jshamlet |
signal CN_Next_Wdt : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
245 |
|
|
signal CN_Next_Per : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
246 |
175 |
jshamlet |
|
247 |
191 |
jshamlet |
signal CN_PWM_Wdt : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
248 |
|
|
signal CN_PWM_Per : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
249 |
175 |
jshamlet |
|
250 |
191 |
jshamlet |
signal CN_Wdt_Ctr : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
251 |
|
|
signal CN_Per_Ctr : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
252 |
175 |
jshamlet |
|
253 |
191 |
jshamlet |
signal LCD_Bright : std_logic_vector(7 downto 0) := (others => '0');
|
254 |
175 |
jshamlet |
|
255 |
191 |
jshamlet |
signal BL_DACin_q : std_logic_vector(DAC_WIDTH-1 downto 0) := (others => '0');
|
256 |
175 |
jshamlet |
|
257 |
191 |
jshamlet |
signal BL_Divisor : std_logic_vector(DIV_WIDTH-1 downto 0) := (others => '0');
|
258 |
|
|
signal BL_Dividend : std_logic_vector(DIV_WIDTH-1 downto 0) := (others => '0');
|
259 |
175 |
jshamlet |
|
260 |
191 |
jshamlet |
signal BL_q : std_logic_vector(DIV_WIDTH*2-1 downto 0) := (others => '0');
|
261 |
|
|
signal BL_diff : std_logic_vector(DIV_WIDTH downto 0) := (others => '0');
|
262 |
175 |
jshamlet |
|
263 |
191 |
jshamlet |
signal BL_count : std_logic_vector(CB-1 downto 0) := (others => '0');
|
264 |
175 |
jshamlet |
|
265 |
191 |
jshamlet |
signal BL_Next_Wdt : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
266 |
|
|
signal BL_Next_Per : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
267 |
175 |
jshamlet |
|
268 |
191 |
jshamlet |
signal BL_PWM_Wdt : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
269 |
|
|
signal BL_PWM_Per : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
270 |
175 |
jshamlet |
|
271 |
191 |
jshamlet |
signal BL_Wdt_Ctr : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
272 |
|
|
signal BL_Per_Ctr : std_logic_vector(DAC_Width-1 downto 0) := (others => '0');
|
273 |
175 |
jshamlet |
|
274 |
|
|
begin
|
275 |
|
|
|
276 |
|
|
--------------------------------------------------------------------------------
|
277 |
|
|
-- Open8 Register interface
|
278 |
|
|
--------------------------------------------------------------------------------
|
279 |
|
|
|
280 |
|
|
Addr_Match <= '1' when Comp_Addr = User_Addr else '0';
|
281 |
|
|
|
282 |
|
|
io_reg: process( Clock, Reset )
|
283 |
|
|
begin
|
284 |
|
|
if( Reset = Reset_Level )then
|
285 |
|
|
Reg_Addr_q <= (others => '0');
|
286 |
|
|
Wr_Data_q <= (others => '0');
|
287 |
|
|
Wr_En <= '0';
|
288 |
|
|
Rd_En <= '0';
|
289 |
191 |
jshamlet |
Rd_Data <= OPEN8_NULLBUS;
|
290 |
175 |
jshamlet |
|
291 |
|
|
Reg_Valid <= '0';
|
292 |
|
|
Reg_Sel <= '0';
|
293 |
|
|
Reg_Data <= x"00";
|
294 |
|
|
|
295 |
|
|
LCD_Contrast <= Default_Contrast;
|
296 |
|
|
LCD_Bright <= Default_Brightness;
|
297 |
|
|
elsif( rising_edge( Clock ) )then
|
298 |
|
|
Reg_Addr_q <= Reg_Addr;
|
299 |
|
|
|
300 |
|
|
Wr_Data_q <= Wr_Data;
|
301 |
|
|
Wr_En <= Addr_Match and Wr_Enable;
|
302 |
|
|
|
303 |
|
|
Reg_Valid <= '0';
|
304 |
|
|
|
305 |
|
|
if( Wr_En = '1' )then
|
306 |
|
|
case( Reg_Addr_q )is
|
307 |
|
|
when "00" | "01" =>
|
308 |
|
|
Reg_Valid <= '1';
|
309 |
|
|
Reg_Sel <= Reg_Addr_q(0);
|
310 |
|
|
Reg_Data <= Wr_Data_q;
|
311 |
|
|
when "10" =>
|
312 |
|
|
LCD_Contrast<= Wr_Data_q;
|
313 |
|
|
when "11" =>
|
314 |
|
|
LCD_Bright <= Wr_Data_q;
|
315 |
|
|
when others => null;
|
316 |
|
|
end case;
|
317 |
|
|
end if;
|
318 |
|
|
|
319 |
191 |
jshamlet |
Rd_Data <= OPEN8_NULLBUS;
|
320 |
175 |
jshamlet |
Rd_En <= Addr_Match and Rd_Enable;
|
321 |
|
|
if( Rd_En = '1' )then
|
322 |
|
|
case( Reg_Addr_q )is
|
323 |
|
|
when "00" | "01" =>
|
324 |
|
|
Rd_Data(7) <= Tx_Ready;
|
325 |
|
|
when "10" =>
|
326 |
|
|
Rd_Data <= LCD_Contrast;
|
327 |
|
|
when "11" =>
|
328 |
|
|
Rd_Data <= LCD_Bright;
|
329 |
|
|
when others => null;
|
330 |
|
|
end case;
|
331 |
|
|
end if;
|
332 |
|
|
end if;
|
333 |
|
|
end process;
|
334 |
|
|
|
335 |
|
|
--------------------------------------------------------------------------------
|
336 |
|
|
-- LCD and Register logic
|
337 |
|
|
--------------------------------------------------------------------------------
|
338 |
|
|
|
339 |
|
|
LCD_RW <= '0'; -- Permanently wire the RW line low
|
340 |
|
|
|
341 |
|
|
LCD_IO: process( Clock, Reset )
|
342 |
|
|
begin
|
343 |
|
|
if( Reset = Reset_Level )then
|
344 |
|
|
io_state <= INIT;
|
345 |
|
|
init_count <= (others => '0');
|
346 |
|
|
io_timer <= (others => '0');
|
347 |
|
|
busy_timer <= (others => '0');
|
348 |
|
|
LCD_Data <= (others => '0');
|
349 |
|
|
LCD_Addr <= '0';
|
350 |
|
|
LCD_E <= '0';
|
351 |
|
|
LCD_RS <= '0';
|
352 |
|
|
LCD_D <= (others => '0');
|
353 |
|
|
Tx_Ready <= '0';
|
354 |
|
|
Interrupt <= '0';
|
355 |
|
|
elsif( rising_edge(Clock) )then
|
356 |
|
|
LCD_E <= '0';
|
357 |
|
|
LCD_RS <= '0';
|
358 |
|
|
LCD_D <= (others => '0');
|
359 |
|
|
Tx_Ready <= '0';
|
360 |
|
|
Interrupt <= '0';
|
361 |
|
|
io_timer <= io_timer - 1;
|
362 |
|
|
busy_timer <= busy_timer - uSec_Tick;
|
363 |
|
|
case( io_state )is
|
364 |
|
|
|
365 |
|
|
when INIT =>
|
366 |
|
|
busy_timer <= INIT_DELAY;
|
367 |
|
|
init_count <= (others => '1');
|
368 |
|
|
io_state <= BUSY_WAIT;
|
369 |
|
|
|
370 |
|
|
when FN_JUMP =>
|
371 |
|
|
io_state <= WR_PREP;
|
372 |
|
|
case( init_count )is
|
373 |
|
|
when "000" =>
|
374 |
|
|
io_state <= IDLE;
|
375 |
|
|
when "001" =>
|
376 |
|
|
LCD_Addr <= '0';
|
377 |
|
|
LCD_Data <= LCD_CONFIG6; -- Reset the Cursor
|
378 |
|
|
when "010" =>
|
379 |
|
|
LCD_Addr <= '1'; -- Print a "*", and
|
380 |
|
|
LCD_Data <= LCD_CONFIG5; -- set RS to 1
|
381 |
|
|
when "011" =>
|
382 |
|
|
LCD_Data <= LCD_CONFIG4; -- Entry mode
|
383 |
|
|
when "100" =>
|
384 |
|
|
LCD_Data <= LCD_CONFIG3; -- Clear Display
|
385 |
|
|
when "101" =>
|
386 |
|
|
LCD_Data <= LCD_CONFIG2; -- Display control
|
387 |
|
|
when "110" | "111" =>
|
388 |
|
|
LCD_Addr <= '0';
|
389 |
|
|
LCD_Data <= LCD_CONFIG1; -- Function set
|
390 |
|
|
when others => null;
|
391 |
|
|
end case;
|
392 |
|
|
|
393 |
|
|
when IDLE =>
|
394 |
|
|
Tx_Ready <= '1';
|
395 |
|
|
if( Reg_Valid = '1' )then
|
396 |
|
|
LCD_Addr <= Reg_Sel;
|
397 |
|
|
LCD_Data <= Reg_Data;
|
398 |
|
|
io_state <= WR_PREP;
|
399 |
|
|
end if;
|
400 |
|
|
|
401 |
|
|
when WR_PREP =>
|
402 |
|
|
io_timer <= SNH_DELAY;
|
403 |
|
|
io_state <= WR_SETUP;
|
404 |
|
|
|
405 |
|
|
when WR_SETUP =>
|
406 |
|
|
LCD_RS <= LCD_Addr;
|
407 |
|
|
LCD_D <= LCD_Data;
|
408 |
|
|
LCD_E <= '1';
|
409 |
|
|
if( io_timer = 0 )then
|
410 |
|
|
io_timer <= SNH_DELAY;
|
411 |
|
|
io_state <= WR_HOLD;
|
412 |
|
|
end if;
|
413 |
|
|
|
414 |
|
|
when WR_HOLD =>
|
415 |
|
|
LCD_RS <= LCD_Addr;
|
416 |
|
|
LCD_D <= LCD_Data;
|
417 |
|
|
if( io_timer = 0 )then
|
418 |
|
|
LCD_E <= '0';
|
419 |
|
|
io_state <= BUSY_PREP;
|
420 |
|
|
end if;
|
421 |
|
|
|
422 |
|
|
when BUSY_PREP =>
|
423 |
|
|
busy_timer <= BUSY_DELAY;
|
424 |
|
|
if( LCD_Addr = '0' and LCD_Data < 4 )then
|
425 |
|
|
busy_timer <= CLDSP_DELAY;
|
426 |
|
|
end if;
|
427 |
|
|
io_state <= BUSY_WAIT;
|
428 |
|
|
|
429 |
|
|
when BUSY_WAIT =>
|
430 |
|
|
if( busy_timer = 0 )then
|
431 |
|
|
io_state <= ISSUE_INT;
|
432 |
|
|
if( init_count > 0 )then
|
433 |
|
|
init_count<= init_count - 1;
|
434 |
|
|
io_state <= FN_JUMP;
|
435 |
|
|
end if;
|
436 |
|
|
end if;
|
437 |
|
|
|
438 |
|
|
when ISSUE_INT =>
|
439 |
|
|
Interrupt <= '1';
|
440 |
|
|
io_state <= IDLE;
|
441 |
|
|
|
442 |
|
|
when others => null;
|
443 |
|
|
|
444 |
|
|
end case;
|
445 |
|
|
|
446 |
|
|
end if;
|
447 |
|
|
end process;
|
448 |
|
|
|
449 |
|
|
--------------------------------------------------------------------------------
|
450 |
|
|
-- Contrast control logic (optional)
|
451 |
|
|
--------------------------------------------------------------------------------
|
452 |
|
|
|
453 |
|
|
Contrast_Disabled: if( not Use_Contrast )generate
|
454 |
|
|
LCD_CN <= '0';
|
455 |
|
|
end generate;
|
456 |
|
|
|
457 |
|
|
Contrast_Enabled: if( Use_Contrast )generate
|
458 |
|
|
|
459 |
|
|
CN_diff <= ('0' & CN_q(DIV_WIDTH*2-2 downto DIV_WIDTH-1)) -
|
460 |
|
|
('0' & CN_Divisor);
|
461 |
|
|
|
462 |
|
|
CN_Dividend<= PADJ_2 when CN_DACin_q >= DELTA_2_I and CN_DACin_q < DELTA_3_I else
|
463 |
|
|
PADJ_3 when CN_DACin_q >= DELTA_3_I and CN_DACin_q < DELTA_4_I else
|
464 |
|
|
PADJ_4 when CN_DACin_q >= DELTA_4_I and CN_DACin_q < DELTA_5_I else
|
465 |
|
|
PADJ_5 when CN_DACin_q >= DELTA_5_I and CN_DACin_q < DELTA_6_I else
|
466 |
|
|
PADJ_6 when CN_DACin_q >= DELTA_6_I else
|
467 |
|
|
PADJ_1;
|
468 |
|
|
|
469 |
|
|
CN_Next_Wdt<= DELTA_1 when CN_DACin_q >= DELTA_1_I and CN_DACin_q < DELTA_2_I else
|
470 |
|
|
DELTA_2 when CN_DACin_q >= DELTA_2_I and CN_DACin_q < DELTA_3_I else
|
471 |
|
|
DELTA_3 when CN_DACin_q >= DELTA_3_I and CN_DACin_q < DELTA_4_I else
|
472 |
|
|
DELTA_4 when CN_DACin_q >= DELTA_4_I and CN_DACin_q < DELTA_5_I else
|
473 |
|
|
DELTA_5 when CN_DACin_q >= DELTA_5_I and CN_DACin_q < DELTA_6_I else
|
474 |
|
|
DELTA_6 when CN_DACin_q >= DELTA_6_I else
|
475 |
|
|
(others => '0');
|
476 |
|
|
|
477 |
|
|
CN_Next_Per <= BL_q(7 downto 0) - 1;
|
478 |
|
|
|
479 |
|
|
CN_vDSM_proc: process( Clock, Reset )
|
480 |
|
|
begin
|
481 |
|
|
if( Reset = Reset_Level )then
|
482 |
|
|
CN_q <= (others => '0');
|
483 |
|
|
CN_count <= (others => '1');
|
484 |
|
|
CN_Divisor <= (others => '0');
|
485 |
|
|
CN_DACin_q <= (others => '0');
|
486 |
|
|
CN_PWM_Wdt <= (others => '0');
|
487 |
|
|
CN_PWM_Per <= (others => '0');
|
488 |
|
|
CN_Per_Ctr <= (others => '0');
|
489 |
|
|
CN_Wdt_Ctr <= (others => '0');
|
490 |
|
|
LCD_CN <= '0';
|
491 |
|
|
elsif( rising_edge(Clock) )then
|
492 |
|
|
CN_q <= CN_diff(DIV_WIDTH-1 downto 0) &
|
493 |
|
|
CN_q(DIV_WIDTH-2 downto 0) & '1';
|
494 |
|
|
if( CN_diff(DIV_WIDTH) = '1' )then
|
495 |
|
|
CN_q <= CN_q(DIV_WIDTH*2-2 downto 0) & '0';
|
496 |
|
|
end if;
|
497 |
|
|
|
498 |
|
|
CN_count <= CN_count + 1;
|
499 |
|
|
if( CN_count = DIV_WIDTH )then
|
500 |
|
|
CN_PWM_Wdt <= CN_Next_Wdt;
|
501 |
|
|
CN_PWM_Per <= CN_Next_Per;
|
502 |
|
|
CN_DACin_q <= LCD_Contrast;
|
503 |
|
|
CN_Divisor <= (others => '0');
|
504 |
|
|
CN_Divisor(DAC_Width-1 downto 0) <= CN_DACin_q;
|
505 |
|
|
CN_q <= conv_std_logic_vector(0,DIV_WIDTH) & CN_Dividend;
|
506 |
|
|
CN_count <= (others => '0');
|
507 |
|
|
end if;
|
508 |
|
|
|
509 |
|
|
CN_Per_Ctr <= CN_Per_Ctr - 1;
|
510 |
|
|
CN_Wdt_Ctr <= CN_Wdt_Ctr - 1;
|
511 |
|
|
|
512 |
|
|
LCD_CN <= '1';
|
513 |
|
|
if( CN_Wdt_Ctr = 0 )then
|
514 |
|
|
LCD_CN <= '0';
|
515 |
|
|
CN_Wdt_Ctr <= (others => '0');
|
516 |
|
|
end if;
|
517 |
|
|
|
518 |
|
|
if( CN_Per_Ctr = 0 )then
|
519 |
|
|
CN_Per_Ctr <= CN_PWM_Per;
|
520 |
|
|
CN_Wdt_Ctr <= CN_PWM_Wdt;
|
521 |
|
|
end if;
|
522 |
|
|
|
523 |
|
|
end if;
|
524 |
|
|
end process;
|
525 |
|
|
end generate;
|
526 |
|
|
|
527 |
|
|
--------------------------------------------------------------------------------
|
528 |
|
|
-- Backlight control logic (optional)
|
529 |
|
|
--------------------------------------------------------------------------------
|
530 |
|
|
|
531 |
|
|
Backlight_Disabled: if( not Use_Backlight )generate
|
532 |
|
|
LCD_BL <= '0';
|
533 |
|
|
end generate;
|
534 |
|
|
|
535 |
|
|
Backlight_Enabled: if( Use_Backlight )generate
|
536 |
|
|
|
537 |
|
|
BL_diff <= ('0' & BL_q(DIV_WIDTH*2-2 downto DIV_WIDTH-1)) -
|
538 |
|
|
('0' & BL_Divisor);
|
539 |
|
|
|
540 |
|
|
BL_Dividend<= PADJ_2 when BL_DACin_q >= DELTA_2_I and BL_DACin_q < DELTA_3_I else
|
541 |
|
|
PADJ_3 when BL_DACin_q >= DELTA_3_I and BL_DACin_q < DELTA_4_I else
|
542 |
|
|
PADJ_4 when BL_DACin_q >= DELTA_4_I and BL_DACin_q < DELTA_5_I else
|
543 |
|
|
PADJ_5 when BL_DACin_q >= DELTA_5_I and BL_DACin_q < DELTA_6_I else
|
544 |
|
|
PADJ_6 when BL_DACin_q >= DELTA_6_I else
|
545 |
|
|
PADJ_1;
|
546 |
|
|
|
547 |
|
|
BL_Next_Wdt<= DELTA_1 when BL_DACin_q >= DELTA_1_I and BL_DACin_q < DELTA_2_I else
|
548 |
|
|
DELTA_2 when BL_DACin_q >= DELTA_2_I and BL_DACin_q < DELTA_3_I else
|
549 |
|
|
DELTA_3 when BL_DACin_q >= DELTA_3_I and BL_DACin_q < DELTA_4_I else
|
550 |
|
|
DELTA_4 when BL_DACin_q >= DELTA_4_I and BL_DACin_q < DELTA_5_I else
|
551 |
|
|
DELTA_5 when BL_DACin_q >= DELTA_5_I and BL_DACin_q < DELTA_6_I else
|
552 |
|
|
DELTA_6 when BL_DACin_q >= DELTA_6_I else
|
553 |
|
|
(others => '0');
|
554 |
|
|
|
555 |
|
|
BL_Next_Per <= BL_q(7 downto 0) - 1;
|
556 |
|
|
|
557 |
|
|
BL_vDSM_proc: process( Clock, Reset )
|
558 |
|
|
begin
|
559 |
|
|
if( Reset = Reset_Level )then
|
560 |
|
|
BL_q <= (others => '0');
|
561 |
|
|
BL_count <= (others => '1');
|
562 |
|
|
BL_Divisor <= (others => '0');
|
563 |
|
|
BL_DACin_q <= (others => '0');
|
564 |
|
|
BL_PWM_Wdt <= (others => '0');
|
565 |
|
|
BL_PWM_Per <= (others => '0');
|
566 |
|
|
BL_Per_Ctr <= (others => '0');
|
567 |
|
|
BL_Wdt_Ctr <= (others => '0');
|
568 |
|
|
LCD_BL <= '0';
|
569 |
|
|
elsif( rising_edge(Clock) )then
|
570 |
|
|
BL_q <= BL_diff(DIV_WIDTH-1 downto 0) &
|
571 |
|
|
BL_q(DIV_WIDTH-2 downto 0) & '1';
|
572 |
|
|
if( BL_diff(DIV_WIDTH) = '1' )then
|
573 |
|
|
BL_q <= BL_q(DIV_WIDTH*2-2 downto 0) & '0';
|
574 |
|
|
end if;
|
575 |
|
|
|
576 |
|
|
BL_count <= BL_count + 1;
|
577 |
|
|
if( BL_count = DIV_WIDTH )then
|
578 |
|
|
BL_PWM_Wdt <= BL_Next_Wdt;
|
579 |
|
|
BL_PWM_Per <= BL_Next_Per;
|
580 |
|
|
BL_DACin_q <= LCD_Bright;
|
581 |
|
|
BL_Divisor <= (others => '0');
|
582 |
|
|
BL_Divisor(DAC_Width-1 downto 0) <= BL_DACin_q;
|
583 |
|
|
BL_q <= conv_std_logic_vector(0,DIV_WIDTH) & BL_Dividend;
|
584 |
|
|
BL_count <= (others => '0');
|
585 |
|
|
end if;
|
586 |
|
|
|
587 |
|
|
BL_Per_Ctr <= BL_Per_Ctr - 1;
|
588 |
|
|
BL_Wdt_Ctr <= BL_Wdt_Ctr - 1;
|
589 |
|
|
|
590 |
|
|
LCD_BL <= '1';
|
591 |
|
|
if( BL_Wdt_Ctr = 0 )then
|
592 |
|
|
LCD_BL <= '0';
|
593 |
|
|
BL_Wdt_Ctr <= (others => '0');
|
594 |
|
|
end if;
|
595 |
|
|
|
596 |
|
|
if( BL_Per_Ctr = 0 )then
|
597 |
|
|
BL_Per_Ctr <= BL_PWM_Per;
|
598 |
|
|
BL_Wdt_Ctr <= BL_PWM_Wdt;
|
599 |
|
|
end if;
|
600 |
|
|
|
601 |
|
|
end if;
|
602 |
|
|
end process;
|
603 |
|
|
|
604 |
|
|
end generate;
|
605 |
|
|
|
606 |
|
|
end architecture;
|