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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [hd44780_8b.vhd] - Blame information for rev 329

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

Line No. Rev Author Line
1 287 jshamlet
-- Copyright (c)2021 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 timing of the control signals in 8-bit mode
26
--              (required by o8_hd44780_if)
27
--
28 322 jshamlet
-- Note: This code attempts to implement the timing diagram in the HD44780U
29
--        LCD II datasheet with a few simplifications. Chiefly, DQ is updated
30
--        at the start of E, rather than attempting to assert within Tds of
31
--        the falling edge of E. Further, both RS and DQ are asserted until
32
--        the end of Tcycle, where Tcycle is defined as TcycleE + Tas
33
 
34 287 jshamlet
-- Revision History
35
-- Author          Date     Change
36
------------------ -------- ---------------------------------------------------
37
-- Seth Henry      04/12/21 Design Start
38 322 jshamlet
-- Seth Henry      09/19/23 Rewrote IF to use a single cycle timer
39 287 jshamlet
 
40 286 jshamlet
library ieee;
41
  use ieee.std_logic_1164.all;
42
  use ieee.std_logic_unsigned.all;
43
  use ieee.std_logic_arith.all;
44
  use ieee.std_logic_misc.all;
45
 
46
entity hd44780_8b is
47
generic(
48 322 jshamlet
  Tas                        : integer :=   50; -- ns
49
  Tpwe                       : integer :=  450; -- ns
50
  Tcyce                      : integer := 1000; -- ns
51
  Clock_Frequency            : real    := 100000000.0; -- Hz
52 286 jshamlet
  Reset_Level                : std_logic := '1'
53
);
54
port(
55
  Clock                      : in  std_logic;
56
  Reset                      : in  std_logic;
57
  --
58
  Wr_Data                    : in  std_logic_vector(7 downto 0);
59
  Wr_Reg                     : in  std_logic;
60
  Wr_En                      : in  std_logic;
61
  --
62
  IO_Done                    : out std_logic;
63
  --
64
  LCD_RS                     : out std_logic;
65
  LCD_E                      : out std_logic;
66
  LCD_DQ                     : out std_logic_vector(7 downto 0)
67
);
68
end entity;
69
 
70
architecture behave of hd44780_8b is
71
 
72
  -- The ceil_log2 function returns the minimum register width required to
73
  --  hold the supplied integer.
74
  function ceil_log2 (x : in natural) return natural is
75
    variable retval          : natural;
76
  begin
77
    retval                   := 1;
78
    while ((2**retval) - 1) < x loop
79
      retval                 := retval + 1;
80
    end loop;
81
    return retval;
82
  end function;
83
 
84
  constant CONV_NANOSECS     : real := 0.000000001;
85
 
86 322 jshamlet
  constant Tas_r             : real := CONV_NANOSECS * real(Tas);
87
  constant Tpwe_r            : real := CONV_NANOSECS * real(Tpwe + Tas);
88
  constant Tcyc_r            : real := CONV_NANOSECS * real(Tcyce + Tas);
89 286 jshamlet
 
90
  constant TCYC_i            : integer := integer(Clock_Frequency * Tcyc_r);
91
  constant TCYC_BITS         : integer := ceil_log2(TCYC_i);
92
 
93
  constant TCYC_DELAY        : std_logic_vector(TCYC_BITS-1 downto 0) :=
94
                               conv_std_logic_vector(TCYC_i-1, TCYC_BITS);
95
  signal tcyc_timer          : std_logic_vector(TCYC_BITS - 1 downto 0) :=
96
                               (others => '0');
97
 
98 322 jshamlet
  constant TAS_i             : integer := integer(Clock_Frequency * Tas_r);
99
  constant TAS_DELAY         : std_logic_vector(TCYC_BITS - 1 downto 0) :=
100
                               conv_std_logic_vector(TAS_i-1,TCYC_BITS);
101 286 jshamlet
 
102 322 jshamlet
  constant TPWE_i            : integer := integer(Clock_Frequency * Tpwe_r);
103
  constant TPWE_DELAY        : std_logic_vector(TCYC_BITS-1 downto 0) :=
104
                               conv_std_logic_vector(TPWE_i-1, TCYC_BITS);
105 286 jshamlet
 
106 322 jshamlet
  type IO_STATES   is (IDLE, IO_TAS, IO_TPWE, IO_TCYC );
107 286 jshamlet
  signal io_state            : IO_STATES;
108
 
109
  signal Wr_Buffer           : std_logic_vector(8 downto 0);
110
  alias Wr_Buffer_A          is Wr_Buffer(8);
111
  alias Wr_Buffer_D          is Wr_Buffer(7 downto 0);
112
 
113
begin
114
 
115
  LCD_IO_proc: process( Clock, Reset )
116
  begin
117
    if( Reset = Reset_Level )then
118
      io_state               <= IDLE;
119
      tcyc_timer             <= (others => '0');
120
      Wr_Buffer              <= (others => '0');
121
      IO_Done                <= '0';
122
      LCD_RS                 <= '0';
123
      LCD_E                  <= '0';
124
      LCD_DQ                 <= (others => '0');
125
    elsif( rising_edge(Clock) )then
126
      IO_Done                <= '0';
127 322 jshamlet
      LCD_RS                 <= '0';
128 286 jshamlet
      LCD_E                  <= '0';
129 322 jshamlet
      LCD_DQ                 <= x"00";
130
      tcyc_timer             <= tcyc_timer + 1;
131
 
132 286 jshamlet
      case( io_state )is
133
        when IDLE =>
134 322 jshamlet
          tcyc_timer         <= (others => '0');
135 286 jshamlet
          if( Wr_En = '1' )then
136
            Wr_Buffer        <= Wr_Reg & Wr_Data;
137 322 jshamlet
            io_state         <= IO_TAS;
138 286 jshamlet
          end if;
139
 
140 322 jshamlet
        when IO_TAS =>
141 286 jshamlet
          LCD_RS             <= Wr_Buffer_A;
142 322 jshamlet
          if( tcyc_timer >= TAS_DELAY )then
143
            io_state         <= IO_TPWE;
144 286 jshamlet
          end if;
145
 
146 322 jshamlet
        when IO_TPWE =>
147
          LCD_RS             <= Wr_Buffer_A;
148 286 jshamlet
          LCD_E              <= '1';
149
          LCD_DQ             <= Wr_Buffer_D;
150 322 jshamlet
          if( tcyc_timer >= TPWE_DELAY )then
151 286 jshamlet
            io_state         <= IO_TCYC;
152
          end if;
153
 
154
        when IO_TCYC =>
155 322 jshamlet
          LCD_RS             <= Wr_Buffer_A;
156
          LCD_DQ             <= Wr_Buffer_D;
157 286 jshamlet
          if( tcyc_timer >= TCYC_DELAY )then
158 322 jshamlet
            IO_Done          <= '1';
159
            io_state         <= IDLE;
160 286 jshamlet
          end if;
161
 
162
        when others =>
163
          null;
164
      end case;
165
    end if;
166
  end process;
167
 
168
end architecture;

powered by: WebSVN 2.1.0

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