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

Subversion Repositories graphicallcd

[/] [graphicallcd/] [trunk/] [test_lcd.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 maihde
-------------------------------------------------------------------------------
2
-- This tests the graphical lcd code
3
-------------------------------------------------------------------------------
4
library IEEE;
5
use IEEE.std_logic_1164.all;
6
use IEEE.std_logic_arith.all;
7
use IEEE.std_logic_unsigned.all;
8
 
9
entity test_lcd is
10
 
11
  port (
12
    DONE  : out   std_logic;
13
    E     : out   std_logic;
14
    R_W   : out   std_logic;
15
    CS1   : out   std_logic;
16
    CS2   : out   std_logic;
17
    D_I   : out   std_logic;
18
    DB    : inout std_logic_vector(7 downto 0);
19
    CLK   : in    std_logic;
20
    RST   : in    std_logic;
21
    RAM_DIS : out std_logic);
22
 
23
end test_lcd;
24
 
25
architecture behavioral of test_lcd is
26
  component graphical_lcd
27
    port (
28
      E     : out   std_logic;
29
      R_W   : out   std_logic;
30
      CS1   : out   std_logic;
31
      CS2   : out   std_logic;
32
      D_I   : out   std_logic;
33
      DB    : inout std_logic_vector(7 downto 0);
34
      CLK_I : in    std_logic;
35
      RST_I : in    std_logic;
36
      DAT_I : in    std_logic_vector(7 downto 0);
37
      DAT_O : out   std_logic_vector(7 downto 0);
38
      ACK_O : out   std_logic;
39
      STB_I : in    std_logic;
40
      WE_I  : in    std_logic;
41
      TGD_I : in    std_logic_vector(2 downto 0));
42
  end component;
43
 
44
  signal E_i     : std_logic;
45
  signal R_W_i   : std_logic;
46
  signal CS1_i   : std_logic;
47
  signal CS2_i   : std_logic;
48
  signal D_I_i   : std_logic;
49
  signal DB_i    : std_logic_vector(7 downto 0);
50
  signal CLK_i : std_logic;
51
  signal RST_i : std_logic;
52
  signal DAT_O_i : std_logic_vector(7 downto 0);
53
  signal DAT_I_i : std_logic_vector(7 downto 0);
54
  signal ACK_i : std_logic;
55
  signal STB_i : std_logic;
56
  signal WE_i  : std_logic;
57
  signal TGD_i : std_logic_vector(2 downto 0);
58
 
59
  signal page : std_logic_vector(3 downto 0);
60
  signal addr : std_logic_vector(6 downto 0);
61
  signal lcd_wr : std_logic;
62
  signal lcd_rd : std_logic;
63
 
64
  type lcd_state_type is (LCD_IDLE, LCD_DO_WR, LCD_DO_RD, LCD_WR_DONE, LCD_RD_DONE, LCD_READ_STATUS, LCD_STATUS_DONE, LCD_CHK_BUSY, LCD_WAIT_CLEAR);
65
  type state_type is (IDLE, TURN_ON, SET_PAGE, SET_ADDR, DRAW_DATA, WAIT_COMPLETE, HALT);
66
 
67
  signal cur_state : state_type;
68
  signal next_state : state_type;
69
  signal lcd_state : lcd_state_type;
70
  signal d_i_int : std_logic;
71
  signal cs1_int : std_logic;
72
  signal cs2_int : std_logic;
73
begin  -- behavioral
74
 
75
  -- Map all the signals to the proper ports
76
  E <= E_i;
77
  R_W <= R_W_i;
78
  CS1 <= CS1_i;
79
  CS2 <= CS2_i;
80
  D_I <= D_I_i;
81
  CLK_i <= CLK;
82
  RST_i <= RST;
83
  DONE <= '1' when (cur_state = HALT) else '0';
84
  RAM_DIS <= '1'; -- disable 'Flash RAM'
85
  TGD_i(1) <= cs1_int;
86
  TGD_i(2) <= cs2_int;
87
 
88
  lcd_op: process (CLK_i, RST_i)
89
  begin  -- process
90
    if RST_i = '1' then                 -- asynchronous reset (active low)
91
      lcd_state <= LCD_IDLE;
92
         STB_i <= '0';
93
         WE_i <= '0';
94
         TGD_i(0) <= '0';
95
    elsif CLK_i'event and CLK_i = '1' then  -- rising clock edge
96
      case lcd_state is
97
        when LCD_IDLE =>
98
          STB_i <= '0';
99
          WE_i <= '0';
100
                TGD_i(0) <= d_i_int;
101
          if lcd_wr = '1' then
102
            lcd_state <= LCD_DO_WR;
103
          elsif lcd_rd = '1' then
104
            lcd_state <= LCD_DO_RD;
105
          else
106
            lcd_state <= LCD_IDLE;
107
          end if;
108
 
109
        when LCD_DO_WR =>
110
          STB_i <= '1';
111
          WE_i <= '1';
112
                TGD_i(0) <= d_i_int;
113
          if (ACK_i = '1') then
114
            lcd_state <= LCD_WR_DONE;
115
          end if;
116
 
117
        when LCD_WR_DONE =>
118
          STB_i <= '0';
119
          WE_i <= '0';
120
                TGD_i(0) <= d_i_int;
121
          if (ACK_i = '0') then
122
            lcd_state <= LCD_READ_STATUS;
123
          end if;
124
 
125
        when LCD_DO_RD =>
126
          STB_i <= '1';
127
          WE_i <= '0';
128
                TGD_i(0) <= '0';
129
          if (ACK_i = '1') then
130
            lcd_state <= LCD_RD_DONE;
131
          end if;
132
 
133
        when LCD_RD_DONE =>
134
          STB_i <= '0';
135
          WE_i <= '0';
136
                TGD_i(0) <= '0';
137
          if (ACK_i = '0') then
138
            lcd_state <= LCD_READ_STATUS;
139
          end if;
140
 
141
        when LCD_READ_STATUS =>
142
          STB_i <= '1';
143
          WE_i <= '0';
144
                TGD_i(0) <= '0';
145
          if (ACK_i = '1') then
146
            lcd_state <= LCD_STATUS_DONE;
147
          end if;
148
 
149
        when LCD_STATUS_DONE =>
150
          STB_i <= '0';
151
          WE_i <= '0';
152
                TGD_i(0) <= '0';
153
          if (ACK_i = '0') then
154
            lcd_state <=  LCD_CHK_BUSY;
155
          end if;
156
 
157
        when LCD_CHK_BUSY =>
158
          if (DAT_O_i(7) = '0') then
159
            lcd_state <= LCD_WAIT_CLEAR;
160
                else
161
                  lcd_state <= LCD_READ_STATUS;
162
          end if;
163
 
164
        when LCD_WAIT_CLEAR =>
165
          if (lcd_wr = '0') and (lcd_rd = '0') and (ACK_i = '0') then
166
            lcd_state <= LCD_IDLE;
167
          else
168
                  lcd_state <= LCD_WAIT_CLEAR;
169
          end if;
170
 
171
        when others => null;
172
      end case;
173
    end if;
174
  end process;
175
 
176
  -- Draw lines on the lcd
177
  draw: process (CLK_i, RST_i)
178
  begin  -- process draw
179
    if RST_i = '1' then
180
      cur_state <= IDLE;
181
      next_state <= IDLE;
182
      d_i_int <= '0';
183
         cs1_int <= '1';
184
         cs2_int <= '1';
185
      DAT_I_i <= "00000000";
186
      lcd_wr <= '0';
187
      lcd_rd <= '0';
188
      page <= "0000";
189
      addr <= "0000000";
190
    elsif CLK_i'event and CLK_i = '1' then
191
      case cur_state is
192
        when IDLE =>
193
          lcd_wr <= '0';
194
          lcd_rd <= '0';
195
                d_i_int <= '0';
196
                cs1_int <= '1';
197
                cs2_int <= '1';
198
          cur_state <= TURN_ON;
199
 
200
        when TURN_ON =>
201
          DAT_I_i <= "00111111";
202
          d_i_int <= '0';
203
                cs1_int <= '0';
204
                cs2_int <= '0';
205
          lcd_wr <= '1';
206
          next_state <= SET_PAGE;
207
          cur_state <= WAIT_COMPLETE;
208
 
209
        when SET_PAGE =>
210
          DAT_I_i  <= "10111" & page(2 downto 0);
211
          d_i_int <= '0';
212
          cs1_int <= '0';
213
                cs2_int <= '0';
214
          lcd_wr <= '1';
215
          addr <= "0000000";
216
          if (page /= "1000") then
217
            next_state <= SET_ADDR;
218
          else
219
            next_state <= HALT;
220
          end if;
221
          cur_state <= WAIT_COMPLETE;
222
 
223
        when SET_ADDR =>
224
          DAT_I_i  <= "01" & addr(5 downto 0);
225
          d_i_int <= '0';
226
                cs1_int <= '0';
227
          cs2_int <= '0';
228
                lcd_wr <= '1';
229
          next_state <= DRAW_DATA;
230
          cur_state <= WAIT_COMPLETE;
231
 
232
        when DRAW_DATA =>
233
          DAT_I_i  <= "01011010";
234
          d_i_int <= '1';
235
          cs1_int <= '0';
236
                cs2_int <= '0';
237
          lcd_wr <= '1';
238
          if (addr /= "1000000") then
239
                  addr <= addr + 1;
240
            next_state <= DRAW_DATA;
241
          else
242
            page <= page + 1;
243
            next_state <= SET_PAGE;
244
          end if;
245
          cur_state <= WAIT_COMPLETE;
246
 
247
        when WAIT_COMPLETE =>
248
          lcd_wr <= '0';
249
          lcd_rd <= '0';
250
          if lcd_state = LCD_WAIT_CLEAR then
251
            cur_state <= next_state;
252
          end if;
253
 
254
        when HALT =>
255
          cur_state <= HALT;
256
 
257
        when others => null;
258
      end case;
259
    end if;
260
  end process draw;
261
 
262
  lcd_cntrl: graphical_lcd
263
    port map (
264
        E     => E_i,
265
        R_W   => R_W_i,
266
        CS1   => CS1_i,
267
        CS2   => CS2_i,
268
        D_I   => D_I_i,
269
        DB    => DB,
270
        CLK_I => CLK_i,
271
        RST_I => RST_i,
272
        DAT_I => DAT_I_i,
273
        DAT_O => DAT_O_i,
274
        ACK_O => ACK_i,
275
        STB_I => STB_i,
276
        WE_I  => WE_i,
277
        TGD_I => TGD_i);
278
 
279
 
280
end behavioral;
281
 

powered by: WebSVN 2.1.0

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