Exemplo n.º 1
0
int16_t parse_cmd_lcd_clear(char *cmd, char *output, uint16_t len)
{
    if(*cmd)
	{
		uint8_t line = atoi(cmd);

        if (line > (LCD_LINES - 1) )
            return ECMD_ERR_PARSE_ERROR;

        hd44780_goto(line, 0);
        for (uint8_t i = 0; i < LCD_CHAR_PER_LINE; i++)
            fputc(' ', &lcd);
        hd44780_goto(line, 0);

        return ECMD_FINAL_OK;
    }
	else
	{
        hd44780_clear();
        hd44780_goto(0, 0);
        return ECMD_FINAL_OK;
    }
}
Exemplo n.º 2
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;
Exemplo 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, 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 /*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 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
    /* open file descriptor */
    lcd = fdevopen(hd44780_put, NULL);

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


}
Exemplo n.º 4
0
void hd44780_message(const char *s) {
	hd44780_clear();
	hd44780_rewrite_string(s);
}
Exemplo n.º 5
0
/** Główna funkcja programu
*/
int main(void)
{
	FuncPtr FPtr;

	ioinit();

	hd44780_clear();
	hd44780_bl_on();
	hd44780_cursor_off();

	load_basic_settings(EEPROM_BASIC_SETTINGS_BEGIN);
	load_temp_sensors_settings(EEPROM_TEMP_SETTINGS_BEGIN);
	load_outputs_settings(EEPROM_OUTS_SETTING_BEGIN);
	load_timers_settings(EEPROM_TIMERS_SETTING_BEGIN);
	load_timersv_settings(EEPROM_TIMERSV_SETTING_BEGIN);
	load_topoff_settings(EEPROM_TOPOFF_SETTINGS_BEGIN);

	hd44780_printOnLcdDelay(PSTR(PROGRAM_FULL_NAME));
	hd44780_clear();
	sei();

	rtc_get_time();
	rtc_get_date();

	gui_client_present();

	log_write_record(LOG_EVENT_START,0,0,0);

	for (;;) {

		wdt_reset();

		qbuttons_process();

		ui_key_pressed();

		if (key_pressed && alarms_notification_enabled() && alarms_is_active() ){
			alarms_block_notification();
			menu_set(1,1,0,0);
			key_pressed = NONE;
		}

		//########################### akcje wykonywane kiedy minie sekunda
		if (SF(FLAG_SECOND_PAST)) {
			SSF(FLAG_FORCE_LCD_REFRESH);
			temp_counter++;
			top_off_check_time();
			top_off_process();
			CSF(FLAG_SECOND_PAST);
		}

 		//########################### akcje wykonywane kiedy minie pół sekundy
		if (SF(FLAG_HALF_SECOND_PAST)) {
			SSF(FLAG_FORCE_LCD_SEMI_REFRESH);
			if (alarms_is_active() && alarms_notification_enabled()) {
				buzzer_toggle();
			} else {
				buzzer_off();
			}
			CSF(FLAG_HALF_SECOND_PAST);
		}

		//######################################## odświeżenie wyswietlacza LCD
		if (system_flags & LCD_REFRESH_MASK) {
			//if (back_light_counter < LCD_BL_SHUTOFF_TIME) { hd44780_bl_on(); }
			FPtr=(FuncPtr)pgm_read_word(&FuncPtrTable[menu_func_index()]);
			hd44780_outcmd(HD44780_HOME);
			FPtr();
			menu_dummy();
			CSF(FLAG_FORCE_LCD_REFRESH);
			CSF(FLAG_FORCE_LCD_SEMI_REFRESH);
		}

		//########################### akcje wykonywane kiedy minie minuta
		if (SF(FLAG_MINUTE_PAST)) {
			//if (back_light_counter < 0xFF) { back_light_counter++; }
			//if (back_light_counter >= LCD_BL_SHUTOFF_TIME) { hd44780_bl_off(); }
			timers_process();
			timersv_process();
			if (alarms_block_notification_counter < ALARM_MAX_BLOCK_VALUE) {
				alarms_block_notification_counter++;
			}
			CSF(FLAG_MINUTE_PAST);
		}

		//########################### akcje wykonywane kiedy minie godzina
		if (SF(FLAG_HOUR_PAST)) {
			temp_register();
			CSF(FLAG_HOUR_PAST);
		}

		//########################### akcje wykonywane jak minie dzień
		if (SF(FLAG_DAY_PAST)) {
			rtc_get_time();
			rtc_get_date();
			CSF(FLAG_DAY_PAST);
		}

		//########################### pomiar temeratury
		if (temp_counter > TEMP_SENSOR_READ_INTERVAL) {
			temp_read_temperature();
			temp_counter = 0;
		}

		//######################################## obsługa interfejsu szeregowego
        gui_cm_process_char();

        //######################################## aktualizacja stanu wyjść
		outputs_update();
    }
  	return 0;
}