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

Subversion Repositories lcd1

[/] [lcd1/] [trunk/] [src/] [BACKUP/] [lcd.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimo
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
 
6
entity lcd is
7
    Port ( lcd_data   : out std_logic_vector (7 downto 4);
8
           clk        : in  std_logic;
9
           reset      : in  std_logic;
10
           lcd_enable : out STD_LOGIC_VECTOR (1 DOWNTO 0);
11
           lcd_rs     : out std_logic;
12
           lcd_rw     : out std_logic
13
         );
14
end lcd ;
15
 
16
architecture behavioural of lcd is
17
 
18
    type state_type is (warmup, setfunc, clear1, clear2, setmode1, setmode2, write1, home1, home2);
19
 
20
    signal state : state_type;
21
 
22
    attribute syn_state_machine : boolean;
23
    attribute syn_state_machine of state : signal is true;
24
 
25
    signal count    : std_logic_vector(3 downto 0);
26
    signal finished : std_logic;         -- set high if done write cycle
27
 
28
    signal  char_mode : std_logic_vector(1 downto 0);
29
 
30
    --defining the display
31
    constant N: integer :=8;
32
    type arr is array (1 to N) of std_logic_vector(7 downto 0);
33
 
34
    constant display_char1 : arr :=    (x"A0",  --blank
35
                                        X"68",  --h
36
                                        X"74",  --t
37
                                        X"74",  --t
38
                                        X"70",  --p
39
                                        X"3A",  --:
40
                                        X"2F",  --/
41
                                        X"2F"); --/
42
 
43
    constant display_char2 : arr :=    (X"77",  --w
44
                                        X"77",  --w
45
                                        X"77",  --w
46
                                        X"2E",  --.
47
                                        X"66",  --f
48
                                        X"70",  --p
49
                                        X"67",  --g
50
                                        X"61"); --a
51
 
52
    constant display_char3 : arr :=    (X"2E",  --.
53
                                        X"62",  --b
54
                                        X"65",  --e
55
                                        X"88",  --blank
56
                                        X"88",  --blank
57
                                        X"88",  --blank
58
                                        X"88",  --blank
59
                                        X"88"); --blank
60
 
61
    constant display_char4 : arr :=    (X"A0",  --blank
62
                                        X"88",  --blank
63
                                        X"58",  --X
64
                                        X"49",  --I
65
                                        X"4F",  --O
66
                                        X"53",  --S
67
                                        X"88",  --blank
68
                                        X"88"); --blank
69
 
70
    signal display_char : arr;
71
 
72
begin
73
    lcd_rw <= '0';
74
    lcd_enable(1) <= clk; --not clk;  -- this is very important! if enable is not pulsed, lcd will not write
75
    lcd_enable(0) <= clk;
76
 
77
    char_mode_process: process (char_mode)
78
    begin
79
        case char_mode  is
80
            when "00" =>
81
                display_char <= display_char1;
82
            when "01" =>
83
                display_char <= display_char2;
84
            when "10" =>
85
                display_char <= display_char3;
86
            when "11" =>
87
                display_char <= display_char4;
88
            when OTHERS  =>
89
                display_char <= display_char1;
90
         end case;
91
    end process;
92
 
93
    state_set: process (clk, reset, finished)
94
    begin
95
      if (reset = '1') then
96
 
97
         state     <= warmup;   --setfunc;
98
         count     <= (others => '0');
99
         char_mode <= (others => '0');
100
 
101
      elsif (clk'event and clk = '1') then
102
         case state is
103
 
104
            when warmup =>
105
               lcd_rs <= '0';
106
               lcd_data <= "0011"; --"0000";  -- do nothing
107
               if count = "0111" then  --0111
108
                  count <= (others => '0');
109
                  state <= setfunc;
110
               else
111
                  count <= count + '1';
112
                  state <= warmup;
113
               end if;
114
 
115
            when setfunc =>
116
               lcd_rs <= '0';
117
               lcd_data <= "0010";
118
               finished <= '0';
119
 
120
               if count = "0010" then  --0010
121
                  count <= (others => '0');
122
                  state <= clear1;
123
               else
124
                  count <= count + '1';
125
                  state <= setfunc;
126
               end if;
127
 
128
            when clear1 =>
129
 
130
               lcd_rs <= '0';
131
               lcd_data <= "0000";
132
               state <= clear2;
133
 
134
            when clear2 =>
135
               lcd_rs <= '0';
136
               if count = "0111" then
137
                    state <= setmode1;
138
                    count <= (others => '0');
139
                    lcd_data <= "1111";
140
               else
141
                    count <= count + '1';
142
                    lcd_data <= "0001";
143
                    state <= clear1;
144
               end if;
145
 
146
            when setmode1 =>
147
               lcd_rs   <= '0';
148
               lcd_data <= "0000";
149
               state    <= setmode2;
150
               finished <= '0';
151
 
152
            when setmode2 =>
153
               lcd_rs   <= '0';
154
               lcd_data <= "0110";
155
               state    <= write1;
156
 
157
            when write1 =>
158
               if finished = '1' then
159
                  state <= home1;
160
               else
161
                  lcd_rs <= '1';
162
                  count  <= count  + '1';
163
                  state  <= write1;
164
 
165
                  CASE count IS
166
 
167
                     WHEN "0000" =>
168
                         lcd_data <= display_char(1)(7 downto 4);
169
 
170
                     WHEN "0001" =>
171
                         lcd_data <= display_char(1)(3 downto 0);
172
 
173
                     WHEN "0010" =>
174
                         lcd_data <= display_char(2)(7 downto 4);
175
 
176
                     WHEN "0011" =>
177
                         lcd_data <= display_char(2)(3 downto 0);
178
 
179
                     WHEN "0100"=>
180
                         lcd_data <= display_char(3)(7 downto 4);
181
 
182
                     WHEN "0101"=>
183
                         lcd_data <= display_char(3)(3 downto 0);
184
 
185
                     WHEN "0110"=>
186
                         lcd_data <= display_char(4)(7 downto 4);
187
 
188
                     WHEN "0111"=>
189
                         lcd_data <= display_char(4)(3 downto 0);
190
 
191
                     WHEN "1000" =>
192
                         lcd_data <= display_char(5)(7 downto 4);
193
 
194
                     WHEN "1001" =>
195
                         lcd_data <= display_char(5)(3 downto 0);
196
 
197
                     WHEN "1010" =>
198
                         lcd_data <= display_char(6)(7 downto 4);
199
 
200
                     WHEN "1011" =>
201
                         lcd_data <= display_char(6)(3 downto 0);
202
 
203
                     WHEN "1100" =>
204
                         lcd_data <= display_char(7)(7 downto 4);
205
 
206
                     WHEN "1101" =>
207
                         lcd_data <= display_char(7)(3 downto 0);
208
 
209
                     WHEN "1110" =>
210
                         lcd_data <= display_char(8)(7 downto 4);
211
                         --finished <= '1';  -- needed to set done low before valid data is gone
212
                         --char_mode  <= char_mode + '1';
213
 
214
                    WHEN "1111" =>
215
                         lcd_data <= display_char(8)(3 downto 0);
216
                         finished <= '1';  -- needed to set done low before valid data is gone
217
                         char_mode  <= char_mode + '1';
218
 
219
                     WHEN OTHERS =>
220
                         lcd_data <= "0000";  -- ' '
221
 
222
                  END CASE;
223
               end if;
224
 
225
            when home1 =>
226
               lcd_rs <= '0';
227
               lcd_data <= "0000";
228
               state <= home2;
229
               finished <= '0';
230
               count <= (others => '0');
231
 
232
            when home2 =>
233
               lcd_rs <= '0';
234
               lcd_data <= "0111";
235
               state <= write1;
236
 
237
         end case;
238
 
239
      end if;
240
 
241
   end process;
242
 
243
end behavioural;

powered by: WebSVN 2.1.0

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