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 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_8b 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_Data                    : in  std_logic_vector(7 downto 0);
20
  Wr_Reg                     : in  std_logic;
21
  Wr_En                      : in  std_logic;
22
  --
23
  IO_Done                    : out std_logic;
24
  --
25
  LCD_RS                     : out std_logic;
26
  LCD_E                      : out std_logic;
27
  LCD_DQ                     : out std_logic_vector(7 downto 0)
28
);
29
end entity;
30
 
31
architecture behave of hd44780_8b is
32
 
33
  -- The ceil_log2 function returns the minimum register width required to
34
  --  hold the supplied integer.
35
  function ceil_log2 (x : in natural) return natural is
36
    variable retval          : natural;
37
  begin
38
    retval                   := 1;
39
    while ((2**retval) - 1) < x loop
40
      retval                 := retval + 1;
41
    end loop;
42
    return retval;
43
  end function;
44
 
45
  constant CONV_NANOSECS     : real := 0.000000001;
46
 
47
  constant Tsu_r             : real := CONV_NANOSECS * real(Tsu);
48
  constant Tpw_r             : real := CONV_NANOSECS * real(Tpw);
49
  constant Tcyc_r            : real := CONV_NANOSECS * real(Tcyc);
50
 
51
  constant TCYC_i            : integer := integer(Clock_Frequency * Tcyc_r);
52
  constant TCYC_BITS         : integer := ceil_log2(TCYC_i);
53
 
54
  constant TCYC_DELAY        : std_logic_vector(TCYC_BITS-1 downto 0) :=
55
                               conv_std_logic_vector(TCYC_i-1, TCYC_BITS);
56
  signal tcyc_timer          : std_logic_vector(TCYC_BITS - 1 downto 0) :=
57
                               (others => '0');
58
 
59
  constant TPW_i             : integer := integer(Clock_Frequency * Tpw_r);
60
  constant TPW_DELAY         : std_logic_vector(TCYC_BITS-1 downto 0) :=
61
                               conv_std_logic_vector(TPW_i-1, TCYC_BITS);
62
 
63
  constant TSU_i             : integer := integer(Clock_Frequency * Tsu_r);
64
  constant TSU_BITS          : integer := ceil_log2(TSU_i);
65
  constant TSU_DELAY         : std_logic_vector(TSU_BITS - 1 downto 0) :=
66
                               conv_std_logic_vector(TSU_i-1,TSU_BITS);
67
  signal tsnh_timer          : std_logic_vector(TSU_BITS-1 downto 0) :=
68
                                (others => '0');
69
 
70
  type IO_STATES   is (IDLE, INIT, IO_TAS, IO_TPW, IO_TCYC, DONE );
71
  signal io_state            : IO_STATES;
72
 
73
  signal Wr_Buffer           : std_logic_vector(8 downto 0);
74
  alias Wr_Buffer_A          is Wr_Buffer(8);
75
  alias Wr_Buffer_D          is Wr_Buffer(7 downto 0);
76
 
77
begin
78
 
79
  LCD_IO_proc: process( Clock, Reset )
80
  begin
81
    if( Reset = Reset_Level )then
82
      io_state               <= IDLE;
83
      tcyc_timer             <= (others => '0');
84
      tsnh_timer             <= (others => '0');
85
      Wr_Buffer              <= (others => '0');
86
      IO_Done                <= '0';
87
      LCD_RS                 <= '0';
88
      LCD_E                  <= '0';
89
      LCD_DQ                 <= (others => '0');
90
    elsif( rising_edge(Clock) )then
91
      IO_Done                <= '0';
92
      LCD_E                  <= '0';
93
      case( io_state )is
94
        when IDLE =>
95
          if( Wr_En = '1' )then
96
            Wr_Buffer        <= Wr_Reg & Wr_Data;
97
            io_state         <= INIT;
98
          end if;
99
 
100
        when INIT =>
101
          tsnh_timer         <= TSU_DELAY;
102
          tcyc_timer         <= (others => '0');
103
          LCD_RS             <= Wr_Buffer_A;
104
          io_state           <= IO_TAS;
105
 
106
        when IO_TAS =>
107
          tsnh_timer         <= tsnh_timer - 1;
108
          if( or_reduce(tsnh_timer) = '0' )then
109
            io_state         <= IO_TPW;
110
          end if;
111
 
112
        when IO_TPW =>
113
          tcyc_timer         <= tcyc_timer + 1;
114
          LCD_E              <= '1';
115
          LCD_DQ             <= Wr_Buffer_D;
116
          if( tcyc_timer = TPW_DELAY )then
117
            io_state         <= IO_TCYC;
118
          end if;
119
 
120
        when IO_TCYC =>
121
          tcyc_timer         <= tcyc_timer + 1;
122
          if( tcyc_timer >= TCYC_DELAY )then
123
            io_state         <= DONE;
124
          end if;
125
 
126
        when DONE =>
127
          IO_Done            <= '1';
128
          LCD_RS             <= '0';
129
          LCD_DQ             <= (others => '0');
130
          io_state           <= IDLE;
131
 
132
        when others =>
133
          null;
134
      end case;
135
    end if;
136
  end process;
137
 
138
end architecture;

powered by: WebSVN 2.1.0

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