lpcware

lcp1769 to lcd help request

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by jennycortez326 on Thu Aug 07 19:22:39 MST 2014
Hi everyone, I am trying to interface my LCP1769 to a 16x2 LCD. Please see the code below. I have the LCD data pins connected correctly to the LCP1769 and RS,R/W, E pins connected to the given addresses as well. I am trying to display the word "Hello" on my LCD but I am still not getting anything..... Any advise would be helpful.

Thanks in advanced.




#include "lpc_types.h"
#include "lpc17xx.h"
#include "system_lpc17xx.h"
#include <NXP/crp.h>
__CRP const unsigned int CRP_WORD = CRP_NO_CRP;



#define EN LPC_GPIO0->FIOSET |= (1<<21)
#define DIS_EN LPC_GPIO0->FIOCLR |= (1<<21)
#define RS LPC_GPIO0->FIOSET |= (1<<10)
#define DIS_RS LPC_GPIO0->FIOCLR |= (1<<10)
#define RW LPC_GPIO0->FIOSET |= (1<<11)
#define DIS_RW LPC_GPIO0->FIOCLR |= (1<<11)
#define lcd_delay 1000000

void lcd_init(void);
void lcd_initwrite(unsigned char value);
void command(uint8_t value);
void delay(unsigned int i);

void delay(unsigned int i)
{
uint8_t bit[4];
unsigned int j =0;
for (j=0;j>4;j++)
bit[1]=(i & 0x20)>>5;
bit[2]=(i & 0x40)>>6;
bit[3]=(i & 0x80)>>7;
bit[0] ? (LPC_GPIO1->FIOSET = (1<<27)) : (LPC_GPIO1->FIOCLR = (1 << 27));
bit[1] ? (LPC_GPIO1->FIOSET = (1<<24)) : (LPC_GPIO1->FIOCLR = (1 << 24));
bit[2] ? (LPC_GPIO1->FIOSET = (1<<21)) : (LPC_GPIO1->FIOCLR = (1 << 21));
bit[3] ? (LPC_GPIO1->FIOSET = (1<<18)) : (LPC_GPIO1->FIOCLR = (1 << 18));
EN;
DIS_EN;
}

void command(uint8_t value)
{

uint8_t bit[4];
DIS_RW; //RW is low
DIS_RS;
bit[0] = (value & 0x10) >> 4;
bit[1] = (value & 0x20) >> 5;
bit[2] = (value & 0x40) >> 6;
bit[3] = (value & 0x80) >> 7;
bit[0] ? (LPC_GPIO1->FIOSET = (1<<27)) : (LPC_GPIO1->FIOCLR = (1 << 27));
bit[1] ? (LPC_GPIO1->FIOSET = (1<<24)) : (LPC_GPIO1->FIOCLR = (1 << 24));
bit[2] ? (LPC_GPIO1->FIOSET = (1<<21)) : (LPC_GPIO1->FIOCLR = (1 << 21));
bit[3] ? (LPC_GPIO1->FIOSET = (1<<18)) : (LPC_GPIO1->FIOCLR = (1 << 18));
EN;
DIS_EN;

bit[0]=(value & 0x01)>>0;
bit[1]=(value & 0x02)>>1;
bit[2]=(value & 0x04)>>2;
bit[3]=(value & 0x08)>>3;
bit[0] ? (LPC_GPIO1->FIOSET = (1<<27)) : (LPC_GPIO1->FIOCLR = (1 << 27));
bit[1] ? (LPC_GPIO1->FIOSET = (1<<24)) : (LPC_GPIO1->FIOCLR = (1 << 24));
bit[2] ? (LPC_GPIO1->FIOSET = (1<<21)) : (LPC_GPIO1->FIOCLR = (1 << 21));
bit[3] ? (LPC_GPIO1->FIOSET = (1<<18)) : (LPC_GPIO1->FIOCLR = (1 << 18));
EN;
DIS_EN;
}

void print(uint8_t cmd)
{
delay(4800);
uint8_t bit[4];
RS;
DIS_RW;
bit[0] = (cmd & 0x10) >> 4;
bit[1] = (cmd & 0x20) >> 5;
bit[2] = (cmd & 0x40) >> 6;
bit[3] = (cmd & 0x80) >> 7;
bit[0] ? (LPC_GPIO1->FIOSET = (1<<27)) : (LPC_GPIO1->FIOCLR = (1 << 27));
bit[1] ? (LPC_GPIO1->FIOSET = (1<<24)) : (LPC_GPIO1->FIOCLR = (1 << 24));
bit[2] ? (LPC_GPIO1->FIOSET = (1<<21)) : (LPC_GPIO1->FIOCLR = (1 << 21));
bit[3] ? (LPC_GPIO1->FIOSET = (1<<18)) : (LPC_GPIO1->FIOCLR = (1 << 18));
EN;
DIS_EN;

bit[0]=(cmd & 0x01)>>0;
bit[1]=(cmd & 0x02)>>1;
bit[2]=(cmd & 0x04)>>2;
bit[3]=(cmd & 0x08)>>3;
bit[0] ? (LPC_GPIO1->FIOSET = (1<<27)) : (LPC_GPIO1->FIOCLR = (1 << 27));
bit[1] ? (LPC_GPIO1->FIOSET = (1<<24)) : (LPC_GPIO1->FIOCLR = (1 << 24));
bit[2] ? (LPC_GPIO1->FIOSET = (1<<21)) : (LPC_GPIO1->FIOCLR = (1 << 21));
bit[3] ? (LPC_GPIO1->FIOSET = (1<<18)) : (LPC_GPIO1->FIOCLR = (1 << 18));
EN;
DIS_EN;
DIS_RS;
}
int main()
{
//LPC_PINCON->PINSEL3 |= ~((1<<20)|(1<<19)|(1<<18)|(1<<21))
LPC_PINCON->PINSEL3 |= ~((1<<27) | (1<<24) | (1<<21) |(1<<18)); //Data lines D4-D7
LPC_GPIO1->FIODIR |= (1<<27) | (1<<24) | (1<<21) |(1<<18); //sets the data lines as output.
LPC_GPIO1->FIOCLR |= (1<<27) | (1<<24) | (1<<21) |(1<<18);// clears the output pins
LPC_GPIO0->FIODIR |= (1<<21);
LPC_GPIO0->FIODIR |= (1<<10) |(1<<11);
//lcd_init();

int count = 0;
char output[] = "Hello.";

while (output[count] != '\0')
{
print(output[count]);
count++;
}

while(1);
return 0 ;
}



Outcomes