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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [hd44780_4b.vhd] - Blame information for rev 333

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_4b
25
-- Description: Provides low-level timing of the control signals in 4-bit mode
26
--              (required by o8_hd44780_if)
27
--
28
-- Revision History
29
-- Author          Date     Change
30
------------------ -------- ---------------------------------------------------
31
-- Seth Henry      04/12/21 Design Start
32
 
33 286 jshamlet
library ieee;
34
  use ieee.std_logic_1164.all;
35
  use ieee.std_logic_unsigned.all;
36
  use ieee.std_logic_arith.all;
37
  use ieee.std_logic_misc.all;
38
 
39
entity hd44780_4b is
40
generic(
41 322 jshamlet
  Tas                        : integer :=   40; -- ns
42
  Tpwe                       : integer :=  250; -- nS
43
  Tcyce                      : integer := 1000; -- nS
44
  Clock_Frequency            : real    := 100000000.0; -- Hz
45 286 jshamlet
  Reset_Level                : std_logic := '1'
46
);
47
port(
48
  Clock                      : in  std_logic;
49
  Reset                      : in  std_logic;
50
  --
51
  Wr_Fnset                   : in  std_logic;
52
  Wr_Data                    : in  std_logic_vector(7 downto 0);
53
  Wr_Reg                     : in  std_logic;
54
  Wr_En                      : in  std_logic;
55
  --
56
  IO_Done                    : out std_logic;
57
  --
58
  LCD_RS                     : out std_logic;
59
  LCD_E                      : out std_logic;
60
  LCD_DQ                     : out std_logic_vector(7 downto 0)
61
);
62
end entity;
63
 
64
architecture behave of hd44780_4b is
65
 
66
  -- The ceil_log2 function returns the minimum register width required to
67
  --  hold the supplied integer.
68
  function ceil_log2 (x : in natural) return natural is
69
    variable retval          : natural;
70
  begin
71
    retval                   := 1;
72
    while ((2**retval) - 1) < x loop
73
      retval                 := retval + 1;
74
    end loop;
75
    return retval;
76
  end function;
77
 
78
  constant CONV_NANOSECS     : real := 0.000000001;
79
 
80 322 jshamlet
  constant Tas_r             : real := CONV_NANOSECS * real(Tas);
81
  constant Tpwe_r            : real := CONV_NANOSECS * real(Tpwe + Tas);
82
  constant Tcyc_r            : real := CONV_NANOSECS * real(Tcyce + Tas);
83 286 jshamlet
 
84
  constant TCYC_i            : integer := integer(Clock_Frequency * Tcyc_r);
85
  constant TCYC_BITS         : integer := ceil_log2(TCYC_i);
86
 
87
  constant TCYC_DELAY        : std_logic_vector(TCYC_BITS-1 downto 0) :=
88
                               conv_std_logic_vector(TCYC_i-1, TCYC_BITS);
89 322 jshamlet
 
90
  constant TAS_i             : integer := integer(Clock_Frequency * Tas_r);
91
  constant TAS_DELAY         : std_logic_vector(TCYC_BITS - 1 downto 0) :=
92
                               conv_std_logic_vector(TAS_i-1,TCYC_BITS);
93
 
94
  constant TPWE_i            : integer := integer(Clock_Frequency * Tpwe_r);
95
  constant TPWE_DELAY        : std_logic_vector(TCYC_BITS-1 downto 0) :=
96
                               conv_std_logic_vector(TPWE_i-1, TCYC_BITS);
97
 
98 286 jshamlet
  signal tcyc_timer          : std_logic_vector(TCYC_BITS - 1 downto 0) :=
99
                               (others => '0');
100
 
101
  type IO_STATES   is (IDLE,
102 322 jshamlet
                       TAS_UB, TPW_UB, TCYC_UB,
103 286 jshamlet
                       INIT_LB, TPW_LB, TCYC_LB,
104
                       DONE );
105
  signal io_state            : IO_STATES;
106
  signal fn_set              : std_logic;
107
 
108
  signal Wr_Buffer           : std_logic_vector(8 downto 0);
109
  alias Wr_Buffer_A          is Wr_Buffer(8);
110
  alias Wr_Buffer_U          is Wr_Buffer(7 downto 4);
