<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: lpcxpresso lpc1227 64 interfacing LCD 20x2 in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpcxpresso-lpc1227-64-interfacing-LCD-20x2/m-p/526173#M8806</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by tschnagel on Sat Jul 26 03:34:26 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a version that I adapted from some LPC11xx code.&amp;nbsp; I use it on LPC1225.&amp;nbsp; If I remember correctly, the biggest issue I had when porting the code was the LCD_init.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know if this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;lcd.h&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
#ifndef LCD_H_
#define LCD_H_
#include "LPC122x.h"

void LCD_init(void);
void lcd_gotoxy(uint8_t x, uint8_t y);
void LCD_send_char(uint8_t theChar);
void LCD_print(char *p);
extern void LCDSendInstruction(uint8_t theInstruction);
extern char DISP_BUFFER[16];
#define LCD_FUNCTION SET0x30
#define LCD_FUNCTION_SET_4BIT0x28
#define LCD_DISPLAY_OFF0x08
#define LCD_DISPLAY_ON0x0C
#define LCD_DISPLAY_CLEAR0x01
#define LCD_ENTRY_MODE_SET0x06
#defineLCD_CURSOR_HOME0x02

#defineLCD_DDRAM7

#defineLCD_LINE10x0
#define LCD_LINE20x40
#define LCD_LINE30x14
#define LCD_LINE40x54

//lcd display pins.&amp;nbsp; will be using 4 bit interface
#define LCD_PORT0
#define LCD_PIN03
#define LCD_PINRS7
#defineLCD_PINE8

#endif
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;lcd.c&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;

#ifdef __USE_CMSIS
#include "LPC122x.h"
#endif

#include "driver_config.h"
#include "target_config.h"
#include "lcd.h"
#include "gpio.h"
#include "../src/main.h"

char DISP_BUFFER[16];

void lcd_delay(int msec){
volatile uint32_t done = msTicks + msec;
while (msTicks != done);
}

/*************************************************
 * LCDSendNibble
 * sends a 4-bit nibble to the display
 *
 * PARAMS:
 *&amp;nbsp; uint8_t nibble: The high nibble of this byte
 *&amp;nbsp; is sent to the display
 *
 *&amp;nbsp; RETURNS:
 *&amp;nbsp; none
 **************************************************/
void LCDSendNibble(uint32_t nibble){
uint8_t i=0;
uint8_t x=0;
lcd_delay(3);

//output upper nibble to the data port upper bits
LPC_GPIO0-&amp;gt;OUT &amp;amp;= ~0x78;
LPC_GPIO0-&amp;gt;OUT |= ((nibble &amp;amp; 0x0f) &amp;lt;&amp;lt; LCD_PIN0);


//toggle the E line
LPC_GPIO0-&amp;gt;SET = (1 &amp;lt;&amp;lt; LCD_PINE);
/*__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();*/
LPC_GPIO0-&amp;gt;CLR = (1 &amp;lt;&amp;lt; LCD_PINE);
}

/**************************************************
 * LCDSendByte
 *
 * Sends 8-bit byte to display
 *
 * PARAMS:
 *&amp;nbsp; uint8_t theByte the byte to send to the display
 *
 * RETURNS:
 * none
 *
 ***************************************************/
void LCDSendByte(uint8_t theByte){
//send high nibble
LCDSendNibble(theByte &amp;gt;&amp;gt; 4);

//send low nibble
LCDSendNibble(theByte);
}

/***************************************************
 * LCDSendInstruction
 * Sends an instruction to the display
 *
 * PARAMS:
 * uint8_t command&amp;nbsp; This byte is sent to the display as
 * an instruction (RS low)
 *
 * RETURNS:
 * none
 *
 ****************************************************/
void LCDSendInstruction(uint8_t theInstruction) {
//RS Low for instructions
LPC_GPIO0-&amp;gt;CLR |= (1 &amp;lt;&amp;lt; LCD_PINRS);

//send the instructions
LCDSendByte(theInstruction);
}


void lcd_gotoxy(uint8_t x, uint8_t y) {
if (y==0){
LCDSendInstruction((1&amp;lt;&amp;lt;LCD_DDRAM)+LCD_LINE1+x);
}else if(y==1){
LCDSendInstruction((1&amp;lt;&amp;lt;LCD_DDRAM)+LCD_LINE2+x);
}else if(y==2){
LCDSendInstruction((1&amp;lt;&amp;lt;LCD_DDRAM)+LCD_LINE3+x);
}else{
LCDSendInstruction((1&amp;lt;&amp;lt;LCD_DDRAM)+LCD_LINE4+x);
}

}

/******************************************************
 * LCD_send_character
 * Sends a character to the display
 *
 * PARAMS:
 *&amp;nbsp; uint8_t nibble&amp;nbsp; This byte is send to the display as
 *&amp;nbsp; a characters (RS high)
 *
 * RETURNS:
 * none
 *
 *******************************************************/
