lcp1769 to lcd help request

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

lcp1769 to lcd help request

237 Views
lpcware
NXP Employee
NXP Employee
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 ;
}



0 Kudos
Reply
2 Replies

218 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pbrown-sct on Fri Aug 08 14:01:13 MST 2014
The for-loop conditional is incorrect:
for (j=0;j>4;j++)//does loop 4 times.
should be
for (j=0;j<4;j++)//does loop 4 times.
0 Kudos
Reply

218 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DwarfPotato on Fri Aug 08 01:54:38 MST 2014
Hi there,

First things I've noticed, assuming this is the entire program:
- You don't ever call your command function
- I'm not sure delay causes much of a delay, and I'm a little confused as to what it does.
Does this look more correct?
void delay(unsigned int i)
{
uint8_t bit[4]; //4 bit array
unsigned int j =0;//counting variable
for (j=0;j>4;j++)//does loop 4 times.
{
bit[1]=(i & 0x20)>>5;// Only thing in the loop, which is probably wrong.
bit[2]=(i & 0x40)>>6;
bit[3]=(i & 0x80)>>7;
bit[0] ? (LPC_GPIO1->FIOSET = (1<<27)) : (LPC_GPIO1->FIOCLR = (1 << 27));//Make DB0 what Bit[0] is.
bit[1] ? (LPC_GPIO1->FIOSET = (1<<24)) : (LPC_GPIO1->FIOCLR = (1 << 24));//make DB1 what bit[1] is
bit[2] ? (LPC_GPIO1->FIOSET = (1<<21)) : (LPC_GPIO1->FIOCLR = (1 << 21));//and so on.
bit[3] ? (LPC_GPIO1->FIOSET = (1<<18)) : (LPC_GPIO1->FIOCLR = (1 << 18));
EN; //LPC_GPIO0->FIOSET |= (1 << 21); So set enable
DIS_EN;//LPC_GPIO0->FIOCLR |= (1 << 21); Clear enable.
}
}

- I can't see anywhere in your code where you have initialised the screen.
Have you used an LCD screen before? I've found the wikipedia article on them to be very helpful http://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller

Hope this helps.
DP
0 Kudos
Reply