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 286

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

Line No. Rev Author Line
1 286 jshamlet
library ieee;
2
  use ieee.std_logic_1164.all;
3
  use ieee.std_logic_unsigned.all;
4
  use ieee.std_logic_arith.all;
5
  use ieee.std_logic_misc.all;
6
 
7
entity hd44780_4b is
8
generic(
9
  Tsu                        : integer :=  40; -- ns
10
  Tpw                        : integer := 250; -- nS
11
  Tcyc                       : integer := 500; -- nS
12
  Clock_Frequency            : real    := 50000000.0; -- Hz
13
  Reset_Level                : std_logic := '1'
14
);
15
port(
16
  Clock                      : in  std_logic;
17
  Reset                      : in  std_logic;
18
  --
19
  Wr_Fnset                   : in  std_logic;
20
  Wr_Data                    : in  std_logic_vector(7 downto 0);
21
  Wr_Reg                     : in  std_logic;
22
  Wr_En                      : in  std_logic;
23
  --
24
  IO_Done                    : out std_logic;
25
  --
26
  LCD_RS                     : out std_logic;
27
  LCD_E                      : out std_logic;
28
  LCD_DQ                     : out std_logic_vector(7 downto 0)
29
);
30
end entity;
31
 
32
architecture behave of hd44780_4b is
33
 
34
  -- The ceil_log2 function returns the minimum register width required to
35
  --  hold the supplied integer.
36
  function ceil_log2 (x : in natural) return natural is
37
    variable retval          : natural;
38
  begin
39
    retval                   := 1;
40
    while ((2**retval) - 1) < x loop
41
      retval                 := retval + 1;
42
    end loop;
43
    return retval;
44
  end function;
45
 
46
  constant CONV_NANOSECS     : real := 0.000000001;
47
 
48
  constant Tsu_r             : real := CONV_NANOSECS * real(Tsu);
49
  constant Tpw_r             : real := CONV_NANOSECS * real(Tpw);
50
  constant Tcyc_r            : real := CONV_NANOSECS * real(Tcyc);
51
 
52
  constant TCYC_i            : integer := integer(Clock_Frequency * Tcyc_r);
53
  constant TCYC_BITS         : integer := ceil_log2(TCYC_i);
54
 
55
  constant TCYC_DELAY        : std_logic_vector(TCYC_BITS-1 downto 0) :=
56
                               conv_std_logic_vector(TCYC_i-1, TCYC_BITS);
57
  signal tcyc_timer          : std_logic_vector(TCYC_BITS - 1 downto 0) :=
58
                               (others => '0');
59
 
60
  constant TPW_i             : integer := integer(Clock_Frequency * Tpw_r);
61
  constant TPW_DELAY         : std_logic_vector(TCYC_BITS-1 downto 0) :=
62
                               conv_std_logic_vector(TPW_i-1, TCYC_BITS);
63
 
64
  constant TSU_i             : integer := integer(Clock_Frequency * Tsu_r);
65
  constant TSU_BITS          : integer := ceil_log2(TSU_i);
66
  constant TSU_DELAY         : std_logic_vector(TSU_BITS - 1 downto 0) :=
67
                               conv_std_logic_vector(TSU_i-1,TSU_BITS);
68
  signal tsnh_timer          : std_logic_vector(TSU_BITS-1 downto 0) :=
69
                                (others => '0');
70
 
71
  type IO_STATES   is (IDLE,
72
                       INIT_UB, TAS_UB, TPW_UB, TCYC_UB,
73
                       INIT_LB, TPW_LB, TCYC_LB,
74
                       DONE );
75
  signal io_state            : IO_STATES;
76
  signal fn_set              : std_logic;
77
 
78
  signal Wr_Buffer           : std_logic_vector(8 downto 0);
79
  alias Wr_Buffer_A          is Wr_Buffer(8);
80
  alias Wr_Buffer_U          is Wr_Buffer(7 downto 4);
81
  alias Wr_Buffer_L          is Wr_Buffer(3 downto 0);
82
 
83
  alias LCD_DQ_U             is LCD_DQ(7 downto 4);
84
  alias LCD_DQ_L             is LCD_DQ(3 downto 0);
85
 
86
begin
87
 
88
  LCD_IO_proc: process( Clock, Reset )
89
  begin
90
    if( Reset = Reset_Level )then
91
      io_state               <= IDLE;
92
      fn_set                 <= '0';
93
      tcyc_timer             <= (others => '0');
94
      tsnh_timer             <= (others => '0');
95
      Wr_Buffer              <= (others => '0');
96
      IO_Done                <= '0';
97
      LCD_RS                 <= '0';
98
      LCD_E                  <= '0';
99
      LCD_DQ                 <= (others => '0');
100
    elsif( rising_edge(Clock) )then
101
      IO_Done                <= '0';
102
      LCD_E                  <= '0';
103
      LCD_DQ_L               <= (others => '0');
104
      case( io_state )is
105
        when IDLE =>
106
          if( Wr_En = '1' )then
107
            Wr_Buffer        <= Wr_Reg & Wr_Data;
108
            fn_set           <= Wr_Fnset;
109
            io_state         <= INIT_UB;
110
          end if;
111
 
112
        when INIT_UB =>
113
          tsnh_timer         <= TSU_DELAY;
114
          tcyc_timer         <= (others => '0');
115
          LCD_RS             <= Wr_Buffer_A;
116
          io_state           <= TAS_UB;
117
 
118
        when TAS_UB =>
119
          tsnh_timer         <= tsnh_timer - 1;
120
          if( or_reduce(tsnh_timer) = '0' )then
121
            io_state         <= TPW_UB;
122
          end if;
123
 
124
        when TPW_UB =>
125
          tcyc_timer         <= tcyc_timer + 1;
126
          LCD_E              <= '1';
127
          LCD_DQ_U           <= Wr_Buffer_U;
128
          if( tcyc_timer = TPW_DELAY )then
129
            io_state         <= TCYC_UB;
130
          end if;
131
 
132
        when TCYC_UB =>
133
          tcyc_timer         <= tcyc_timer + 1;
134
          if( tcyc_timer >= TCYC_DELAY )then
135
            io_state         <= INIT_LB;
136
          end if;
137
 
138
        when INIT_LB =>
139
          tcyc_timer         <= (others => '0');
140
          io_state           <= TPW_LB;
141
          if( fn_set = '1' )then
142
            fn_set           <= '0';
143
            io_state         <= TPW_UB;
144
          end if;
145
 
146
        when TPW_LB =>
147
          tcyc_timer         <= tcyc_timer + 1;
148
          LCD_E              <= '1';
149
          LCD_DQ_U           <= Wr_Buffer_L;
150
          if( tcyc_timer = TPW_DELAY )then
151
            io_state         <= TCYC_LB;
152
          end if;
153
 
154
        when TCYC_LB =>
155
          tcyc_timer         <= tcyc_timer + 1;
156
          if( tcyc_timer >= TCYC_DELAY )then
157
            io_state         <= DONE;
158
          end if;
159
 
160
        when DONE =>
161
          IO_Done            <= '1';
162
          LCD_RS             <= '0';
163
          LCD_DQ_U           <= (others => '0');
164
          io_state           <= IDLE;
165
 
166
        when others =>
167
          null;
168
      end case;
169
    end if;
170
  end process;
171
 
172
end architecture;

powered by: WebSVN 2.1.0

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