OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_hd44780_8b.vhd] - Blame information for rev 194

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.