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

Subversion Repositories 16x2_lcd_display_driver

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /16x2_lcd_display_driver/trunk
    from Rev 1 to Rev 2
    Reverse comparison

Rev 1 → Rev 2

/rtl/lcd_fpga.v
0,0 → 1,157
/*
16x2 LCD DEMO
DESCRIPTION
Demo for 16X2 LCD.
Example Hello World!
IO DETAILS
clk >> Clock
rst >> Reset
start >> Start process
rs >> LCD Register select
en >> LCD Enable
lcd_data >> LCD Data pins
AUTHOR:
Name: Jagadeesh J
Email: jagadeeshj@kenosys.in
Tel: +91-8098701730
COMPANY:
KENOSYS EMBEDDED SOLUTIONS, SALEM, TAMILNADU, INDIA
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
*/
module lcd_fpga (
input clk,rst,start,
output rs,en,
output [7:0]lcd_data
);
 
parameter SIZE = 5'd16; //SIZE OF MEMORY
reg [7:0]mem[0:SIZE-1];
reg [7:0]data_reg, data_next;
reg [1:0]state_reg, state_next;
reg [3:0]count_reg, count_next;
reg cd_next, cd_reg;
reg d_start_reg, d_start_next;
wire done_tick;
 
initial
begin
mem[0] = 8'h38; //LCD_mode 8 bit
mem[1] = 8'h06; //Entry mode
mem[2] = 8'h0E; //Curson on
mem[3] = 8'h01; //Clear Display
mem[4] = 8'h48; //H
mem[5] = 8'h45; //E
mem[6] = 8'h4C; //L
mem[7] = 8'h4C; //L
mem[8] = 8'h4F; //O
mem[9] = 8'h20; //
mem[10] = 8'h57; //W
mem[11] = 8'h4F; //O
mem[12] = 8'h52; //R
mem[13] = 8'h4C; //L
mem[14] = 8'h44; //D
mem[15] = 8'h21; //!
end
 
//States
localparam [1:0] IDLE = 2'b00,
INIT = 2'b01,
DISP = 2'b10,
FIN = 2'b11;
//LCD Driver Instantiation
lcd_16x2_8bit DUT (
.data(data_reg),
.clk(clk),
.rst(rst),
.start(d_start_reg),
.cd(cd_reg),
.lcd_data(lcd_data),
.rs(rs),
.en(en),
.done_tick(done_tick)
);
 
 
always@(posedge clk, negedge rst)
begin
if(!rst)
begin
state_reg <= IDLE;
count_reg <= 0;
data_reg <= 0;
cd_reg <= 0;
d_start_reg <= 0;
end
else
begin
state_reg <= state_next;
count_reg <= count_next;
data_reg <= data_next;
cd_reg <= cd_next;
d_start_reg <= d_start_next;
end
end
 
always@*
begin
state_next = state_reg;
count_next = count_reg;
data_next = data_reg;
cd_next = cd_reg;
d_start_next = d_start_reg;
case(state_reg)
IDLE:
begin
if(!start)
state_next = INIT;
end
INIT: //LCD INITIALIZE CMDS
begin
data_next = mem[count_reg];
d_start_next = 1'b1;
cd_next = 0;
if(done_tick)
begin
d_start_next = 0;
count_next = count_reg+1'b1;
if(count_reg > 8'd2)
state_next = DISP;
end
end
DISP: //DISPLAY CHARACTERS
begin
data_next = mem[count_reg];
d_start_next = 1'b1;
cd_next = 1;
if(done_tick)
begin
d_start_next = 0;
count_next = count_reg+1'b1;
if(count_reg > SIZE-2)
state_next = FIN;
end
end
FIN:
begin
data_next = 0;
d_start_next = 0;
cd_next = 0;
state_next = IDLE;
end
endcase
end
endmodule
/rtl/lcd_16x2_8bit.v
0,0 → 1,135
/*
16x2 LCD DRIVER
DESCRIPTION
Driver for 16X2 LCD.
Fetch data from the input data port and presents it to the LCD pins with enable latch pulse. cd input pin
is used to select whether the data is lcd command data or character data.
IO DETAILS
data >> lcd input
clk >> Clock
rst >> Reset
start >> Start process
cd >> 0-LCD Command/1-LCD Char
rs >> LCD Register select
en >> LCD Enable
done_tick >> Process completed clock tick
AUTHOR:
Name: Jagadeesh J
Email: jagadeeshj@kenosys.in
Tel: +91-8098701730
COMPANY:
KENOSYS EMBEDDED SOLUTIONS, SALEM, TAMILNADU, INDIA
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
*/
module lcd_16x2_8bit (
input [7:0]data,
input clk, rst, start, cd,
output [7:0]lcd_data,
output rs, en,
output reg done_tick
);
 
localparam [2:0] idle = 3'b000,
load = 3'b001,
wait1 = 3'b010,
wait2 = 3'b011,
done = 3'b100;
 
reg [2:0]state_reg,state_next;
reg [15:0]count_reg;
wire [15:0]count_next;
reg [7:0]lcd_data_reg, lcd_data_next;
reg rs_reg, rs_next, en_reg, en_next, c_load_reg, c_load_next;
wire c_1ms, c_h1ms;
 
always@(posedge clk, negedge rst)
begin
if(!rst)
begin
state_reg <= idle;
c_load_reg <= 0;
en_reg <= 0;
rs_reg <= 0;
lcd_data_reg <= 0;
count_reg <= 0;
end
else
begin
state_reg <= state_next;
c_load_reg <= c_load_next;
en_reg <= en_next;
rs_reg <= rs_next;
lcd_data_reg <= lcd_data_next;
count_reg <= count_next;
end
end
 
assign count_next = (c_load_reg)?(count_reg + 1'b1):16'd0;
 
assign c_1ms = (count_reg == 16'd50000);
assign c_h1ms = (count_reg == 16'd25000);
 
always@*
begin
state_next = state_reg;
rs_next = rs_reg;
en_next = en_reg;
lcd_data_next = lcd_data_reg;
done_tick = 0;
c_load_next = c_load_reg;
case(state_reg)
idle:
begin
if(start)
state_next = load;
end
load:
begin
state_next = wait1;
lcd_data_next = data;
rs_next = cd;
end
wait1:
begin
c_load_next = 1;
en_next = 1;
if(c_1ms)
begin
state_next = wait2;
en_next = 0;
c_load_next = 0;
end
end
wait2:
begin
c_load_next= 1;
if(c_h1ms)
begin
state_next = done;
c_load_next = 0;
end
end
done:
begin
done_tick = 1;
state_next = idle;
end
endcase
end
assign lcd_data = lcd_data_reg;
assign en = en_reg;
assign rs = rs_reg;
endmodule

powered by: WebSVN 2.1.0

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