OpenCores
URL https://opencores.org/ocsvn/16x2_lcd_display_driver/16x2_lcd_display_driver/trunk

Subversion Repositories 16x2_lcd_display_driver

[/] [16x2_lcd_display_driver/] [trunk/] [rtl/] [lcd_fpga.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jagadeeshj
/*
2
16x2 LCD DEMO
3
DESCRIPTION
4
        Demo for 16X2 LCD.
5
        Example Hello World!
6
IO DETAILS
7
        clk             >>      Clock
8
        rst             >>      Reset
9
        start   >>      Start process
10
        rs              >>      LCD Register select
11
        en              >>      LCD Enable
12
        lcd_data        >>      LCD Data pins
13
AUTHOR:
14
        Name:   Jagadeesh J
15
        Email:  jagadeeshj@kenosys.in
16
        Tel:    +91-8098701730
17
COMPANY:
18
        KENOSYS EMBEDDED SOLUTIONS, SALEM, TAMILNADU, INDIA
19
 
20
 This program is free software: you can redistribute it and/or modify
21
   it under the terms of the GNU General Public License as published by
22
   the Free Software Foundation, either version 3 of the License, or
23
   (at your option) any later version.
24
 
25
   This program is distributed in the hope that it will be useful,
26
   but WITHOUT ANY WARRANTY; without even the implied warranty of
27
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
   GNU General Public License for more details.
29
 
30
   You should have received a copy of the GNU General Public License
31
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
32
 
33
 */
34
 module lcd_fpga (
35
        input clk,rst,start,
36
        output rs,en,
37
        output [7:0]lcd_data
38
);
39
 
40
parameter SIZE = 5'd16; //SIZE OF MEMORY
41
reg [7:0]mem[0:SIZE-1];
42
reg [7:0]data_reg, data_next;
43
reg [1:0]state_reg, state_next;
44
reg [3:0]count_reg, count_next;
45
reg cd_next, cd_reg;
46
reg d_start_reg, d_start_next;
47
wire done_tick;
48
 
49
initial
50
begin
51
        mem[0] = 8'h38;          //LCD_mode 8 bit
52
        mem[1] = 8'h06;         //Entry mode
53
        mem[2] = 8'h0E;         //Curson on
54
        mem[3] = 8'h01;         //Clear Display
55
        mem[4] = 8'h48;         //H
56
        mem[5] = 8'h45;         //E
57
        mem[6] = 8'h4C;         //L
58
        mem[7] = 8'h4C;         //L
59
        mem[8] = 8'h4F;         //O
60
        mem[9] = 8'h20;         // 
61
        mem[10] = 8'h57;        //W     
62
        mem[11] = 8'h4F;        //O
63
        mem[12] = 8'h52;        //R
64
        mem[13] = 8'h4C;        //L
65
        mem[14] = 8'h44;        //D
66
        mem[15] = 8'h21;        //!
67
end
68
 
69
//States
70
localparam [1:0] IDLE            = 2'b00,
71
                                        INIT            = 2'b01,
72
                                        DISP            = 2'b10,
73
                                        FIN             = 2'b11;
74
 
75
//LCD Driver Instantiation                                      
76
lcd_16x2_8bit DUT (
77
        .data(data_reg),
78
        .clk(clk),
79
        .rst(rst),
80
        .start(d_start_reg),
81
        .cd(cd_reg),
82
        .lcd_data(lcd_data),
83
        .rs(rs),
84
        .en(en),
85
        .done_tick(done_tick)
86
        );
87
 
88
 
89
always@(posedge clk, negedge rst)
90
begin
91
        if(!rst)
92
        begin
93
                state_reg       <= IDLE;
94
                count_reg       <= 0;
95
                data_reg        <= 0;
96
                cd_reg          <= 0;
97
                d_start_reg <= 0;
98
        end
99
        else
100
        begin
101
                state_reg       <= state_next;
102
                count_reg       <= count_next;
103
                data_reg        <= data_next;
104
                cd_reg          <= cd_next;
105
                d_start_reg <= d_start_next;
106
        end
107
end
108
 
109
always@*
110
begin
111
        state_next = state_reg;
112
        count_next = count_reg;
113
        data_next = data_reg;
114
        cd_next = cd_reg;
115
        d_start_next = d_start_reg;
116
        case(state_reg)
117
                IDLE:
118
                begin
119
                        if(!start)
120
                                state_next = INIT;
121
                end
122
                INIT:   //LCD INITIALIZE CMDS
123
                begin
124
                        data_next = mem[count_reg];
125
                        d_start_next = 1'b1;
126
                        cd_next = 0;
127
                        if(done_tick)
128
                        begin
129
                                d_start_next = 0;
130
                                count_next = count_reg+1'b1;
131
                                if(count_reg > 8'd2)
132
                                        state_next = DISP;
133
                        end
134
                end
135
                DISP:   //DISPLAY CHARACTERS
136
                begin
137
                        data_next = mem[count_reg];
138
                        d_start_next = 1'b1;
139
                        cd_next = 1;
140
                        if(done_tick)
141
                        begin
142
                                d_start_next = 0;
143
                                count_next = count_reg+1'b1;
144
                                if(count_reg > SIZE-2)
145
                                        state_next = FIN;
146
                        end
147
                end
148
                FIN:
149
                begin
150
                        data_next = 0;
151
                        d_start_next = 0;
152
                        cd_next = 0;
153
                        state_next = IDLE;
154
                end
155
        endcase
156
end
157
endmodule

powered by: WebSVN 2.1.0

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