LCD init function - now must return OK / FAIL...

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!
Please help! I want to add a return value to my LCD init function:
- TRUE if init ok (LCD is there live&kicking);
- FALSE if there is NO LCD.
I do have some problems with some devices where the LCD contacts are poor and the AVR program gets stuck, so I need to test if init fails or not.
Here is my code [CodeVision / mega8]:

void LCD_init(void) 
{
 unsigned char i;
 // wait for power on
 delay_us(15000);
 //
 for(i = 0; i < 3; i++)
 {
 	 LcdEnable();
 	 LCD_PORT = 0x03; // send SW reset 
 	 LCD_delay();
 	 LcdDisable();
 	 delay_us(5000);
 }
 //  
 LcdEnable();
 LCD_PORT = 0x02; // 4 bit interface
 LCD_delay();
 LcdDisable();
 delay_us(5000);
 // 
 LCD_sendCommand(0x28); // 2 line, 5x8 matrix
 LCD_sendCommand(0x01); // clear display
 LCD_sendCommand(0x06); // set entry mode 
 LCD_sendCommand(0x0C); // turn display on
}

Any help/idea would be highly appreciated!
TIA.

Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies.

Last Edited: Tue. Nov 22, 2005 - 02:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The only possible way:

Place a human in front of the display, which press a key, if the display works right.

If reading back was supported by your hardware and software, you can read back the code of the current character.
But you can never read back the initialization state.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Isn't there a command to read display status register? Or to read display memory? I'm sure they can be used to test the connection.

The Dark Boxes are coming.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

danni wrote:
The only possible way:

Place a human in front of the display, which press a key, if the display works right.

If reading back was supported by your hardware and software, you can read back the code of the current character.
But you can never read back the initialization state.


Wrong answer!
I know it is possible, but I don't know how (right now...)
I guy that works with PICs did it!!! Of course, he didn't say HOW...
but I will try to find out.
Thx anyway! Good joke :lol: ... a "human"... hehe!

Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

svofski wrote:
Isn't there a command to read display status register? Or to read display memory? I'm sure they can be used to test the connection.

Don't know anything about LCD status register...
But the one with the "read back display memory" should work! ... I think...

Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Standard alphanumeric display's based on HD44780 have status register that *should* be readed before sending any data to it. If you read the datasheet for this controller, then you see that when you initialize it, you only can read it after certain time. Then my suggestion is to do that: pull down resistor on data bus, at least at D7 (the busy flag). Initialize. Send some data and then look for the busy flag. If busy, (1 logic level), then you have LCD attached. Put a timeout timer and to clear the busy flag in a certain time extracted from the datasheet. Do this with all initialization settings. Abort and return NoLCD or LCDDamaged if timeout expires or if busy flag is always '0', LCDinitOK otherwise.

Some ideas only, variations are welcomed.

Guillem.

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As well as checking the busy flag prior to sending data I also read back the message sent.
Note the use of a timer while checking the busy flag


char lcd_read_byte(void)
     {
      unsigned char low;
      unsigned char high;
      lcd_read_set();//
      en_port |= lcd_rw; //send high rw on same port as en
      DelayUs(4);
      en_port |= lcd_en;//output_high(lcd_enable);
      DelayUs(4);   
      high = get_lcd_data();//(PINA & 0x0f);//fetch the upper nibble
      en_port &= ~lcd_en ; //output_low(lcd_enable);
      DelayUs(8);//was 4 13 2 2002
      en_port |= lcd_en;//output_high(lcd_enable);
      DelayUs(8); //was 4 13 2 2002
      low = get_lcd_data();//(PINA & 0x0f);//fetch lower nibble
      en_port &= ~lcd_en;// output_low(lcd_enable);  
      //leave the data lines as inputs with pull ups active
      lcd_read_set();
      return((high<<4) | low);
      }

char lcd_send_byte(char address, int n ) 
    {                                
     char con;
     char error;
     _WDR();
     error=no_error;
     con=n; 
     lcd_response_timer=30; //set of 0.3 of a second
     rs_port_dir |= lcd_rs; //1=output;
     rs_port &= ~lcd_rs;
     _NOP();//make sure pin has had 1 clock to settle the value
     //wait for the lcd to finish
     while ( (lcd_read_byte() & 0x80) && lcd_response_timer );
     if(lcd_response_timer==0)
        error=1;
     if(address==0)
        rs_port &= ~lcd_rs; //outputting  an instruction
     else
       rs_port|= lcd_rs;//output_high(lcd_rs); //outputting data
     lcd_write_set();//
     rw_port &= ~lcd_rw;
     en_port &= ~lcd_en; //output_low(lcd_enable);
     lcd_send_nibble(con >> 4);
     DelayUs(50);//
     lcd_send_nibble(con);
     lcd_read_set();//leave as inputs with pull ups
     return error;
    }
char lcd_getc( char x, char y)//fetch a char from the indicated location
  {
   lcd_gotoxy(x,y);  
   rs_port |= lcd_rs; //1=output;
   y = lcd_read_byte();
   rs_port &= ~lcd_rs;//output_low(lcd_rs) 
   return y;
   }
    

Keep it simple it will not bite as hard

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sutton wrote:
As well as checking the busy flag prior to sending data I also read back the message sent.

Sutton, did the above code worked *on hardware* for you? Because, I had tried the same concept of busy waiting for the D7 bit, but it dint click for me. The mcu was waiting for its lifetime for LCD to respond, then I had to adopt a the non-busy wait algorithm for interfacing 44780.

Cheers,
Vignesh

If everything seems to be coming onto your way, then you are probably driving on a wrong lane..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

vignesh wrote:
sutton wrote:
As well as checking the busy flag prior to sending data I also read back the message sent.

Sutton, did the above code worked *on hardware* for you? Because, I had tried the same concept of busy waiting for the D7 bit, but it dint click for me. The mcu was waiting for its lifetime for LCD to respond, then I had to adopt a the non-busy wait algorithm for interfacing 44780.

Oh, it works... Definitely!

Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies.