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

Subversion Repositories hd44780_driver

[/] [hd44780_driver/] [trunk/] [example_driver.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 jodb
-- Filename:     example_driver.vhd
2
-- Filetype:     VHDL Source Code
3
-- Date:         26 oct 2012
4
-- Update:       -
5
-- Description:  VHDL Description of example driver
6
-- Author:       J. op den Brouw
7
-- State:        Demo
8
-- Error:        -
9
-- Version:      1.1alpha
10
-- Copyright:    (c)2012, De Haagse Hogeschool
11
 
12
-- This VHDL code is a example description on how to use the
13
-- HD44780 LCD display driver module. It writes 4x16 characters
14
-- to the display, presuming that the display has four lines.
15
--
16
-- This code is tested on a Terasic DE0-board with an optional
17
-- LCD display. See the weblinks
18
-- http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=56&No=364
19
-- http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=78&No=396
20
-- for more info. The display used has only two lines.
21
 
22
-- After a line has written completely, the cursor is moved to
23
-- the beginning of the next line. After the last line is written,
24
-- this code goes into hold mode.
25
--
26
 
27
-- Libraries et al.
28
library ieee;
29
use ieee.std_logic_1164.all;
30
use ieee.numeric_std.all;
31
 
32
-- The entity of a Terasic DE0-board.
33
entity example_driver is
34
        port (CLOCK_50 : in std_logic;
35
                        BUTTON   : in std_logic_vector(2 downto 0);
36
                        SW       : in std_logic_vector(9 downto 0);
37
                        LEDG     : out std_logic_vector(9 downto 0);
38
                        HEX3_D   : out std_logic_vector(6 downto 0);
39
                        HEX2_D   : out std_logic_vector(6 downto 0);
40
                        HEX1_D   : out std_logic_vector(6 downto 0);
41
                        HEX0_D   : out std_logic_vector(6 downto 0);
42
                        HEX0_DP  : out std_logic;
43
                        HEX1_DP  : out std_logic;
44
                        HEX2_DP  : out std_logic;
45
                        HEX3_DP  : out std_logic;
46
                        -- LCD of the DE0 board
47
                        LCD_EN   : out std_logic;
48
                        LCD_RS   : out std_logic;
49
                        LCD_RW   : out std_logic;
50
                        LCD_DATA : inout std_logic_vector(7 downto 0);
51
                        LCD_BLON : out std_logic
52
        );
53
 
54
end entity example_driver;
55
 
56
-- The architecture!
57
architecture hardware of example_driver is
58
-- Component declaration of the LCD module
59
component lcd_driver_hd44780_module is
60
        generic (freq         : integer := 50000000;
61
                                areset_pol   : std_logic := '1';
62
                                time_init1   : time := 40 ms;
63
                                time_init2   : time := 4100 us;
64
                                time_init3   : time := 100 us;
65
                                time_tas     : time := 60 ns;
66
                                time_cycle_e : time := 1000 ns;
67
                                time_pweh    : time := 500 ns;
68
                                time_no_bf   : time := 2 ms;
69
                                cursor_on    : boolean := false;
70
                                blink_on     : boolean := false;
71
                                use_bf       : boolean := true
72
                          );
73
        port      (clk      : in std_logic;
74
                           areset   : in std_logic;
75
                           -- User site
76
                           init     : in std_logic;
77
                           data     : in std_logic_vector(7 downto 0);
78
                           wr       : in std_logic;
79
                           cls      : in std_logic;
80
                           home     : in std_logic;
81
                           goto10   : in std_logic;
82
                           goto20   : in std_logic;
83
                           goto30   : in std_logic;
84
                           busy     : out std_logic;
85
                           -- LCD side
86
                           LCD_E    : out std_logic;
87
                           LCD_RS   : out std_logic;
88
                           LCD_RW   : out std_logic;
89
                           LCD_DB   : inout std_logic_vector(7 downto 0)
90
                          );
91
end component lcd_driver_hd44780_module;
92
 
93
-- The system's frequency
94
constant sys_freq : integer := 50000000;
95
 
96
signal areset   : std_logic;
97
signal clk      : std_logic;
98
signal init     : std_logic;
99
signal data     : std_logic_vector(7 downto 0);
100
signal wr       : std_logic;
101
signal cls      : std_logic;
102
signal home     : std_logic;
103
signal goto10   : std_logic;
104
signal goto20   : std_logic;
105
signal goto30   : std_logic;
106
signal busy              : std_logic;
107
 
108
type state_type is (reset, write_char, write_char_wait, update, update_linecount,
109
                                                  update_linecount_wait, write_char_1, write_char_1_wait,
110
                                                  write_char_2, write_char_2_wait, write_char_3, write_char_4, hold);
111
signal state : state_type;
112
 
113
-- A string of 16 characters
114
subtype string16_type is string(1 to 16);
115
-- An array of 4 strings of 16 characters.
116
type message4x16_type is array (1 to 4) of string16_type;
117
 
118
-- The four-line message
119
constant message : message4x16_type :=
120
                                                        ( 1 => "1Elektrotechniek",
121
                                                          2 => "2  LCD HD44780  ",
122
                                                          3 => "3Driver in VHDL!",
123
                                                          4 => "4J. op den Brouw");
124
 
125
-- Counts the characters on a line.
126
signal character_counter : integer range 1 to 16;
127
-- Counts the lines.
128
signal line_counter : integer range 1 to 4;
129
 
130
begin
131
 
132
        -- Push buttons are active low.
133
        areset <= not BUTTON(0);
134
 
135
        -- The clock
136
        clk <= CLOCK_50;
137
 
138
        -- Use LCD module.
139
        lcdm : lcd_driver_hd44780_module
140
        generic map (freq => sys_freq, areset_pol => '1', time_cycle_e => 2000 ns, time_pweh => 500 ns,
141
                                         cursor_on => false, blink_on => false, use_bf => false)
142
        port map (clk => clk, areset => areset, init => init, data => data, wr => wr, cls => cls,
143
                                 home => home, goto10 => goto10, goto20 => goto20, goto30 => goto30, busy => busy,
144
                                 LCD_E => LCD_EN, LCD_RS => LCD_RS, LCD_RW => LCD_RW, LCD_DB => LCD_DATA);
145
 
146
        -- The client side
147
        drive: process (clk, areset) is
148
        variable aline : string16_type;
149
        begin
150
                if areset = '1' then
151
                        wr <= '0';
152
                        init <= '0';
153
                        cls <= '0';
154
                        home <= '0';
155
                        goto10 <= '0';
156
                        goto20 <= '0';
157
                        goto30 <= '0';
158
                        LEDG(0) <= '0';
159
                        data <= "00000000";
160
                        character_counter <= 1;
161
                        state <= reset;
162
                elsif rising_edge(clk) then
163
                        wr <= '0';
164
                        init <= '0';
165
                        cls <= '0';
166
                        home <= '0';
167
                        goto10 <= '0';
168
                        goto20 <= '0';
169
                        goto30 <= '0';
170
                        LEDG(0) <= '0';
171
                        data <= "00000000";
172
                        case state is
173
 
174
                                when reset =>
175
                                        -- Wait for the LCD module ready
176
                                        if busy = '0' then
177
                                                state <= write_char;
178
                                        end if;
179
                                        -- Setup message counter, start at 1.
180
                                        character_counter <= 1;
181
                                        line_counter <= 1;
182
 
183
                                when write_char =>
184
                                        LEDG(0) <= '1';
185
                                        -- Set up WRITE!
186
                                        -- Use the data from the string
187
                                        aline := message(line_counter);
188
                                        data <= std_logic_vector( to_unsigned( character'pos(aline(character_counter)),8));
189
                                        wr <= '1';
190
                                        state <= write_char_wait;
191
 
192
                                when write_char_wait =>
193
                                        -- This state is needed so that the LCD driver
194
                                        -- can process the write command. Note that data
195
                                        -- and wr are registered outputs and get their
196
                                        -- respective values while in *this* state. If you don't
197
                                        -- want this behaviour, please make your outputs
198
                                        -- non-registered.
199
                                        state <= update;
200
 
201
                                when update =>
202
                                        LEDG(0) <= '1';
203
                                        -- Wait for the write complete
204
                                        if busy = '0' then
205
                                                -- If end of string, goto hold mode...
206
                                                if line_counter = 4 and character_counter = 16 then
207
                                                        state <= hold;
208
                                                -- If end of line...    
209
                                                elsif character_counter = 16 then
210
                                                        case line_counter is
211
                                                                when 1 => goto10 <= '1';
212
                                                                when 2 => goto20 <= '1';
213
                                                                when 3 => goto30 <= '1';
214
                                                                -- Never reached, but nice anyway...
215
                                                                when 4 => home <= '1';
216
                                                                when others => null;
217
                                                        end case;
218
                                                        -- Set new values of the counters
219
                                                        line_counter <= line_counter+1;
220
                                                        character_counter <= 1;
221
                                                        -- Goto the update state
222
                                                        state <= update_linecount;
223
                                                else
224
                                                   -- Not the end of a lines, update the character counter.
225
                                                        character_counter <= character_counter+1;
226
                                                        state <= write_char;
227
                                                end if;
228
                                        end if;
229
 
230
                                when update_linecount =>
231
                                        -- This state is needed so that the LCD driver
232
                                        -- can process the gotoXX command. Note that the gotoXX
233
                                        -- signals are registered outputs and get their
234
                                        -- respective values while in *this* state. If you don't
235
                                        -- want this behaviour, please make your outputs
236
                                        -- non-registered.
237
                                        state <= update_linecount_wait;
238
 
239
                                when update_linecount_wait =>
240
                                        -- Wait for the LCD module ready
241
                                        if busy = '0' then
242
                                                state <= write_char;
243
                                        end if;
244
 
245
                                -- The "hohouwer"
246
                                when hold =>
247
                                        state <= hold;
248
 
249
                                when others =>
250
                                        null;
251
 
252
                        end case;
253
                end if;
254
        end process;
255
 
256
                -- The unused outputs...
257
        HEX3_D <= (others => '1');
258
        HEX2_D <= (others => '1');
259
        HEX1_D <= (others => '1');
260
        HEX0_D <= (others => '1');
261
 
262
        HEX3_DP <= '1';
263
        HEX2_DP <= '1';
264
        HEX1_DP <= '1';
265
        HEX0_DP <= '1';
266
 
267
        LEDG(9 downto 1) <= (others => '0');
268
 
269
        -- Sadly, the LCD doesn't have a backlight...
270
        LCD_BLON <= '0';
271
 
272
end architecture hardware;

powered by: WebSVN 2.1.0

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