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 287

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

powered by: WebSVN 2.1.0

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