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
  • If the problem is delay related then try this.

    Create a file my_delay.s and add it to the project.

            AREA DELAY, CODE, READONLY
    delay4 PROC
            EXPORT delay4
            subs R0,R0,#1
            bne delay4
            BX LR
            ENDP
            END
    

    Then use the following defines

    extern void delay4(int loops);
    #define delay_us(x) delay4((x*(SystemCoreClock/4000))/1000)
    #define delay_ms(x) delay4((x*(SystemCoreClock/400))/10)
    

    The SystemCoreClock is defined in the CMSIS library, you may need to call SystemClockUpdate() if you change the clock frequency.

    If this was working in AVR and you set the I/O operation to work properly in LPC1769 then it will work fine.

    Alex

Reply
  • If the problem is delay related then try this.

    Create a file my_delay.s and add it to the project.

            AREA DELAY, CODE, READONLY
    delay4 PROC
            EXPORT delay4
            subs R0,R0,#1
            bne delay4
            BX LR
            ENDP
            END
    

    Then use the following defines

    extern void delay4(int loops);
    #define delay_us(x) delay4((x*(SystemCoreClock/4000))/1000)
    #define delay_ms(x) delay4((x*(SystemCoreClock/400))/10)
    

    The SystemCoreClock is defined in the CMSIS library, you may need to call SystemClockUpdate() if you change the clock frequency.

    If this was working in AVR and you set the I/O operation to work properly in LPC1769 then it will work fine.

    Alex

Children
  • Thank you for the answer, however I am using LPCXpresso IDE compiler and I think I can't create .s file here and SystemClockUpdate() marked as en error.

  • 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.