This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem interfacing HD77480 LCD to LCP1769

Hello, I am having problem interfacing HD77480 controller based 16x2 LCD to LCP1769 mcu in 4 bit mode. The black line never disappears. I also tried adding pull-up resisors, however that doesn't solve the problem. I ported code which I wrote for AVR, it was working just fine with it. Maybe there are problems with delays? I also attached LED's on data lines and I see that data is being sent, however screen doesn't show anything.

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

#define RS 0
#define EN 2

void init(void);
void writeCmd(unsigned char a);
void writedat(unsigned char b);
void sendstring(unsigned char *c);
void delay(int count);
void high_to_low_pulse(void);
void setdata(unsigned int data);
unsigned char i,j;
unsigned char vardas[] = "Andrius";

void init()
{
writeCmd(0x02);
writeCmd(0x28);//4 bit mode, 2 display lines
writeCmd(0x0C);
writeCmd(0x06);
}

void writeCmd(unsigned char a)
{
LPC_GPIO2->FIOCLR = (1 << RS);
setdata(a);//(a >> 4);
high_to_low_pulse();
setdata(a<<4);//(a & 0x0F);
high_to_low_pulse();
}

void writedat(unsigned char b)
{
LPC_GPIO2->FIOSET = (1 << RS);
setdata(b);//(b >> 4);
high_to_low_pulse();
setdata(b<<4);//(b & 0x0F);
high_to_low_pulse();
}

void sendstring(unsigned char *c)
{
     while(*c)
     writedat(*c++);
}

void delay(int count)
{
int j=0, i=0;
for (j=0;j<count;j++)
for (i=0;i<900;i++);
}

void high_to_low_pulse(void)
{
LPC_GPIO2->FIOSETL = (1 << EN);
delay(10);
LPC_GPIO2->FIOCLRL = (1 << EN);
}

void setdata(unsigned int data)
{
        if (data & (1<<0))
                LPC_GPIO2->FIOSET0 = (1<<3);
        else
                LPC_GPIO2->FIOCLR0 = (1<<3);
        if (data & (1<<1))
                LPC_GPIO2->FIOSET0 = (1<<4);
        else
                LPC_GPIO2->FIOCLR0 = (1<<4);
        if (data & (1<<2))
                LPC_GPIO2->FIOSET0 = (1<<5);
        else
                LPC_GPIO2->FIOCLR0 = (1<<5);
        if (data & (1<<3))
                LPC_GPIO2->FIOSETL = (1<<6);
        else
                LPC_GPIO2->FIOCLRL = (1<<6);
}

int main(void)
{
        LPC_PINCON->PINSEL2 &= ~(0xFFFFFFFF);
        //LPC_PINCON->PINSEL2 |= (1 << 3)|(1 << 4)|(1 << 5)|(1 << 6);
        LPC_GPIO2->FIODIR |=(1 << RS)|(1 << EN)|(1 << 3)|(1 << 4)|(1 << 5)|(1 << 6);
        init();
        writeCmd(0x80);
        sendstring(vardas);
        while(1);
        return 0;
}

Parents Reply Children
  • I thought you were using keil uvision...
    I'm not familiar with the IDE you use so I don't know how you can add an ASM function.

    I think the majority of IDE use the CMSIS library (system_LPC17xx.c) and the function is there but without the delay function there is no point in using a define with the core clock I think unless you intend to use it some other way.

    An alternative is to use the systick or a timer to get the delays you want or just for test sake increase the for loop to give a much higher delay to see if that changes anything.

    Also make sure to use volatile variables in the delay for loop to make sure that it doesn't get removed (optimized) from the compiler.

    By the way , your display is HD44780 right?

    Alex

  • Yes, it's HD44780, sorry, I guess I was thinking about something else when I wrote HD77480. Well, I checked several times if pins are right but maybe I was wrong and I can't see that. Well, first thing is to check delays.