
// -----------------------------------------------------------------------
// Initialize the LCD display.
// -----------------------------------------------------------------------
extern	void			LcdInit		( void ) {
	uint8_t	mycount;

	// Our first assumption is that we have a LCD module in place
	__lib_lcd_exists_flag = 1;

	// First, set display interface - do this three times
	for	( mycount = 0; mycount < 3; mycount++ ) {
		ApplicationLcdDelay( 10 );
		LcdCommand( LCD_CMD_FUNCSET(1,1,0) );
	}

	// Wait until the display is no more busy or we have ran out
	// of time which means that we do not have the display
	mycount = 0;
	while	( (LcdBusy()) && ( mycount < 50 ) ) {
		ApplicationLcdDelay( 1 );
	}
	if	( LcdBusy() ) {
		__lib_lcd_exists_flag = 0;
		return;
	}
	// Next step funnily enough is to switch the display on...
	// We don't activate cursor or blinking. This is done
	// later is the host application wishes to do that.
	LcdWait( 5 );
	LcdCommand( LCD_CMD_CONTROL(1,0,0) );

	// Clear the display. Takes some milliseconds to finish
	LcdClear();

	// Set LCD entry mode
	LcdWait( 5 );
	LcdCommand( LCD_CMD_MODE(1,0) );

	// So we are good so far. Now, let's write an address
	// and try to read it back
	// If we get the same address then we propably have a LCD
	LcdWait( 5 );
	LcdCommand( LCD_CMD_DDASET(5) );
	LcdWait( 5 );
	if	( LcdGetAddress() != 5 ) {
		__lib_lcd_exists_flag = 0;
	}
	else {
		__lib_lcd_exists_flag = 1;
		LcdCommand( LCD_CMD_DDASET(0) );
	}
}


