Ejemplo n.º 1
0
int16_t parse_cmd_lcd_init(char *cmd, char *output, uint16_t len)
{
	uint8_t cursor, blink;

#ifdef TEENSY_SUPPORT
	/* Skip leading spaces. */
	while(*cmd == ' ') cmd ++;

	/* Seek space (blink argument), chop and atoi to `blink'.  */
	char *p = cmd;
	while(*p && *p != ' ') p ++;
	if(!*p)
		return ECMD_ERR_PARSE_ERROR; /* Required argument `blink' missing. */

	*p = 0;
	blink = atoi(p + 1);
	cursor = atoi(cmd);
#else
	int ret = sscanf_P(cmd, PSTR("%hhu %hhu"), &cursor, &blink);
	if(ret != 2)
		return ECMD_ERR_PARSE_ERROR;
#endif

    hd44780_init();
    hd44780_config(cursor, blink,1);
    return ECMD_FINAL_OK;
}
Ejemplo n.º 2
0
void hd44780_init(void)
{

    /* init io pins */
    CTRL_OUTPUT();
    PIN_CLEAR(HD44780_RS);
    PIN_CLEAR(HD44780_EN);
#ifdef HAVE_HD44780_RW
    PIN_CLEAR(HD44780_RW);
#endif
    PIN_CLEAR(HD44780_D4);
    PIN_CLEAR(HD44780_D5);
    PIN_CLEAR(HD44780_D6);
    PIN_CLEAR(HD44780_D7);
    DATA_OUTPUT();

    _delay_ms(40);
    PIN_SET(HD44780_D4);
    PIN_SET(HD44780_D5);
    clock_write();

    _delay_ms(4);
    clock_write();

    _delay_ms(1);
    clock_write();

    /* init done */
    _delay_ms(1);
    PIN_CLEAR(HD44780_D4);
    clock_write();
    _delay_ms(1);

    /* configure for 4 bit, 2 lines, 5x9 font (datasheet, page 24) */
    output_byte(0, CMD_FUNCTIONSET(0, 1, 0));

    /* turn on display, cursor and blinking */
    hd44780_config(0,0);

    /* clear display */
    hd44780_clear();

    /* set shift and increment */
    output_byte(0, CMD_ENTRY_MODE(1, 0));

    /* set ddram address */
    output_byte(0, CMD_SETDRAMADR(0));

    /* open file descriptor */
    lcd = fdevopen(hd44780_put, NULL);
    
    /* set current virtual postion */
    current_pos = 0;
}
Ejemplo n.º 3
0
void hd44780_init(void)
{
    /* verschiedene Hardware initialisieren */
    hd44780_hw_init();
    _delay_ms(40);

#if HD44780_TYPE == HD44780_KS0066U
    /* Hardware initialisiert -> Standardprozedur KS0066U Datenblatt 4bit Mode */
    output_nibble(0, 0x02);
#else
    /* Hardware initialisiert -> Standardprozedur HD44780 Datenblatt 4bit Mode */
    output_nibble(0, 0x03);

    _delay_ms(4);
    clock_write();

    _delay_ms(1);
    clock_write();

    _delay_ms(1);
    output_nibble(0, 0x02);		//4bit mode
    _delay_ms(1);
    /* init done */
#endif

    /* configure for 4 bit, 2 lines, 5x9 font (datasheet, page 24) */
    output_byte(0, CMD_FUNCTIONSET(0, 1, 0));

    /* turn on display, cursor and blinking */
    hd44780_config(0,0);

    /* clear display */
    hd44780_clear();

    /* set shift and increment */
    output_byte(0, CMD_ENTRY_MODE(1, 0));

    /* set ddram address */
    output_byte(0, CMD_SETDRAMADR(0));

    /* open file descriptor */
    lcd = fdevopen(hd44780_put, NULL);

    /* set current virtual postion */
    current_pos = 0;
}
Ejemplo n.º 4
0
HD44780_Result hd44780_init(HD44780 *display, HD44780_Mode mode,
  const HD44780_Config *config, uint8_t cols, uint8_t lines, uint8_t charsize)
{
  HD44780_RETURN_ASSERT(display != NULL, HD44780_RESULT_ERROR);
  HD44780_RETURN_ASSERT(config != NULL, HD44780_RESULT_ERROR);
  HD44780_RETURN_ASSERT(config->gpios != NULL, HD44780_RESULT_ERROR);
  HD44780_RETURN_ASSERT(config->gpios->write != NULL, HD44780_RESULT_ERROR);
  HD44780_RETURN_ASSERT(config->delay_microseconds != NULL, HD44780_RESULT_ERROR);
  HD44780_RETURN_ASSERT(cols > 0, HD44780_RESULT_ERROR);
  HD44780_RETURN_ASSERT(lines > 0, HD44780_RESULT_ERROR);

  display->cfg = *config;

  HD44780_GPIO_Interface *const gpios = display->cfg.gpios;
  HD44780_DelayMicrosecondsFn delay_microseconds = display->cfg.delay_microseconds;

  if (gpios->configure != NULL)
  {
    HD44780_RETURN_IF_ERROR(gpios->configure(gpios, HD44780_PIN_RS, HD44780_PINMODE_OUTPUT));
    HD44780_RETURN_IF_ERROR(gpios->configure(gpios, HD44780_PIN_ENABLE, HD44780_PINMODE_OUTPUT));

    if (display->cfg.options & HD44780_OPT_USE_RW)
      HD44780_RETURN_IF_ERROR(gpios->configure(gpios, HD44780_PIN_RW, HD44780_PINMODE_OUTPUT));

    if (display->cfg.options & HD44780_OPT_USE_BACKLIGHT)
      HD44780_RETURN_IF_ERROR(gpios->configure(gpios, HD44780_PIN_BACKLIGHT, HD44780_PINMODE_OUTPUT));
  }

  if (display->cfg.options & HD44780_OPT_USE_BACKLIGHT)
    HD44780_RETURN_IF_ERROR(gpios->write(gpios, HD44780_PIN_BACKLIGHT, HD44780_PINSTATE_LOW));

  if (mode == HD44780_MODE_4BIT)
  {
    display->displayfunction = HD44780_FLAG_4BITMODE | HD44780_FLAG_1LINE | HD44780_FLAG_5x8DOTS;
    display->dp_first = HD44780_PIN_DP4;
    display->dp_amount = 4;
  }
  else
  {
    display->displayfunction = HD44780_FLAG_8BITMODE | HD44780_FLAG_1LINE | HD44780_FLAG_5x8DOTS;
    display->dp_first = HD44780_PIN_DP0;
    display->dp_amount = 8;
  }

  /* For some 1 line displays you can select a 10 pixel high font */
  if ((charsize != 0) && (lines == 1))
    display->displayfunction |= HD44780_FLAG_5x10DOTS;

  if (lines > 1)
    display->displayfunction |= HD44780_FLAG_2LINE;

  display->columns_amount = cols;
  display->lines_amount = lines;
  display->currline = 0;

  if (hd44780_config(display) != HD44780_RESULT_OK)
    return HD44780_RESULT_ERROR;

  /* Put the LCD into 4 bit or 8 bit mode */
  if (! (display->displayfunction & HD44780_FLAG_8BITMODE))
  {
    /* This is according to the hitachi HD44780 datasheet figure 24, pg 46 */

    /* We start in 8bit mode, try to set 4 bit mode */
    HD44780_RETURN_IF_ERROR(hd44780_write_bits(display, 0x03));
    delay_microseconds(4500); // wait min 4.1ms

    /* Second try */
    HD44780_RETURN_IF_ERROR(hd44780_write_bits(display, 0x03));
    delay_microseconds(4500); // wait min 4.1ms

    /* Third go! */
    HD44780_RETURN_IF_ERROR(hd44780_write_bits(display, 0x03));
    delay_microseconds(150);

    /* Finally, set to 4-bit interface */
    HD44780_RETURN_IF_ERROR(hd44780_write_bits(display, 0x02));
  }
  else
  {
    /* This is according to the hitachi HD44780 datasheet page 45 figure 23 */

    /* Send function set command sequence */
    HD44780_RETURN_IF_ERROR(hd44780_command(display, HD44780_CMD_FUNCTIONSET | display->displayfunction));
    delay_microseconds(4500);  // wait more than 4.1ms

    /* Second try */
    HD44780_RETURN_IF_ERROR(hd44780_command(display, HD44780_CMD_FUNCTIONSET | display->displayfunction));
    delay_microseconds(150);

    /* Third go */
    HD44780_RETURN_IF_ERROR(hd44780_command(display, HD44780_CMD_FUNCTIONSET | display->displayfunction));
  }

  /* Finally, set # lines, font size, etc. */
  HD44780_RETURN_IF_ERROR(hd44780_command(display, HD44780_CMD_FUNCTIONSET | display->displayfunction));

  /* Turn the display on with no cursor or blinking default */
  display->displaycontrol = HD44780_FLAG_DISPLAYON | HD44780_FLAG_CURSOROFF | HD44780_FLAG_BLINKOFF;
  HD44780_RETURN_IF_ERROR(hd44780_display_on(display));

  /* Clear it off */
  HD44780_RETURN_IF_ERROR(hd44780_clear(display));
  /* Initialize to default text direction (for romance languages) */
  display->displaymode = HD44780_FLAG_ENTRYLEFT | HD44780_FLAG_ENTRYSHIFTDECREMENT;
  /* Set the entry mode */
  HD44780_RETURN_IF_ERROR(hd44780_command(display, HD44780_CMD_ENTRYMODESET | display->displaymode));

  return HD44780_RESULT_OK;
Ejemplo n.º 5
0
void hd44780_init(void)
{
    /* verschiedene Hardware initialisieren */
    hd44780_hw_init();
    _delay_ms(40);

#if CONF_HD44780_TYPE == HD44780_KS0066U
    /* Hardware initialisiert -> Standardprozedur KS0066U Datenblatt 4bit Mode */
    output_nibble(0, 0x02, 1);
#else
    /* Hardware initialisiert -> Standardprozedur HD44780 Datenblatt 4bit Mode */
    output_nibble(0, 0x03,1);

    _delay_ms(4);
#ifdef HD44780_2WIRE
    output_nibble(0, 0x03,1);
#else
    clock_write(1);
#endif /*HD44780_2WIRE*/

    _delay_ms(1);
#ifdef HD44780_2WIRE
	output_nibble(0, 0x03,1);
#else
    clock_write(1);
#endif /*HD44780_2WIRE*/

    _delay_ms(1);
    output_nibble(0, 0x02,1);		//4bit mode
    _delay_ms(1);
    /* init done */
#endif /*CONF_HD44780_TYPE*/

    /* configure for 4 bit, 2 lines, 5x8 font (datasheet, page 24) */
    output_byte(0, CMD_FUNCTIONSET(0, 1, 0), 1);

    /* turn on display, cursor and blinking */
    hd44780_config(0,0,1);

    /* clear display */
    hd44780_clear(1);
    /* set shift and increment */
    output_byte(0, CMD_ENTRY_MODE(1, 0),1);

    /* set ddram address */
    output_byte(0, CMD_SETDRAMADR(0),1);

/*Configure Controller 2 */
#ifdef HD44780_MULTIENSUPPORT
    /* verschiedene Hardware initialisieren */
    hd44780_hw_init();
    _delay_ms(40);

#if CONF_HD44780_TYPE == HD44780_KS0066U
    /* Hardware initialisiert -> Standardprozedur KS0066U Datenblatt 4bit Mode */
    output_nibble(0, 0x02, 2);
#else
    /* Hardware initialisiert -> Standardprozedur HD44780 Datenblatt 4bit Mode */
    output_nibble(0, 0x03,2);

    _delay_ms(4);
    clock_write(2);

    _delay_ms(1);
    clock_write(2);

    _delay_ms(1);
    output_nibble(0, 0x02,2);		//4bit mode
    _delay_ms(1);
    /* init done */
#endif

    /* configure for 4 bit, 2 lines, 5x9 font (datasheet, page 24) */
    output_byte(0, CMD_FUNCTIONSET(0, 1, 0), 2);

    /* turn on display, cursor and blinking */
    hd44780_config(0,0,2);

    /* clear display */
    hd44780_clear(2);
    /* set shift and increment */
    output_byte(0, CMD_ENTRY_MODE(1, 0),2);

    /* set ddram address */
    output_byte(0, CMD_SETDRAMADR(0),2);
#endif

    /* set current virtual postion */
    current_pos = 0;


}