Beispiel #1
0
void setup_LCD() {
  uint8_t i;

  // wait 50ms for LCD to come up
  Delay(50);

  // reset pins to all 0
  send_LCD(0);
  DelayUS(4500);

  for(i = 0; i < 3; i++) { // try three times to set LCD into a known state (re-sync half-byte stream)
    // start by setting 8 bit mode
    send_halfbyte(LCD_FUNCTIONSET|LCD_8BITMODE);
    DelayUS(4500); // wait a minimum of 4.1ms
  }

  // set in 4 bit mode
  send_halfbyte(LCD_FUNCTIONSET|LCD_4BITMODE);

  // set # of lines, font size, etc
  send_byte(LCD_FUNCTIONSET|LCD_2LINE|LCD_4BITMODE|LCD_5x8DOTS, 0);

  // TODO: does this need a modifier?
  // turn on display
  send_byte(LCD_BACKLIGHT|LCD_DISPLAYON|LCD_CURSOROFF|LCD_BLINKOFF, 0);

  LCD_clear();

  // left to right
  send_byte(LCD_ENTRYMODESET|LCD_ENTRYLEFT|LCD_ENTRYSHIFTDECREMENT, 0);

  LCD_home();

  LCD_print_char('B');
}
Beispiel #2
0
/*
	Initialize the LCD using proper delays and commands.
*/
void LCD_init( void )
{

	// Set pins as outputs
	LCDPORT->DIR |= (~LCD_MASK & 0xFFF);
	LCDPORT_CTRL_RS->DIR |= (1<<RS);
	LCDPORT_CTRL_E->DIR |= (1<<ENABLE);

	// Initial delay
	_delay_ms( 15 );

	// Initial instuctions
	unsigned char i;
	for (i = 0; i < 3; i++ )
	{
		LCDPORT->DATA &= LCD_MASK ; //Set used pins to zero
		LCDPORT_CTRL_RS->DATA &= ~(1<<RS);

		LCDPORT->DATA |= 0x03 << LCD_OFFSET;	//And set up the command
		_LCD_pulse();

		_delay_ms( 5 );
	}

	// Set 4bit mode
	LCDPORT->DATA &= LCD_MASK;
	LCDPORT->DATA |= 0x02<<LCD_OFFSET;
	_LCD_pulse();

	// Set 2-row display
	LCD_sendCmd( 0x28 );

	// Display off
	LCD_sendCmd( 0x08 );

	// Clear display
	LCD_clear();

	// Set incrementmode, no shift
	LCD_sendCmd( 0x06 );

	// Turn LCD on and set cursor to home
	LCD_sendCmd( 0x0C );
	LCD_home();
}
uint8 LCD_init(){

    i2c_master_start();
    i2c_master_writeByte(LCD_ADDRESS << 1);
    if (!i2c_master_checkAck()) {
        i2c_master_stop();
        return 0;
    }
    i2c_master_stop();

    _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;

    if (LCD_ROW > 1) {
        _displayfunction |= LCD_2LINE;
    }
    _numlines = LCD_ROW;

    // for some 1 line displays you can select a 10 pixel high font
    if ((LCD_DOTSIZE != 0) && (LCD_ROW == 1)) {
        _displayfunction |= LCD_5x10DOTS;
    }

    // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
    // according to datasheet, we need at least 40ms after power rises above 2.7V
    // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
    os_delay_us(50000); 
  
    // Now we pull both RS and R/W low to begin commands
    LCD_expanderWrite(0);   // reset expanderand turn backlight off
    os_delay_us(1000000);

    //put the LCD into 4 bit mode
    // this is according to the hitachi HD44780 datasheet
    // figure 24, pg 46
    
    // we start in 8bit mode, try to set 4 bit mode
    LCD_write4bits(0x30);
    os_delay_us(4500); // wait min 4.1ms
    
    // second try
    LCD_write4bits(0x30);
    os_delay_us(4500); // wait min 4.1ms
    
    // third go!
    LCD_write4bits(0x30); 
    os_delay_us(150);
    
    // finally, set to 4-bit interface
    LCD_write4bits(0x20); 


    // set # lines, font size, etc.
    LCD_command(LCD_FUNCTIONSET | _displayfunction);  
    
    // turn the display on with no cursor or blinking default
    _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
    LCD_display();
    
    // clear it off
    LCD_clear();
    
    // Initialize to default text direction (for roman languages)
    _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
    
    // set the entry mode
    LCD_command(LCD_ENTRYMODESET | _displaymode);
    
    LCD_home();

    return 1;
}