0
\$\begingroup\$

i got a problem with my GPS controlled by ATmega328, when i download the code using arduino ISP the GPS works fine and the lcd displays correct data, but when i remove the power from the atmega328 and connect it again the GPS starts to send weird data to the lcd. the two pictures below illustrates my problem : enter image description here

enter image description here

      #include "ALCD.H"
      char rowCount;
      char lastPOSy;
      void lcd_reset()
      {
      lcd_port_dir=0XFF;
      lcd_port = 0xFF;
      _delay_ms(20);
      lcd_port = 0x03+LCD_EN;
      lcd_port = 0x03;
      _delay_ms(10);
      lcd_port = 0x03+LCD_EN;
      lcd_port = 0x03;
      _delay_ms(1);
      lcd_port = 0x03+LCD_EN;
      lcd_port = 0x03;
      _delay_ms(1);
      lcd_port = 0x02+LCD_EN;
     lcd_port = 0x02;
     _delay_ms(1);
    }

     void lcd_init (unsigned char rows)
     {
     rowCount=rows;
     lastPOSy=0;
    lcd_reset();         // Call LCD reset
    lcd_cmd(0x28);       // 4-bit mode - 2 line - 5x7 font. 
    lcd_cmd(0x0c);       // Display no cursor - no blink.
    lcd_cmd(0x06);       // Automatic Increment - No Display shift.
    lcd_cmd(0x80);       // Address DDRAM with 0 offset 80h.
     }

   void lcd_cmd (char cmd)
    {
    lcd_port = ((cmd >> 4) & 0x0F)|LCD_EN;
    lcd_port = ((cmd >> 4) & 0x0F);

    lcd_port = (cmd & 0x0F)|LCD_EN;
    lcd_port = (cmd & 0x0F);

    _delay_us(200);
    _delay_us(200);
     }

   void lcd_data (unsigned char dat)
   {
    lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
    lcd_port = (((dat >> 4) & 0x0F)|LCD_RS);

    lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS);
    lcd_port = ((dat & 0x0F)|LCD_RS);

    _delay_us(200);
    _delay_us(200);
    }
    void lcd_gotoxy(char posX,char posY)
 {
 if (posY==0 ) 
    lcd_cmd((1<<7)+0x00+posX);
  else
  {
    lcd_cmd((1<<7)+0x40+posX);
  lastPOSy=1;
   }        
    _delay_us(40);
  }

 void lcd_clear(void)
 {
lcd_cmd(0x01);
_delay_ms(2);
lcd_cmd(0x02);
_delay_ms(2);
}

 void lcd_putchar(unsigned char data)
 {
 lcd_data(data);
 }

void lcd_puts( char *str)
{
unsigned char i=0;

while(*(str+i)!='\0'&&i<rowCount)
{
lcd_data(str[i]);
i++;    
}
if (i>rowCount-1&&lastPOSy==0)
{
    i=rowCount;
    lcd_gotoxy(0,1);

while(*(str+i)!='\0')
{
lcd_data(str[i]);
i++;    
}
}

}

void lcd_putconsts(const char *str)
{
unsigned char i=0;

while(*(str+i)!='\0'&&i<rowCount)
{
lcd_data(str[i]);
i++;    
}
if (i>rowCount-1&&lastPOSy==0)
{
    i=rowCount;
    lcd_gotoxy(0,1);

while(*(str+i)!='\0')
{
lcd_data(str[i]);
i++;    
}
}
}
\$\endgroup\$
20
  • \$\begingroup\$ does it stay like that forever? \$\endgroup\$
    – KyranF
    May 1, 2015 at 17:35
  • \$\begingroup\$ Is the USB the only thing powering the entire circuit (ATmega/GPS/LCD)? It looks like your character signals to the LCD are going out of sync, or some setting is changing. Do you have a reset button affecting all devices? Have you tried debugging the code within the ATmega to see if it is sending correct data to the LCD? \$\endgroup\$
    – Mewa
    May 1, 2015 at 17:38
  • 1
    \$\begingroup\$ :( How much of a delay did you try? \$\endgroup\$
    – Mewa
    May 1, 2015 at 18:34
  • 1
    \$\begingroup\$ Odd. Could you post your initialization code for the LCD? In my experience with these things, problems are usually caused by improper initialization delays. Hopefully some breadboard people will show up and give some insight on power as well :) \$\endgroup\$
    – Mewa
    May 1, 2015 at 18:41
  • 1
    \$\begingroup\$ perhaps there is a setting which is set too fast on power-up? Not sure, sorry. \$\endgroup\$
    – KyranF
    May 1, 2015 at 20:11

1 Answer 1

1
\$\begingroup\$

This is most likely caused by running the init routine switch the LCD from 8 bit mode to 4 bit mode when it is already in 4 bit mode. It may be possible to try putting it in 8 bit mode and then switching back to 4 bit mode. The most reliable solution is probably just power cycling the display as part of the init routine get it in a consistent state.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.