111
  alias Wr_Buffer_L          is Wr_Buffer(3 downto 0);
112
 
113
  alias LCD_DQ_U             is LCD_DQ(7 downto 4);
114
  alias LCD_DQ_L             is LCD_DQ(3 downto 0);
115
 
116
begin
117
 
118
  LCD_IO_proc: process( Clock, Reset )
119
  begin
120
    if( Reset = Reset_Level )then
121
      io_state               <= IDLE;
122
      fn_set                 <= '0';
123
      tcyc_timer             <= (others => '0');
124
      Wr_Buffer              <= (others => '0');
125
      IO_Done                <= '0';
126
      LCD_RS                 <= '0';
127
      LCD_E                  <= '0';
128
      LCD_DQ                 <= (others => '0');
129
    elsif( rising_edge(Clock) )then
130
      IO_Done                <= '0';
131 322 jshamlet
      LCD_RS                 <= '0';
132 286 jshamlet
      LCD_E                  <= '0';
133 322 jshamlet
      LCD_DQ_U               <= (others => '0');
134 286 jshamlet
      LCD_DQ_L               <= (others => '0');
135 322 jshamlet
      tcyc_timer             <= tcyc_timer + 1;
136
 
137 286 jshamlet
      case( io_state )is
138
        when IDLE =>
139 322 jshamlet
          tcyc_timer         <= (others => '0');
140 286 jshamlet
          if( Wr_En = '1' )then
141
            Wr_Buffer        <= Wr_Reg & Wr_Data;
142
            fn_set           <= Wr_Fnset;
143 322 jshamlet
            io_state         <= TAS_UB;
144 286 jshamlet
          end if;
145
 
146 322 jshamlet
        when TAS_UB =>
147 286 jshamlet
          LCD_RS             <= Wr_Buffer_A;
148 322 jshamlet
          if( tcyc_timer >= TAS_DELAY )then
149 286 jshamlet
            io_state         <= TPW_UB;
150
          end if;
151
 
152
        when TPW_UB =>
153 322 jshamlet
          LCD_RS             <= Wr_Buffer_A;
154 286 jshamlet
          LCD_E              <= '1';
155
          LCD_DQ_U           <= Wr_Buffer_U;
156 322 jshamlet
          if( tcyc_timer >= TPWE_DELAY )then
157 286 jshamlet
            io_state         <= TCYC_UB;
158
          end if;
159
 
160
        when TCYC_UB =>
161 322 jshamlet
          LCD_RS             <= Wr_Buffer_A;
162
          LCD_DQ_U           <= Wr_Buffer_U;
163 286 jshamlet
          if( tcyc_timer >= TCYC_DELAY )then
164
            io_state         <= INIT_LB;
165
          end if;
166
 
167
        when INIT_LB =>
168 322 jshamlet
          tcyc_timer         <= TAS_DELAY;
169
          LCD_RS             <= Wr_Buffer_A;
170
          LCD_DQ_U           <= Wr_Buffer_U;
171 286 jshamlet
          io_state           <= TPW_LB;
172
          if( fn_set = '1' )then
173
            fn_set           <= '0';
174
            io_state         <= TPW_UB;
175
          end if;
176
 
177
        when TPW_LB =>
178 322 jshamlet
          LCD_RS             <= Wr_Buffer_A;
179 286 jshamlet
          LCD_E              <= '1';
180
          LCD_DQ_U           <= Wr_Buffer_L;
181 322 jshamlet
          if( tcyc_timer >= TPWE_DELAY )then
182 286 jshamlet
            io_state         <= TCYC_LB;
183
          end if;
184
 
185
        when TCYC_LB =>
186 322 jshamlet
          LCD_RS             <= Wr_Buffer_A;
187
          LCD_DQ_U           <= Wr_Buffer_L;
188 286 jshamlet
          if( tcyc_timer >= TCYC_DELAY )then
189 322 jshamlet
            IO_Done          <= '1';
190
            io_state         <= IDLE;
191 286 jshamlet
          end if;
192
 
193
        when others =>
194
          null;
195
      end case;
196
    end if;
197
  end process;
198
 
199
end architecture;

powered by: WebSVN 2.1.0

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