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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_hd44780_if.vhd] - Blame information for rev 332

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

Line No. Rev Author Line
1 286 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
-- VHDL Entity: o8_hd44780_if
25
-- Description: Provides low-level access to "standard" character LCDs using
26
--               the ST/HD44780(U) control ASIC wired in either 8-bit or
27
--               reduced (4-bit) mode.
28
--              All low-level timing of the control signals are handled by this
29
--               module, allowing client firmware to use a simple register
30
--               interface to program the LCD panel.
31 288 jshamlet
-- Note that this module assumes that the R/Wn line has been tied LOW
32 286 jshamlet
--
33
-- Register Map
34
-- Address  Function
35
-- Offset  Bitfield Description                        Read/Write
36
-- 0x0     AAAAAAAA LCD Register Write                 (Read-Write*)
37
-- 0x1     AAAAAAAA LCD Data Write                     (Read-Write*)
38
-- 0x2     AAAAAAAA LCD Rearm Init Timer               (Read-Write*)
39
-- 0x3     AAAAAAAA LCD Backlight                      (Read-Write)
40
--
41
-- Note: Reading 0x0, 0x1 or 0x2 will report whether the panel is ready or not
42
--        in the MSB (bit 7). 0x00 = NOT READY / 0x80 = READY
43
--
44
--------------------------------------------------------------------------------
45
-- LCD Controller
46
--------------------------------------------------------------------------------
47
--
48
-- LCD Instruction Set (Hitachi Compatible)
49
-- Instruction             RS  RW  D7  D6  D5  D4  D3  D2  D1  D0  Time
50
------------------------------------------------------------------------
51
-- Clear Display         | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1.52mS
52
-- Return Home           | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | x | 1.52mS
53
-- Entry Mode            | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ID| S |   37uS
54
-- Display Pwr           | 0 | 0 | 0 | 0 | 0 | 0 | 1 | D | C | B |   37uS
55
-- Cursor/Display Shift  | 0 | 0 | 0 | 0 | 0 | 1 | SC| RL| x | x |   37uS
56
-- Function Set          | 0 | 0 | 0 | 0 | 1 | DL| N | F | x | x |   37uS
57
-- Set CGRAM Address     | 0 | 0 | 0 | 1 | A | A | A | A | A | A |   37uS
58
-- Set DDRAM Address     | 0 | 0 | 1 | A | A | A | A | A | A | A |   37uS
59
 
