//check busy line
static void LCDwaitUntilNotBusy()
{
	#if (USE_BUSY_FLAG == 1)
		uint8_t bfst=255;
		
		//make D4-D7 as input
		bit_clear(LCD_D4_DDR, BIT(LCD_D4_BIT));
		bit_set(LCD_D4_PORT, BIT(LCD_D4_BIT));
		bit_clear(LCD_D5_DDR, BIT(LCD_D5_BIT));
		bit_set(LCD_D5_PORT, BIT(LCD_D5_BIT));
		bit_clear(LCD_D6_DDR, BIT(LCD_D6_BIT));
		bit_set(LCD_D6_PORT, BIT(LCD_D6_BIT));
		bit_clear(LCD_D7_DDR, BIT(LCD_D7_BIT));
		bit_set(LCD_D7_PORT, BIT(LCD_D7_BIT));
		
		//rs=en=0
		bit_clear(LCD_EN_PORT, BIT(LCD_EN_BIT));
		bit_clear(LCD_RS_PORT, BIT(LCD_RS_BIT));
		
		//rw=1
		bit_set(LCD_RW_PORT, BIT(LCD_RW_BIT));
		
		_delay_us(LCD_EN_DELAY);
		
		//check busy flag
		do
		{
			//LCD_PORT |= _BV(LCD_EN);//high
			bit_set(LCD_EN_PORT, BIT(LCD_EN_BIT));
			_delay_us(LCD_EN_DELAY);
			//bfst = LCD_PIN;	//ambil bf dr nibble tggi
			bfst = bit_get(LCD_D7_PIN, BIT(LCD_D7_BIT));
			//LCD_PORT &= ~(_BV(LCD_EN));	//low
			bit_clear(LCD_EN_PORT, BIT(LCD_EN_BIT));
			_delay_us(LCD_EN_DELAY);
			
			//LCD_PORT |= _BV(LCD_EN);//high
			bit_set(LCD_EN_PORT, BIT(LCD_EN_BIT));
			_delay_us(LCD_EN_DELAY);
			//LCD_PORT &= ~(_BV(LCD_EN));	//low
			bit_clear(LCD_EN_PORT, BIT(LCD_EN_BIT));
			_delay_us(LCD_EN_DELAY);
		} //while ((bfst & 0x80) == 0x80);	//loop sampe tdk busy
		while(bfst == BIT(LCD_D7_BIT));		
		
		//restore as output
		//LCD_PORT = 0;
		//LCD_DDR = 0xff;
		lcd_pin_setup();
	#else
		//LCD_PORT &= ~(_BV(LCD_RW));	//make as output low state
		_delay_ms(LCD_CMD_DELAY);
	#endif
}
Esempio n. 2
0
/*
 * description: Set up all GPIO pins needed for LCD
 *
*/
static void lcd_pin_setup_All()
{
    lcd_pin_setup(LCD_RS_PIN_NUMBER);
    lcd_pin_setup(LCD_E_PIN_NUMBER);

    lcd_pin_setup(LCD_DB4_PIN_NUMBER);
    lcd_pin_setup(LCD_DB5_PIN_NUMBER);
    lcd_pin_setup(LCD_DB6_PIN_NUMBER);
    lcd_pin_setup(LCD_DB7_PIN_NUMBER);
}
//lcd init
void LCDinit()
{
	//setup lcd pin
	lcd_pin_setup();
	
	//init lcd
	_delay_ms(50);
	bit_clear(LCD_RS_PORT, BIT(LCD_RS_BIT));
	bit_clear(LCD_EN_PORT, BIT(LCD_EN_BIT));
	bit_set(LCD_D4_PORT, BIT(LCD_D4_BIT));
	bit_set(LCD_D5_PORT, BIT(LCD_D5_BIT));
	LCDtoggleEn();
	_delay_ms(10);
	
	//LCD_PORT=0x30;	//DB4 = DB5 = 1, RS = RW = 0
	LCDtoggleEn();
	_delay_ms(5);
	
	//LCD_PORT=0x30;	//DB4 = DB5 = 1, RS = RW = 0
	LCDtoggleEn();
	_delay_ms(5);
	
	//LCD_PORT=0x20;	//DB5 = 1, RS = RW = 0
	bit_clear(LCD_D4_PORT, BIT(LCD_D4_BIT));
	LCDtoggleEn();
	_delay_ms(5);
	
	//set setting
	LCDsendCommand(0x28);	//4bit 2line 5x7font	
	LCDsendCommand(0x0c);	//display on cursor off
	LCDsendCommand(0x06);	//auto inc display shift off
	LCDsendCommand(0x80);	//cursor home
	
	//init 8 custom chars
	//uint8_t ch=0, chn=0;
	//while(ch<64)
	//{
		//LCDdefinechar((LcdCustomChar+ch),chn++);
		//ch=ch+8;
	//}
	LCDDefineProgressBarChar();
}