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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_hd44780_4b.vhd] - Blame information for rev 209

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

powered by: WebSVN 2.1.0

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