Exemplo n.º 1
0
// PURPOSE:  Initialize LCD to 4 bit I/O mode
void HD44780::lcd_init()
{
    // configure all port bits as output (LCD data and control lines on different ports 
    LCD_DDR(LCD_RS_PORT)    |= _BV(LCD_RS_PIN);
    LCD_DDR(LCD_E_PORT)     |= _BV(LCD_E_PIN);
    LCD_DDR(LCD_4BIT_D4_PORT) |= _BV(LCD_4BIT_D4_PIN);
    LCD_DDR(LCD_4BIT_D5_PORT) |= _BV(LCD_4BIT_D5_PIN);
    LCD_DDR(LCD_4BIT_D6_PORT) |= _BV(LCD_4BIT_D6_PIN);
    LCD_DDR(LCD_4BIT_D7_PORT) |= _BV(LCD_4BIT_D7_PIN);
    // wait 25ms or more after power-on
    fcpu_delay_us(25000);

    // initial write to lcd is 8bit 
    LCD_4BIT_D5_PORT |= _BV(LCD_4BIT_D5_PIN);  // _BV(LCD_FUNCTION)>>4;
    LCD_4BIT_D4_PORT |= _BV(LCD_4BIT_D4_PIN);  // _BV(LCD_FUNCTION_8BIT)>>4;
    lcd_toggle_e();
    fcpu_delay_us(2000); //2000        // delay, busy flag can't be checked here 

    // repeat last command
    lcd_toggle_e();      
    fcpu_delay_us(64); //64          // delay, busy flag can't be checked here 

    // now configure for 4bit mode
    LCD_4BIT_D4_PORT &= ~_BV(LCD_4BIT_D4_PIN);   // LCD_FUNCTION_4BIT_1LINE>>4
    lcd_toggle_e();
    fcpu_delay_us(2000);           // some displays need this additional delay 



    // set 4 bit IO
    lcd_instr(LCD_FUNCTION_4BIT_2LINES); // 4-bit interface, dual line,   5x7 dots 
    lcd_toggle_e();
    fcpu_delay_us(2000);           // some displays need this additional delay

    lcd_instr(LCD_ENTRY_INC_);//cursor move right, no shift display
    lcd_toggle_e();
    fcpu_delay_us(2500);           // some displays need this additional delay


    lcd_instr(LCD_DISP_ON);// display on, cursor off, blink char off
    lcd_toggle_e();
    fcpu_delay_us(2500);           // some displays need this additional delay



    lcd_home();//set cursor to home and clear the cursor

}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------------------
// FUNCTION: lcd_newline
// PURPOSE:  Move cursor on specified line
void lcd_setline(uint8_t line)
{
    uint8_t addressCounter = 0;
	switch(line)
	{
		case 0: addressCounter = LCD_START_LINE1; break;
		case 1: addressCounter = LCD_START_LINE2; break;
		case 2: addressCounter = LCD_START_LINE3; break;
		case 3: addressCounter = LCD_START_LINE4; break;
		default:addressCounter = LCD_START_LINE1; break;
	}
	g_nCurrentLine = line;

    lcd_instr((1<<LCD_DDRAM)+addressCounter);
}
Exemplo n.º 3
0
//-----------------------------------------------------------------------------------------
// FUNCTION: lcd_gotoxy
// PURPOSE:  Set cursor to specified position
//           Input:    x  horizontal position  (0: left most position)
//                     y  vertical position    (0: first line)
void lcd_gotoxy(uint8_t x, uint8_t y)
{
#if LCD_LINES==1
    lcd_instr((1<<LCD_DDRAM)+LCD_START_LINE1+x);
#elif LCD_LINES==2
   	switch (y)
	{
		case 0:lcd_instr((1<<LCD_DDRAM)+LCD_START_LINE1+x);break;
    	case 1:lcd_instr((1<<LCD_DDRAM)+LCD_START_LINE2+x);break;
		default: break;
	}
#elif LCD_LINES==4
   	switch (y)
	{
		case 0:lcd_instr((1<<LCD_DDRAM)+LCD_START_LINE1+x);break;
    	case 1:lcd_instr((1<<LCD_DDRAM)+LCD_START_LINE2+x);break;
    	case 2:lcd_instr((1<<LCD_DDRAM)+LCD_START_LINE3+x);break;
    	case 3:lcd_instr((1<<LCD_DDRAM)+LCD_START_LINE4+x);break;
		default: break;
	}
#endif
}
Exemplo n.º 4
0
Arquivo: lcd.c Projeto: gitpan/i2c
/* Initialisierung des Display's 4-BIT , 2 Zeilen */
int lcd_init(void)
{
 int ret;
 ret = iic_tx_pcf8574(8,PCF_ADRESS); // BL EIN RS/RW 0
 usleep(15000);
 ret=lcd_write_nibble(LCD_IR,0x03);
 usleep(5000);
 ret=lcd_write_nibble(LCD_IR,0x03);
 usleep(200);
 ret=lcd_write_nibble(LCD_IR,0x03);
 usleep(50);
 ret=lcd_write_nibble(LCD_IR,0x02);
 ret=lcd_instr(0x28); 		// 4 BIT-Mode , 2 Zeilen
 ret=lcd_instr(LCD_OFF);	// LCD_Off
 ret=lcd_instr(LCD_CLR);	// LCD_Clear
 ret=lcd_instr(0x02);		// Cursor an 1. Stelle
 ret=lcd_instr(0x06);		// Cursor Richtung +1 
 ret=lcd_instr(0x0E);		// Display an , Cursor klein , kein Blinken
 lcd_ADRESS=0; 			// Aktuelle Adresse = 0
 lcd_BACKLIGHT=1;		// Licht ein	
 lcadr=0;
 return ret;
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------------------
// FUNCTION: lcd_home
// PURPOSE:  Set cursor to home position
void lcd_home(void)
{
	g_nCurrentLine = 0;
    lcd_instr(1<<LCD_HOME);
}
Exemplo n.º 6
0
//-----------------------------------------------------------------------------------------
// FUNCTION: lcd_clrscr
// PURPOSE:  Clear display and set cursor to home position
void lcd_clrscr(void)
{
	g_nCurrentLine = 0;
   	lcd_instr(1<<LCD_CLR);
    _delay_us(500);
}
Exemplo n.º 7
0
// PURPOSE:  Set cursor to home position
void HD44780::lcd_home(void)
{
    //g_nCurrentLine = 0;
    lcd_instr(1<<LCD_HOME);
    lcd_setline(0);
}
Exemplo n.º 8
0
// PURPOSE:  Clear display and set cursor to home position
void HD44780::lcd_clrscr(void)
{
    g_nCurrentLine = 0;
    lcd_instr(1<<LCD_CLR);
    fcpu_delay_us(500);
}