Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Lcd (hd44780) working intermittentely!

Status
Not open for further replies.

kgavionics

Full Member level 3
Full Member level 3
Joined
Jun 12, 2012
Messages
167
Helped
7
Reputation
14
Reaction score
11
Trophy points
1,298
Location
Alberta.Canada
Activity points
2,482
Hello
I'm using an arduino uno hooked up to a 16x4 Lcd.I'm not using arduino IDE,instead I'm using avr-gcc complier and avrdude to transfert the hex file to the uno board.
the flowing code is working, but intermittently.Sometimes, it works, but most of the times it's not! I think it has to do with initialization, but I can't find why in my code!
Any help would be much appreciated!

C:
#include <avr/io.h>
#include <util/delay.h>               

#define FOSC 16000000
#define LCD_PRT  PORTD //PD4-PD7
#define LCD_DDR  DDRD
#define LCD_PIN  PIND
#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2
void delay_us(int d)
{
_delay_us(d);
}
void delay_ms(int d)
{
_delay_ms(d);
}

    void lcdCommand( unsigned char cmnd)
{
    LCD_PRT = (LCD_PRT & 0x0f) | (cmnd & 0xf0); //send high nibbles
    LCD_PRT &= ~ (1<<LCD_RS);
    LCD_PRT &= ~ (1<<LCD_RW);
    LCD_PRT |= (1<<LCD_EN);
    delay_us(1);
    LCD_PRT &= ~(1<<LCD_EN);
    delay_us(20);
    LCD_PRT = (LCD_PRT & 0x0f) | (cmnd <<4); //send low nibbles
  
    LCD_PRT |= (1<<LCD_EN);
    delay_us(1);
    LCD_PRT &= ~(1<<LCD_EN);
  
}
    void lcdData( unsigned char data)
{
    LCD_PRT = (LCD_PRT & 0x0f) | (data & 0xf0); //send high nibbles
    LCD_PRT |=  (1<<LCD_RS);
    LCD_PRT &= ~ (1<<LCD_RW);
    LCD_PRT |= (1<<LCD_EN);
    delay_us(1);
    LCD_PRT &= ~(1<<LCD_EN);
  
    LCD_PRT = (LCD_PRT & 0x0f) | (data <<4); //send low nibbles
  
    LCD_PRT |= (1<<LCD_EN);
    delay_us(1);
    LCD_PRT &= ~(1<<LCD_EN);
  
}
void lcd_init(void)
{
    LCD_DDR=0xff;
    LCD_PRT &=~(1<<LCD_EN);
    delay_us(2000);
    lcdCommand(0x28);
    delay_us(100);
    lcdCommand(0x0c);
    delay_us(100);
    lcdCommand(0x01);
    delay_us(2000);
    lcdCommand(0x06);
    delay_us(100);

  

}





void lcd_gotoxy(unsigned char x, unsigned char y)

{
    unsigned char firstCharAdr[] = {0x80, 0xC0, 0x90, 0xD0};//16x4 Lcd display addresses
    lcdCommand (firstCharAdr[y-1] + x-1);
    delay_us(100);

}

void lcd_print (char * str)
{
    unsigned char i = 0;
    while ( str[i] !=0)
    {
        lcdData(str[i]);
        i++;
    }
}


int main (void)

{

lcd_init();



    lcd_gotoxy(1,1);
    lcd_print ("Welcome");
    lcd_gotoxy(1,2);
    lcd_print ("to");
    lcd_gotoxy(1,3);
    lcd_print ("the");
    lcd_gotoxy(1,4);
    lcd_print ("world");


while(1);
return 0;



}
 

Hi,

did you read the HD447800 datasheet. If not: Do it.

I can´t see PORTD setup. (this needs to be done immedaitely after power up to avoid short circuit condition on the data bus.. and has not yet something to do with LCD function)
(try
LCD_DDR=0xff;
LCD_PRT = 0x00; (to ensure RW = 0 and E = 0)

I can´tsee the 15ms wait after power up .. before display init. (40ms on a 3.3V system)

I can´t see the 4.1ms wait during the init sequence...


All in all it´s quite expectable that it behaves odd when you don´t keep on datasheet specifications.

Klaus
--- Updated ---

added:
Why do you try to write your own code while there are thousands of proven code examples?
 

1-To be honest, I took a quick look at the data sheet. I take a closer look at it!
2-I want to write my own code, because if another guy could do it, why can't I?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top