예제 #1
0
void lcd_init()
{
	// Setup all lcd pins as outputs
	LCD_CONTROL_DDR |= _BV(LCD_RS_PIN) | _BV(LCD_E_PIN);
	LCD_DATA_DDR |= _BV(LCD_DATA0_PIN) | _BV(LCD_DATA1_PIN) | _BV(LCD_DATA2_PIN) | _BV(LCD_DATA3_PIN);

	// Wait for the module
	_delay_ms(200);
	
	// To be safe switch back to 8-bit interface for a moment (Function Set)
	LCD_CONTROL_PORT &= ~_BV(LCD_RS_PIN) & ~_BV(LCD_E_PIN);
	LCD_RST_DATA;
	LCD_DATA_PORT |= _BV(LCD_DATA0_PIN) | _BV(LCD_DATA1_PIN);
	lcd_strobe();
	_delay_ms(10);
	lcd_strobe();
	_delay_ms(10);
	lcd_strobe();
	_delay_ms(10);
	
	// Function Set: switch to 4 bit mode (last 8-bit command)
	LCD_RST_DATA;
	LCD_DATA_PORT |= _BV(LCD_DATA1_PIN);
	lcd_strobe();
	_delay_ms(10);
	
	// Using 4 bit mode now. Repeat Function Set command (2 lines, 5x8 chars, 4-bit mode)
	lcd_cmd(0x28);
	
	lcd_off();
	lcd_clr();
	lcd_cmd(LCD_CMD_DEFAULT_MODE);
	lcd_on();
}
void lcd_write_data(char data)
{
  	char temp1;

    LCD_RS = 1;					// Select LCD for data mode
    __delay_ms(4);				// 40us delay for LCD to settle down

    temp1 = data;
    temp1 = temp1 >> 4;
    PORTD = temp1 & 0x0F;
	__delay_ms(8); 
   	LCD_RS = 1;
    __delay_ms(8);			//_-_ strobe data in

    lcd_strobe();
    __delay_ms(8);

    temp1 = data;
    PORTD = temp1 & 0x0F;
    __delay_ms(8);
	LCD_RS = 1;
    __delay_ms(10); 			//_-_ strobe data in

    lcd_strobe();	
    __delay_ms(10);
}
예제 #3
0
static void cmd(unsigned char command)
{
    RS(0);
    udelay(40);
    LCD(command >> 4);
    lcd_strobe();
    LCD(command);
    lcd_strobe();
}
예제 #4
0
static void data(unsigned char data)
{
    RS(1);
    udelay(40);
    LCD(data >> 4);
    lcd_strobe();
    LCD(data);
    lcd_strobe();
    udelay(10);
    RS(0);
    udelay(10);
}
예제 #5
0
/*!	\brief	Send data/commands to the display. */
static void lcd_write(uint8_t data)
{/* Low level function. */
#if (USE_BUSY_FLAG)
	/* Write data/commands to LCD. */
	CLR(LCD_RW_OUT, LCD_RW);
#endif /* USE_BUSY_FLAG */

	lcd_high(data);
	lcd_strobe();
	lcd_low(data);
	lcd_strobe();
	lcd_low(0xff);

	/* The busy flag must be checked after the 4-bit data has been transferred twice. */
#if (USE_BUSY_FLAG)
	lcd_busy_delay();
#else
	lcd_10us_delay(BUSY_CYCLE_TIME);
#endif /* USE_BUSY_FLAG */
}
예제 #6
0
/*!	\brief	Initializing by instruction. 4-bit interface initialization. */
static void lcd_config(uint8_t param)
{/* Low level function. */
	/* Send commands to LCD. */
	CLR(LCD_RS_OUT, LCD_RS);
#if (USE_BUSY_FLAG)
	/* Write data/commands to LCD. */
	CLR(LCD_RW_OUT, LCD_RW);
#endif /* USE_BUSY_FLAG */

	/* Reset LCD config */
	lcd_high(0x30);
	lcd_strobe();
asm volatile (DELAY_230ns);
	lcd_4takt_delay(11130u);	// >4,1mc
	lcd_strobe();
asm volatile (DELAY_230ns);
	lcd_4takt_delay(280u);	// 100ums
	lcd_strobe();
asm volatile (DELAY_230ns);
	
	/* Set LCD config */
	lcd_high(param);
	lcd_strobe();		// Change 8-bit interface to 4-bit interface
	lcd_10us_delay(BUSY_CYCLE_TIME);
	lcd_strobe();		/* DB7 to DB4 of the "Function set" instruction is written twice. */
	lcd_10us_delay(BUSY_CYCLE_TIME);
	lcd_low(param);
	lcd_strobe();		// 4-bit, two lines, 5x8 pixel
	lcd_10us_delay(BUSY_CYCLE_TIME);
	/* Note: The number of display lines and character font cannot be changed after this point. */
}
void lcd_write_cmd(unsigned char cmd)
{
    unsigned char temp2;
    LCD_RS = 0;					// Select LCD for command mode
    __delay_ms(4);				// 40us delay for LCD to settle down
    temp2 = cmd;
    temp2 = temp2 >> 4;			// Output upper 4 bits, by shifting out lower 4 bits
    PORTD = temp2 & 0x0F;		// Output to PORTD which is connected to LCD

    __delay_ms(8);			// 10ms - Delay at least 1 ms before strobing
    lcd_strobe();
    
	__delay_ms(8);			// 10ms - Delay at least 1 ms after strobing

    temp2 = cmd;				// Re-initialise temp2 
    PORTD = temp2 & 0x0F;		// Mask out upper 4 bits

    __delay_ms(8);			// 10ms - Delay at least 1 ms before strobing
    lcd_strobe();
    __delay_ms(8);			// 10ms - Delay at least 1 ms before strobing

}
예제 #8
0
void lcd_transfer(uint8_t token, uint8_t rs)
{
	LCD_CONTROL_PORT &= ~_BV(LCD_RS_PIN) & ~_BV(LCD_E_PIN);
	if (rs) {
		LCD_CONTROL_PORT |= _BV(LCD_RS_PIN);
	}

	LCD_RST_DATA;
	if (token & 0x80) {
		LCD_DATA_PORT |= _BV(LCD_DATA3_PIN);
	}
	if (token & 0x40) {
		LCD_DATA_PORT |= _BV(LCD_DATA2_PIN);
	}
	if (token & 0x20) {
		LCD_DATA_PORT |= _BV(LCD_DATA1_PIN);
	}
	if (token & 0x10) {
		LCD_DATA_PORT |= _BV(LCD_DATA0_PIN);
	}
	lcd_strobe();
	_delay_ms(10);
	
	LCD_RST_DATA;
	if (token & 0x08) {
		LCD_DATA_PORT |= _BV(LCD_DATA3_PIN);
	}
	if (token & 0x04) {
		LCD_DATA_PORT |= _BV(LCD_DATA2_PIN);
	}
	if (token & 0x02) {
		LCD_DATA_PORT |= _BV(LCD_DATA1_PIN);
	}
	if (token & 0x01) {
		LCD_DATA_PORT |= _BV(LCD_DATA0_PIN);
	}
	lcd_strobe();
	_delay_ms(10);
}
예제 #9
0
/*!	\brief	*/
static void lcd_busy_delay(void)
{
	uint8_t BusyFlag;

	Set_D7_as_Input(); /* Set D7 as input. */
	/* When RS = 0 and R/W = 1, the busy flag is output to DB7. */
	CLR(LCD_RS_OUT, LCD_RS);
	SET(LCD_RW_OUT, LCD_RW);

	do
	{/* Note: two cycles are needed for the busy flag check. */
		/* Read busy flag. */
		lcd_strobe();
		/* D7 is used as busy flag. */
		BusyFlag = GET(LCD_D7_IN, LCD_D7);
		/* Discard D3. */
		lcd_strobe();
		/* Verify the busy flag */
	}while (BusyFlag);

	CLR(LCD_RW_OUT, LCD_RW);
	Set_D7_as_Outut(); /* Restore D7 as the output. */
}
예제 #10
0
static void lcd_write_four_bits(int fd, uint8_t data)
{
      i2c_write_cmd(fd, data | LCD_BACKLIGHT);
      lcd_strobe(fd, data);
}
예제 #11
0
void LCD::lcd_write_four_bits(int data) {
	write_cmd(data | LCD_BACKLIGHT);
    lcd_strobe(data);
}