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 191

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

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

powered by: WebSVN 2.1.0

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