60
-- LCD Instruction Set (New Haven)
61
-- Instruction             RS  RW  D7  D6  D5  D4  D3  D2  D1  D0  Time
62
------------------------------------------------------------------------
63
-- Clear Display         | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2.00mS
64
-- Return Home           | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | x |  600uS
65
-- Entry Mode            | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ID| S |  600uS
66
-- Display Pwr           | 0 | 0 | 0 | 0 | 0 | 0 | 1 | D | C | B |  600uS
67
-- Cursor/Display Shift  | 0 | 0 | 0 | 0 | 0 | 1 | SC| RL| x | x |  600uS
68
-- Function Set          | 0 | 0 | 0 | 0 | 1 | DL| N | F | T | T |  600uS
69
-- Set CGRAM Address     | 0 | 0 | 0 | 1 | A | A | A | A | A | A |  600uS
70
-- Set DDRAM Address     | 0 | 0 | 1 | A | A | A | A | A | A | A |  600uS
71
--
72
-- Notes:
73
-- ID = Increment/Decrement DDRAM Address (1 = increment, 0 = decrement)
74
-- S  = Shift Enable (1 = Shift display according to ID, 0 = Don't shift)
75
-- D  = Display On/Off (1 = on, 0 = off)
76
-- C  = Cursor On/Off  (1 = on, 0 = off)
77
-- B  = Cursor Blink   (1 = block cursor, 0 = underline cursor)
78
-- SC / RL = Shift Cursor/Display Right/Left (see data sheet - not needed for init)
79
-- F  = Font (0 = 5x8, 1 = 5x11) Ignored on 2-line displays (N = 1)
80
-- N  = Number of Lines (0 = 1 lines, 1 = 2 lines)
81
-- DL = Data Length (0 = 4-bit bus, 1 = 8-bit bus) This is fixed at 1 in this module
82
-- A  = Address (see data sheet for usage)
83
-- T  = New Haven Only - Changes the character set (see data sheet)
84
--
85
-- Revision History
86
-- Author          Date     Change
87
------------------ -------- ---------------------------------------------------
88 287 jshamlet
-- Seth Henry      04/12/21 Design Start
89 286 jshamlet
 
90
 
91
library ieee;
92
use ieee.std_logic_1164.all;
93
use ieee.std_logic_unsigned.all;
94
use ieee.std_logic_arith.all;
95
 
96
library work;
97
use work.open8_pkg.all;
98
 
99
entity o8_hd44780_if is
100
generic(
101 289 jshamlet
  Use_4Bit_IF                : boolean := FALSE;
102 322 jshamlet
  -- LCD bus IF timing
103
  Tas                        : integer :=    20; -- ns
104
  Tpwe                       : integer :=   450; -- nS
105
  Tcyce                      : integer :=  1000; -- nS
106
  -- LCD command timing
107 286 jshamlet
  Tpwrdly                    : integer := 40000; -- uS
108
  Tcldsp                     : integer :=  2000; -- uS
109
  Tbusy                      : integer :=    50; -- uS
110 322 jshamlet
  -- Backlight
111 286 jshamlet
  Use_Backlight              : boolean := FALSE;
112
  Default_Brightness         : std_logic_vector(7 downto 0) := x"00";
113 322 jshamlet
  -- System clock & address
114 286 jshamlet
  Clock_Frequency            : real;
115
  Address                    : ADDRESS_TYPE
116
);
117
port(
118
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
119
  Write_Qual                 : in  std_logic := '1';
120
  Rd_Data                    : out DATA_TYPE;
121
  Interrupt                  : out std_logic;
122
  --
123
  LCD_E                      : out std_logic;
124
  LCD_RS                     : out std_logic;
125
  LCD_DQ                     : out std_logic_vector(7 downto 0);
126
  LCD_BL                     : out std_logic
127
);
128
end entity;
129
 
130
architecture behave of o8_hd44780_if is
131
 
132
  alias Clock                is Open8_Bus.Clock;
133
  alias Reset                is Open8_Bus.Reset;
134
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
135
 
136
  constant User_Addr         : std_logic_vector(15 downto 2)
137
                               := Address(15 downto 2);
138
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
139
  signal Addr_Match          : std_logic;
140
 
141
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
142
  signal Reg_Sel_q           : std_logic_vector(1 downto 0) := "00";
143
  signal Wr_En_d             : std_logic := '0';
144
  signal Wr_En_q             : std_logic := '0';
145
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
146
  signal Wr_Data_q           : DATA_TYPE := x"00";
147
  signal Rd_En_d             : std_logic := '0';
148
  signal Rd_En_q             : std_logic := '0';
149
 
150
  signal Rearm_Init          : std_logic := '0';
151
 
152
  signal Reg_Valid           : std_logic := '0';
153
  signal Reg_Sel             : std_logic := '0';
154
  signal Reg_Data            : std_logic_vector(7 downto 0) := x"00";
155
 
156
  signal Tx_Ready            : std_logic := '0';
157
 
158
  constant HW_TMR_BITS       : integer := ceil_log2(Tpwrdly);
159
  constant TPWR_DELAY        : std_logic_vector(HW_TMR_BITS-1 downto 0) :=
160
                               conv_std_logic_vector(Tpwrdly,HW_TMR_BITS);
161
 
162
  constant CLDSP_DELAY       : std_logic_vector(HW_TMR_BITS-1 downto 0) :=
163
                               conv_std_logic_vector(Tcldsp,HW_TMR_BITS);
164
 
165
  constant BUSY_DELAY        : std_logic_vector(HW_TMR_BITS-1 downto 0) :=
166
                               conv_std_logic_vector(Tbusy, HW_TMR_BITS);
167
 
168
  signal hw_timer            : std_logic_vector(HW_TMR_BITS-1 downto 0);
169
 
170
  type CTRL_STATES is (INIT, PWR_WAIT, IDLE, PREP_WR, ISSUE_WR, WR_WAIT,
171
                       BUSY_WAIT, ISSUE_INT );
172
 
173
  signal ctrl_state          : CTRL_STATES := INIT;
174
 
175
  signal Wr_Fnset            : std_logic := '0';
176
  signal Wr_Data             : DATA_TYPE := x"00";
177
  signal Wr_Reg              : std_logic := '0';
178
  signal Wr_En               : std_logic := '0';
179
 
180
  signal IO_Done             : std_logic := '0';
181
 
182
  signal LCD_Data            : DATA_TYPE := x"00";
183
  signal LCD_Addr            : std_logic := '0';
184
 
185
--------------------------------------------------------------------------------
186
-- Backlight signals
187
--------------------------------------------------------------------------------
188
 
189
  signal LCD_Bright          : DATA_TYPE := x"00";
190
 
191
begin
192
 
193
--------------------------------------------------------------------------------
194
-- Open8 Register interface
195
--------------------------------------------------------------------------------
196
 
197
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
198
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En and Write_Qual;
199
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
200
 
201
  io_reg: process( Clock, Reset )
202
  begin
203
    if( Reset = Reset_Level )then
204
      Reg_Sel_q              <= "00";
205
      Wr_En_q                <= '0';
206
      Wr_Data_q              <= x"00";
207
      Rd_En_q                <= '0';
208
      Rd_Data                <= OPEN8_NULLBUS;
209
 
210
      Rearm_Init             <= '0';
211
 
212
      Reg_Valid              <= '0';
213
      Reg_Sel                <= '0';
214
      Reg_Data               <= x"00";
215
 
216
      LCD_Bright             <= Default_Brightness;
217
    elsif( rising_edge( Clock ) )then
218
      Reg_Sel_q              <= Reg_Sel_d;
219
 
220
      Rearm_Init             <= '0';
221
 
222
      Wr_En_q                <= Wr_En_d;
223
      Wr_Data_q              <= Wr_Data_d;
224
      Reg_Valid              <= '0';
225
      if( Wr_En_q = '1' )then
226
        case( Reg_Sel_q )is
227
          when "00" | "01" =>
228
            Reg_Valid        <= '1';
229
            Reg_Sel          <= Reg_Sel_q(0);
230
            Reg_Data         <= Wr_Data_q;
231
          when "10" =>
232
            Rearm_Init       <= '1';
233
          when "11" =>
234
            LCD_Bright       <= Wr_Data_q;
235
          when others => null;
236
        end case;
237
      end if;
238
 
239
      Rd_En_q                <= Rd_En_d;
240
      Rd_Data                <= OPEN8_NULLBUS;
241
      if( Rd_En_q = '1' )then
242
        case( Reg_Sel_q )is
243
          when "00" | "01" | "10" =>
244
            Rd_Data(7)       <= Tx_Ready;
245
          when "11" =>
246
            Rd_Data          <= LCD_Bright;
247
          when others => null;
248
        end case;
249
      end if;
250
    end if;
251
  end process;
252
 
253
--------------------------------------------------------------------------------
254
-- LCD and Register logic
255
--------------------------------------------------------------------------------
256
 
257
  LCD_Ctrl_proc: process( Clock, Reset )
258
  begin
259
    if( Reset = Reset_Level )then
260
      ctrl_state             <= INIT;
261
      hw_timer               <= (others => '0');
262
      Wr_Fnset               <= '0';
263
      Wr_Data                <= x"00";
264
      Wr_Reg                 <= '0';
265
      Wr_En                  <= '0';
266
      Tx_Ready               <= '0';
267
      Interrupt              <= '0';
268
    elsif( rising_edge(Clock) )then
269
      Wr_En                  <= '0';
270
      Tx_Ready               <= '0';
271
      Interrupt              <= '0';
272
      hw_timer               <= hw_timer - uSec_Tick;
273
      case( ctrl_state )is
274
 
275
        when INIT =>
276
          hw_timer           <= TPWR_DELAY;
277
          ctrl_state         <= PWR_WAIT;
278
 
279
        when PWR_WAIT =>
280
          if( hw_timer = 0 )then
281
            ctrl_state       <= IDLE;
282
          end if;
283
 
284
        when IDLE =>
285
          Tx_Ready           <= '1';
286
          if( Rearm_Init = '1' )then
287
            ctrl_state       <= INIT;
288
          elsif( Reg_Valid = '1' )then
289
            Wr_Reg           <= Reg_Sel;
290
            Wr_Data          <= Reg_Data;
291
            ctrl_state       <= PREP_WR;
292
          end if;
293
 
294
        when PREP_WR =>
295
          Wr_Fnset           <= '0';
296
          -- Trap on Function Set if we are in 4-bit mode, so that we can issue
297
          --  the first nibble twice.
298
          if( Use_4Bit_IF and
299
              Wr_Reg = '0' and
300
              Wr_Data(7 downto 4) = "0010" )then
301
            Wr_Fnset         <= '1';
302
          end if;
303
            ctrl_state       <= ISSUE_WR;
304
 
305
        when ISSUE_WR =>
306
          Wr_En              <= '1';
307
          hw_timer           <= BUSY_DELAY;
308 289 jshamlet
          if( Wr_Reg = '0' and Wr_Data < 4 )then
309 286 jshamlet
            hw_timer         <= CLDSP_DELAY;
310
          end if;
311
          ctrl_state         <= WR_WAIT;
312
 
313
        when WR_WAIT =>
314
          if( IO_Done = '1' )then
315
            ctrl_state       <= BUSY_WAIT;
316
          end if;
317
 
318
        when BUSY_WAIT =>
319
          if( hw_timer = 0 )then
320
            ctrl_state       <= ISSUE_INT;
321
          end if;
322
 
323
        when ISSUE_INT =>
324
          Interrupt          <= '1';
325
          ctrl_state         <= IDLE;
326
 
327
        when others => null;
328
 
329
      end case;
330
 
331
    end if;
332
  end process;
333
 
334
--------------------------------------------------------------------------------
335
-- Low-level I/O drivers
336
--------------------------------------------------------------------------------
337
 
338
IF_Type_4bit: if( Use_4Bit_IF )generate
339
 
340
  U_IO : entity work.hd44780_4b
341
  generic map(
342 322 jshamlet
    Tas                      => Tas,
343
    Tpwe                     => Tpwe,
344
    Tcyce                    => Tcyce,
345 286 jshamlet
    Clock_Frequency          => Clock_Frequency,
346
    Reset_Level              => Reset_Level
347
  )
348
  port map(
349
    Clock                    => Clock,
350
    Reset                    => Reset,
351
    --
352
    Wr_Fnset                 => Wr_Fnset,
353
    Wr_Data                  => Wr_Data,
354
    Wr_Reg                   => Wr_Reg,
355
    Wr_En                    => Wr_En,
356
    --
357
    IO_Done                  => IO_Done,
358
    --
359
    LCD_RS                   => LCD_RS,
360
    LCD_E                    => LCD_E,
361
    LCD_DQ                   => LCD_DQ
362
  );
363
 
364
end generate;
365
 
366
IF_Type_8bit: if( not Use_4Bit_IF )generate
367
 
368
  U_IO : entity work.hd44780_8b
369
  generic map(
370 322 jshamlet
    Tas                      => Tas,
371
    Tpwe                     => Tpwe,
372
    Tcyce                    => Tcyce,
373 286 jshamlet
    Clock_Frequency          => Clock_Frequency,
374
    Reset_Level              => Reset_Level
375
  )
376
  port map(
377
    Clock                    => Clock,
378
    Reset                    => Reset,
379
    --
380
    Wr_Data                  => Wr_Data,
381
    Wr_Reg                   => Wr_Reg,
382
    Wr_En                    => Wr_En,
383
    --
384
    IO_Done                  => IO_Done,
385
    --
386
    LCD_RS                   => LCD_RS,
387
    LCD_E                    => LCD_E,
388
    LCD_DQ                   => LCD_DQ
389
  );
390
 
391
end generate;
392
 
393
--------------------------------------------------------------------------------
394
-- Backlight control logic (optional)
395
--------------------------------------------------------------------------------
396
 
397
Backlight_Disabled: if( not Use_Backlight )generate
398
  LCD_BL                <= '0';
399
end generate;
400
 
401
Backlight_Enabled: if( Use_Backlight )generate
402
 
403
  U_BL : entity work.vdsm8
404
  generic map(
405
    Reset_Level              => Reset_Level
406
  )
407
  port map(
408
    Clock                    => Clock,
409
    Reset                    => Reset,
410
    DACin                    => LCD_Bright,
411
    DACout                   => LCD_BL
412
  );
413
 
414
end generate;
415
 
416
end architecture;

powered by: WebSVN 2.1.0

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