void LCD_send_character(uint8_t theChar){
LPC_GPIO0-&amp;gt;SET |= (1 &amp;lt;&amp;lt; LCD_PINRS);
LCDSendByte(theChar);
}

void LCD_print(char *p){
while (*p != 0){
LCD_send_character(*p++);
}
}

void LCD_init(void){
uint8_t i;
//SET PINS TO OUTPUT
for(i=0; i &amp;lt; 4; i++){
GPIOSetDir(0,LCD_PIN0+i,1);
}
GPIOSetDir(0,LCD_PINE,1);
GPIOSetDir(0,LCD_PINRS,1);

GPIOSetValue(0,LCD_PINRS,0);
GPIOSetValue(0,LCD_PINE,0);

lcd_delay(16);
LCDSendNibble(0x03);
lcd_delay(5);
LCDSendNibble(0x03);
lcd_delay(100);
LCDSendNibble(0x03);

LCDSendNibble(0x02);

LCDSendByte(0x28);
LCDSendByte(0x0c);
LCDSendByte(0x06);

//LCDSendInstruction(LCD_FUNCTION_SET_4BIT);


//now set display to 4bit mode
//LCDSendNibble(0x02);

//now in 4 bit mode, finish init the display
/*LCDSendInstruction(LCD_FUNCTION_SET_4BIT);
LCDSendInstruction(LCD_DISPLAY_OFF);
LCDSendInstruction(LCD_DISPLAY_CLEAR);
LCDSendInstruction(LCD_ENTRY_MODE_SET);
LCDSendInstruction(LCD_DISPLAY_ON);

LCDSendByte(0x28);
LCDSendByte(0x0C);
LCDSendByte(0x06);
*/
}

&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 17:01:06 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T17:01:06Z</dc:date>
    <item>
      <title>lpcxpresso lpc1227 64 interfacing LCD 20x2</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpcxpresso-lpc1227-64-interfacing-LCD-20x2/m-p/526172#M8805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by elektronchika on Fri Jul 25 12:58:51 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the LPC1227 in 64 pins package lpcxpresso board. I successfully initialised the ssp port. Now I have my spi running. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;Next I connected a 20x2 alphanumerical LCD display, that runs on 4,5 to 5,5V. I supply it with 4,5V so the display accepts 0,7VDD for logic one (3,15V in this case). I used a code from this post &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.lpcware.com%2Fcontent%2Fforum%2Fhelp-connecting-lpc1769-lpcxpresso-hd44780-16x2-led-display" rel="nofollow" target="_blank"&gt;http://www.lpcware.com/content/forum/help-connecting-lpc1769-lpcxpresso-hd44780-16x2-led-display&lt;/A&gt;&lt;SPAN&gt; I reworked it to run on lpc1227 without success&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My kindly request is if someone can post here a code that works on lpc1227. I need it to compare with the one I have and try to find the errors (it it's not hardware error). Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Lazar&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:01:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/lpcxpresso-lpc1227-64-interfacing-LCD-20x2/m-p/526172#M8805</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: lpcxpresso lpc1227 64 interfacing LCD 20x2</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpcxpresso-lpc1227-64-interfacing-LCD-20x2/m-p/526173#M8806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by tschnagel on Sat Jul 26 03:34:26 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a version that I adapted from some LPC11xx code.&amp;nbsp; I use it on LPC1225.&amp;nbsp; If I remember correctly, the biggest issue I had when porting the code was the LCD_init.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know if this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;lcd.h&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
#ifndef LCD_H_
#define LCD_H_
#include "LPC122x.h"

void LCD_init(void);
void lcd_gotoxy(uint8_t x, uint8_t y);
void LCD_send_char(uint8_t theChar);
void LCD_print(char *p);
extern void LCDSendInstruction(uint8_t theInstruction);
extern char DISP_BUFFER[16];
#define LCD_FUNCTION SET0x30
#define LCD_FUNCTION_SET_4BIT0x28
#define LCD_DISPLAY_OFF0x08
#define LCD_DISPLAY_ON0x0C
#define LCD_DISPLAY_CLEAR0x01
#define LCD_ENTRY_MODE_SET0x06
#defineLCD_CURSOR_HOME0x02

#defineLCD_DDRAM7

#defineLCD_LINE10x0
#define LCD_LINE20x40
#define LCD_LINE30x14
#define LCD_LINE40x54

//lcd display pins.&amp;nbsp; will be using 4 bit interface
#define LCD_PORT0
#define LCD_PIN03
#define LCD_PINRS7
#defineLCD_PINE8

#endif
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;lcd.c&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;

#ifdef __USE_CMSIS
#include "LPC122x.h"
#endif

#include "driver_config.h"
#include "target_config.h"
#include "lcd.h"
#include "gpio.h"
#include "../src/main.h"

char DISP_BUFFER[16];

void lcd_delay(int msec){
volatile uint32_t done = msTicks + msec;
while (msTicks != done);
}

