0% found this document useful (0 votes)
25 views8 pages

Ejemplo de Digilent para Un LCD Con El PmodCLP V

Uploaded by

Juan Jaramillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views8 pages

Ejemplo de Digilent para Un LCD Con El PmodCLP V

Uploaded by

Juan Jaramillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Ejemplo de Digilent para un LCD con el PmodCLP

Se utiliza el módulo periférico Pmod CLP y el ejemplo de la referencia para la tarjeta Nexys 3.

Ahora se presenta el código en verilog para la tarjeta Nexys 3, como se encuentra en las referencias.

Observar que las líneas siguientes representan la declaración de un arreglo descrito como parámetros
(parameter), que sería el equivalente de realizar una memoria ROM.

parameter [9:0] LCD_CMDS[0:23] = {


{2'b00, 8'h3C}, // 0, Function Set
{2'b00, 8'h0C}, // 1, Display ON, Cursor OFF, Blink OFF
{…}, //
{…}, //
{…}, //

`timescale 1ns / 1ps


//////////////////////////////////////////////////////////////////////////////////
// Displays "Hello from Digilent" text on the PmodCLP LCD screen.
//////////////////////////////////////////////////////////////////////////////////

// ==============================================================================
// Define Module
// ==============================================================================
module PmodCLP(
btnr,
CLK,
JA,
JB
);

// ===========================================================================
// Port Declarations
// ===========================================================================
input btnr; // use BTNR as reset input
input CLK; // 100 MHz clock input
//lcd input signals
//signal on connector JA
output [7:0] JA; //output bus, used for data transfer (DB)
// signal on connector JB
//JB[4]register selection pin (RS)
//JB[5]selects between read/write modes (RW)
//JB[6]enable signal for starting the data read/write (E)
output [6:4] JB;

// ===========================================================================
// Parameters, Regsiters, and Wires
// ===========================================================================
wire [7:0] JA;
wire [6:4] JB;

//LCD control state machine


parameter [3:0] stFunctionSet = 0, // Initialization states
stDisplayCtrlSet = 1,
stDisplayClear = 2,
stPowerOn_Delay = 3, // Delay states
stFunctionSet_Delay = 4,
stDisplayCtrlSet_Delay = 5,
stDisplayClear_Delay = 6,
stInitDne = 7, // Display characters and perform standard operations
stActWr = 8,
stCharDelay = 9; // Write delay for operations

/* These constants are used to initialize the LCD pannel.


-- FunctionSet:
Bit 0 and 1 are arbitrary
Bit 2: Displays font type(0=5x8, 1=5x11)
Bit 3: Numbers of display lines (0=1, 1=2)
Bit 4: Data length (0=4 bit, 1=8 bit)
Bit 5-7 are set
-- DisplayCtrlSet:
Bit 0: Blinking cursor control (0=off, 1=on)
Bit 1: Cursor (0=off, 1=on)
Bit 2: Display (0=off, 1=on)
Bit 3-7 are set
-- DisplayClear:
Bit 1-7 are set */

reg [6:0] clkCount = 7'b0000000;


reg [20:0] count = 21'b000000000000000000000; // 21 bit count variable for timing delays
wire delayOK; // High when count has reached the right delay time
reg oneUSClk; // Signal is treated as a 1 MHz clock
reg [3:0] stCur = stPowerOn_Delay; // LCD control state machine
reg [3:0] stNext;
wire writeDone; // Command set finish

parameter [9:0] LCD_CMDS[0:23] = {


{2'b00, 8'h3C}, // 0, Function Set
{2'b00, 8'h0C}, // 1, Display ON, Cursor OFF, Blink OFF
{2'b00, 8'h01}, // 2, Clear Display
{2'b00, 8'h02}, // 3, Return Home
{2'b10, 8'h48}, // 4, H
{2'b10, 8'h65}, // 5, e
{2'b10, 8'h6C}, // 6, l
{2'b10, 8'h6C}, // 7, l
{2'b10, 8'h6F}, // 8, o
{2'b10, 8'h20}, // 9, blank
{2'b10, 8'h46}, // 10, F
{2'b10, 8'h72}, // 11, r
{2'b10, 8'h6F}, // 12, o
{2'b10, 8'h6D}, // 13, m
{2'b10, 8'h20}, // 14, blank
{2'b10, 8'h44}, // 15, D
{2'b10, 8'h69}, // 16, i
{2'b10, 8'h67}, // 17, g
{2'b10, 8'h69}, // 18, i
{2'b10, 8'h6C}, // 19, l
{2'b10, 8'h65}, // 20, e
{2'b10, 8'h6E}, // 21, n
{2'b10, 8'h74}, // 22, t
{2'b00, 8'h18} // 23, Shift left
};

reg [4:0] lcd_cmd_ptr;

// ===========================================================================
// Implementation
// ===========================================================================

// This process counts to 100, and then resets. It is used to divide the clock signal.
// This makes oneUSClock peak aprox. once every 1microsecond
always @(posedge CLK)
begin
if(clkCount == 7'b1100100)
begin
clkCount <= 7'b0000000;
oneUSClk <= ~oneUSClk;
end
else
begin
clkCount <= clkCount + 1'b1;
end
end

// This process increments the count variable unless delayOK = 1.


always @(posedge oneUSClk)
begin
if(delayOK == 1'b1)
begin
count <= 21'b000000000000000000000;
end
else
begin
count <= count + 1'b1;
end
end

// Determines when count has gotten to the right number, depending on the state.
assign delayOK = (
((stCur == stPowerOn_Delay) && (count == 21'b111101000010010000000)) || // 2000000=20 ms
((stCur == stFunctionSet_Delay) && (count == 21'b000000000111110100000)) || // 4000 =40 us
((stCur == stDisplayCtrlSet_Delay) && (count == 21'b000000000111110100000)) || // 4000 =40 us
((stCur == stDisplayClear_Delay) && (count == 21'b000100111000100000000)) || // 160000 =1.6 ms
((stCur == stCharDelay) && (count == 21'b000111111011110100000)) // 260000=2.6 ms - Max Delay for
character writes and shifts
) ? 1'b1 : 1'b0;

// writeDone goes high when all commands have been run


assign writeDone = (lcd_cmd_ptr == 5'd23) ? 1'b1 : 1'b0;

// Increments the pointer so the statemachine goes through the commands


always @(posedge oneUSClk)
begin
if((stNext == stInitDne || stNext == stDisplayCtrlSet || stNext == stDisplayClear) && writeDone == 1'b0)
begin
lcd_cmd_ptr <= lcd_cmd_ptr + 1'b1;
end
else if(stCur == stPowerOn_Delay || stNext == stPowerOn_Delay)
begin
lcd_cmd_ptr <= 5'b00000;
end
else
begin
lcd_cmd_ptr <= lcd_cmd_ptr;
end
end
// This process runs the LCD state machine
always @(posedge oneUSClk)
begin
if(btnr == 1'b1)
begin
stCur <= stPowerOn_Delay;
end
else
begin
stCur <= stNext;
end
end

// This process generates the sequence of outputs needed to initialize and write to the LCD screen
always @(stCur or delayOK or writeDone or lcd_cmd_ptr)
begin
case (stCur)
// Delays the state machine for 20ms which is needed for proper startup.
stPowerOn_Delay :
begin
if(delayOK == 1'b1)
begin
stNext <= stFunctionSet;
end
else
begin
stNext <= stPowerOn_Delay;
end
end

// This issues the function set to the LCD as follows


// 8 bit data length, 1 lines, font is 5x8.
stFunctionSet :
begin
stNext <= stFunctionSet_Delay;
end

// Gives the proper delay of 37us between the function set and
// the display control set.
stFunctionSet_Delay :
begin
if(delayOK == 1'b1)
begin
stNext <= stDisplayCtrlSet;
end
else
begin
stNext <= stFunctionSet_Delay;
end
end

// Issuse the display control set as follows


// Display ON, Cursor OFF, Blinking Cursor OFF.
stDisplayCtrlSet :
begin
stNext <= stDisplayCtrlSet_Delay;
end

// Gives the proper delay of 37us between the display control set
// and the Display Clear command.
stDisplayCtrlSet_Delay :
begin
if(delayOK == 1'b1)
begin
stNext <= stDisplayClear;
end
else
begin
stNext <= stDisplayCtrlSet_Delay;
end
end

// Issues the display clear command.


stDisplayClear :
begin
stNext <= stDisplayClear_Delay;
end

// Gives the proper delay of 1.52ms between the clear command


// and the state where you are clear to do normal operations.
stDisplayClear_Delay :
begin
if(delayOK == 1'b1)
begin
stNext <= stInitDne;
end
else
begin
stNext <= stDisplayClear_Delay;
end
end

// State for normal operations for displaying characters, changing the


// Cursor position etc.
stInitDne :
begin
stNext <= stActWr;
end

// stActWr
stActWr :
begin
stNext <= stCharDelay;
end

// Provides a max delay between instructions.


stCharDelay :
begin
if(delayOK == 1'b1)
begin
stNext <= stInitDne;
end
else
begin
stNext <= stCharDelay;
end
end

default : stNext <= stPowerOn_Delay;

endcase
end

// Assign outputs
assign JA = LCD_CMDS[lcd_cmd_ptr][7:0];
assign JB[4] = LCD_CMDS[lcd_cmd_ptr][9];
assign JB[5] = LCD_CMDS[lcd_cmd_ptr][8];
assign JB[6] = (stCur == stFunctionSet || stCur == stDisplayCtrlSet || stCur == stDisplayClear || stCur == stActWr)
? 1'b1 : 1'b0;

endmodule

########################################################################
## This file is a general .ucf for Nexys3 rev B board

##Clock signal
Net "clk" LOC=V10 | IOSTANDARD=LVCMOS33;

## Buttons
Net "btnr" LOC = D9 | IOSTANDARD = LVCMOS33; # BTNR
## 12 pin connectors
##JA
Net "JA<0>" LOC = T12 | IOSTANDARD = LVCMOS33; # JA1
Net "JA<1>" LOC = V12 | IOSTANDARD = LVCMOS33; # JA2
Net "JA<2>" LOC = N10 | IOSTANDARD = LVCMOS33; # JA3
Net "JA<3>" LOC = P11 | IOSTANDARD = LVCMOS33; # JA4
Net "JA<4>" LOC = M10 | IOSTANDARD = LVCMOS33; # JA7
Net "JA<5>" LOC = N9 | IOSTANDARD = LVCMOS33; # JA8
Net "JA<6>" LOC = U11 | IOSTANDARD = LVCMOS33; # JA9
Net "JA<7>" LOC = V11 | IOSTANDARD = LVCMOS33; # JA10

##JB
#Net "JB<0>" LOC = K2 | IOSTANDARD = LVCMOS33; # JB1
#Net "JB<1>" LOC = K1 | IOSTANDARD = LVCMOS33; # JB2
#Net "JB<2>" LOC = L4 | IOSTANDARD = LVCMOS33; # JB3
#Net "JB<3>" LOC = L3 | IOSTANDARD = LVCMOS33; # JB4
Net "JB<4>" LOC = J3 | IOSTANDARD = LVCMOS33; # JB7
Net "JB<5>" LOC = J1 | IOSTANDARD = LVCMOS33; # JB8
Net "JB<6>" LOC = K3 | IOSTANDARD = LVCMOS33; # JB9
#Net "JB<7>" LOC = K5 | IOSTANDARD = LVCMOS33; # JB10

##JC
#Net "JC<0>" LOC = H3 | IOSTANDARD = LVCMOS33; # JC1
#Net "JC<1>" LOC = L7 | IOSTANDARD = LVCMOS33; # JC2
#Net "JC<2>" LOC = K6 | IOSTANDARD = LVCMOS33; # JC3
#Net "JC<3>" LOC = G3 | IOSTANDARD = LVCMOS33; # JC4
#Net "JC<4>" LOC = G1 | IOSTANDARD = LVCMOS33; # JC7
#Net "JC<5>" LOC = J7 | IOSTANDARD = LVCMOS33; # JC8
#Net "JC<6>" LOC = J6 | IOSTANDARD = LVCMOS33; # JC9
#Net "JC<7>" LOC = F2 | IOSTANDARD = LVCMOS33; # JC10

##JD, LX16 Die only


#Net "JD<0>" LOC = G11 | IOSTANDARD = LVCMOS33; # JD1
#Net "JD<1>" LOC = F10 | IOSTANDARD = LVCMOS33; # JD2
#Net "JD<2>" LOC = F11 | IOSTANDARD = LVCMOS33; # JD3
#Net "JD<3>" LOC = E11 | IOSTANDARD = LVCMOS33; # JD4
#Net "JD<4>" LOC = D12 | IOSTANDARD = LVCMOS33; # JD7
#Net "JD<5>" LOC = C12 | IOSTANDARD = LVCMOS33; # JD8
#Net "JD<6>" LOC = F12 | IOSTANDARD = LVCMOS33; # JD9
#Net "JD<7>" LOC = E12 | IOSTANDARD = LVCMOS33; # JD10

Referencias:
Pmod CLP
https://digilent.com/reference/_media/pmod:pmod:pmodclp_rm.pdf?msclkid=d33ffd08d01811ec94612c94b29
3e4b3
https://digilent.com/reference/pmod/pmodclp/start?msclkid=d3402d65d01811ec9a5ab95753699fec

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy