lpcxpresso lpc1227 64 interfacing LCD 20x2

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lpcxpresso lpc1227 64 interfacing LCD 20x2

720 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elektronchika on Fri Jul 25 12:58:51 MST 2014
Hi,

I have the LPC1227 in 64 pins package lpcxpresso board. I successfully initialised the ssp port. Now I have my spi running.

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 http://www.lpcware.com/content/forum/help-connecting-lpc1769-lpcxpresso-hd44780-16x2-led-display I reworked it to run on lpc1227 without success

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!

Best regards,
Lazar
Labels (1)
0 Kudos
1 Reply

604 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tschnagel on Sat Jul 26 03:34:26 MST 2014
Here is a version that I adapted from some LPC11xx code.  I use it on LPC1225.  If I remember correctly, the biggest issue I had when porting the code was the LCD_init.
Let me know if this helps.


lcd.h
#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.  will be using 4 bit interface
#define LCD_PORT0
#define LCD_PIN03
#define LCD_PINRS7
#defineLCD_PINE8

#endif


lcd.c

#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:
 *  uint8_t nibble: The high nibble of this byte
 *  is sent to the display
 *
 *  RETURNS:
 *  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->OUT &= ~0x78;
LPC_GPIO0->OUT |= ((nibble & 0x0f) << LCD_PIN0);


//toggle the E line
LPC_GPIO0->SET = (1 << LCD_PINE);
/*__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();*/
LPC_GPIO0->CLR = (1 << LCD_PINE);
}

/**************************************************
 * LCDSendByte
 *
 * Sends 8-bit byte to display
 *
 * PARAMS:
 *  uint8_t theByte the byte to send to the display
 *
 * RETURNS:
 * none
 *
 ***************************************************/
void LCDSendByte(uint8_t theByte){
//send high nibble
LCDSendNibble(theByte >> 4);

//send low nibble
LCDSendNibble(theByte);
}

/***************************************************
 * LCDSendInstruction
 * Sends an instruction to the display
 *
 * PARAMS:
 * uint8_t command  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->CLR |= (1 << LCD_PINRS);

//send the instructions
LCDSendByte(theInstruction);
}


void lcd_gotoxy(uint8_t x, uint8_t y) {
if (y==0){
LCDSendInstruction((1<<LCD_DDRAM)+LCD_LINE1+x);
}else if(y==1){
LCDSendInstruction((1<<LCD_DDRAM)+LCD_LINE2+x);
}else if(y==2){
LCDSendInstruction((1<<LCD_DDRAM)+LCD_LINE3+x);
}else{
LCDSendInstruction((1<<LCD_DDRAM)+LCD_LINE4+x);
}

}

/******************************************************
 * LCD_send_character
 * Sends a character to the display
 *
 * PARAMS:
 *  uint8_t nibble  This byte is send to the display as
 *  a characters (RS high)
 *
 * RETURNS:
 * none
 *
 *******************************************************/
void LCD_send_character(uint8_t theChar){
LPC_GPIO0->SET |= (1 << 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 < 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);
*/
}

0 Kudos