/*************************************************
 * LCDSendNibble
 * sends a 4-bit nibble to the display
 *
 * PARAMS:
 *&amp;nbsp; uint8_t nibble: The high nibble of this byte
 *&amp;nbsp; is sent to the display
 *
 *&amp;nbsp; RETURNS:
 *&amp;nbsp; none
 **************************************************/
void LCDSendNibble(uint32_t nibble){
uint8_t i=0;
uint8_t x=0;
lcd_delay(3);

//output upper nibble to the data port upper bits
LPC_GPIO0-&amp;gt;OUT &amp;amp;= ~0x78;
LPC_GPIO0-&amp;gt;OUT |= ((nibble &amp;amp; 0x0f) &amp;lt;&amp;lt; LCD_PIN0);


//toggle the E line
LPC_GPIO0-&amp;gt;SET = (1 &amp;lt;&amp;lt; LCD_PINE);
/*__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();*/
LPC_GPIO0-&amp;gt;CLR = (1 &amp;lt;&amp;lt; LCD_PINE);
}

/**************************************************
 * LCDSendByte
 *
 * Sends 8-bit byte to display
 *
 * PARAMS:
 *&amp;nbsp; uint8_t theByte the byte to send to the display
 *
 * RETURNS:
 * none
 *
 ***************************************************/
void LCDSendByte(uint8_t theByte){
//send high nibble
LCDSendNibble(theByte &amp;gt;&amp;gt; 4);

//send low nibble
LCDSendNibble(theByte);
}

/***************************************************
 * LCDSendInstruction
 * Sends an instruction to the display
 *
 * PARAMS:
 * uint8_t command&amp;nbsp; This byte is sent to the display as
 * an instruction (RS low)
 *
 * RETURNS:
 * none
 *
 ****************************************************/
void LCDSendInstruction(uint8_t theInstruction) {
//RS Low for instructions
LPC_GPIO0-&amp;gt;CLR |= (1 &amp;lt;&amp;lt; LCD_PINRS);

//send the instructions
LCDSendByte(theInstruction);
}


void lcd_gotoxy(uint8_t x, uint8_t y) {
if (y==0){
LCDSendInstruction((1&amp;lt;&amp;lt;LCD_DDRAM)+LCD_LINE1+x);
}else if(y==1){
LCDSendInstruction((1&amp;lt;&amp;lt;LCD_DDRAM)+LCD_LINE2+x);
}else if(y==2){
LCDSendInstruction((1&amp;lt;&amp;lt;LCD_DDRAM)+LCD_LINE3+x);
}else{
LCDSendInstruction((1&amp;lt;&amp;lt;LCD_DDRAM)+LCD_LINE4+x);
}

}

/******************************************************
 * LCD_send_character
 * Sends a character to the display
 *
 * PARAMS:
 *&amp;nbsp; uint8_t nibble&amp;nbsp; This byte is send to the display as
 *&amp;nbsp; a characters (RS high)
 *
 * RETURNS:
 * none
 *
 *******************************************************/
void LCD_send_character(uint8_t theChar){
LPC_GPIO0-&amp;gt;SET |= (1 &amp;lt;&amp;lt; LCD_PINRS);
LCDSendByte(theChar);
}

void LCD_print(char *p){
while (*p != 0){
LCD_send_character(*p++);
}
}

void LCD_init(void){
uint8_t i;
//SET PINS TO OUTPUT
for(i=0; i &amp;lt; 4; i++){
GPIOSetDir(0,LCD_PIN0+i,1);
}
GPIOSetDir(0,LCD_PINE,1);
GPIOSetDir(0,LCD_PINRS,1);

GPIOSetValue(0,LCD_PINRS,0);
GPIOSetValue(0,LCD_PINE,0);

lcd_delay(16);
LCDSendNibble(0x03);
lcd_delay(5);
LCDSendNibble(0x03);
lcd_delay(100);
LCDSendNibble(0x03);

LCDSendNibble(0x02);

LCDSendByte(0x28);
LCDSendByte(0x0c);
LCDSendByte(0x06);

//LCDSendInstruction(LCD_FUNCTION_SET_4BIT);


//now set display to 4bit mode
//LCDSendNibble(0x02);

//now in 4 bit mode, finish init the display
/*LCDSendInstruction(LCD_FUNCTION_SET_4BIT);
LCDSendInstruction(LCD_DISPLAY_OFF);
LCDSendInstruction(LCD_DISPLAY_CLEAR);
LCDSendInstruction(LCD_ENTRY_MODE_SET);
LCDSendInstruction(LCD_DISPLAY_ON);

LCDSendByte(0x28);
LCDSendByte(0x0C);
LCDSendByte(0x06);
*/
}

&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:01:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/lpcxpresso-lpc1227-64-interfacing-LCD-20x2/m-p/526173#M8806</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:01:06Z</dc:date>
    </item>
  </channel>
</rss>

