void user_init(void) { uart_set_baud(0, 115200); printf("SDK version:%s\n", sdk_system_get_sdk_version()); i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K); hd44780_t lcd = { .i2c_dev.bus = I2C_BUS, .i2c_dev.addr = ADDR, .font = HD44780_FONT_5X8, .lines = 2, .pins = { .rs = 0, .e = 2, .d4 = 4, .d5 = 5, .d6 = 6, .d7 = 7, .bl = 3 }, .backlight = true }; hd44780_init(&lcd); hd44780_upload_character(&lcd, 0, char_data); hd44780_upload_character(&lcd, 1, char_data + 8); hd44780_gotoxy(&lcd, 0, 0); hd44780_puts(&lcd, "\x08 Hello world!"); hd44780_gotoxy(&lcd, 0, 1); hd44780_puts(&lcd, "\x09 "); char time[16]; while (true) { hd44780_gotoxy(&lcd, 2, 1); snprintf(time, 7, "%u ", sdk_system_get_time() / 1000000); time[sizeof(time) - 1] = 0; hd44780_puts(&lcd, time); for (uint32_t i = 0; i < 1000; i++) sdk_os_delay_us(1000); } }
void main(void) { // lcd display struct dev_hd44780_ctx lcd_ctx; memset((void *)&lcd_ctx, 0x00, sizeof(struct dev_hd44780_ctx)); lcd_ctx.rs.port = &LCD_RS_PORT; lcd_ctx.rs.pin = LCD_RS_PIN; lcd_ctx.e.port = &LCD_E_PORT; lcd_ctx.e.pin = LCD_E_PIN; // setup data lines for (uint8_t x = 0; x<4; x++) { lcd_ctx.data[x].port = &LCD_DB_PORT; lcd_ctx.data[x].pin = LCD_DB_PIN_FIRST + x; } // display specifics lcd_ctx.lines = LCD_NUMBER_OF_LINES; lcd_ctx.font = HD44780_FONT_5X8; // initialize the device hd44780_init(&lcd_ctx); // clear the display initially hd44780_clrscr(&lcd_ctx); hd44780_goto(&lcd_ctx, 0x00); hd44780_puts(&lcd_ctx, "Hello World"); // execution loop for (;;); }
int main(int argc, char* argv[]) { char buffer[80]; initialize(); hd44780_reset(HD44780_CMD_FUNC_SET | HD44780_CMD_FUNC_2LINES); hd44780_ir_write(HD44780_CMD_DISPLAY | HD44780_CMD_DISPLAY_ON | HD44780_CMD_DISPLAY_CURS_ON | HD44780_CMD_DISPLAY_CURS_BLINK ); hd44780_wait_busy(); hd44780_ir_write(HD44780_CMD_EMS | HD44780_CMD_EMS_INCR); hd44780_wait_busy(); adc_calibrate(); adc_start(); while(1) { uint16_t internal_temp = adc_get_median(0), external_temp = adc_get_median(1), battery = adc_get_median(2), reference = adc_get_median(3); //trace_printf("%d %d %d\n", external_temp, internal_temp, reference); uint32_t vdd = 3300u * *VREFINT_CAL / reference; uint32_t internal_temp_volts = internal_temp * vdd / 0xfff, external_temp_volts = external_temp * vdd / 0xfff, battery_volts = battery * vdd / 0xfff; int len = snprintf(buffer, sizeof(buffer), "%04x %04x %04x %04x", internal_temp, external_temp, battery, reference); //hd44780_clear_screen(); hd44780_goto_addr(0); hd44780_puts(buffer, len); len = snprintf(buffer, sizeof(buffer), "%ld.%03ld %ld.%03ld %ld.%03ld", internal_temp_volts / 1000, internal_temp_volts % 1000, external_temp_volts / 1000, external_temp_volts % 1000, battery_volts / 1000, battery_volts % 1000); hd44780_goto_addr(64); hd44780_puts(buffer, len); int32_t internal_temp_celsius = (int32_t)steinhart(internal_temp) - 273150; int32_t external_temp_celsius = hot_junction_temperature(internal_temp, external_temp, reference); len = snprintf(buffer, sizeof(buffer), "%ld.%03d %ld.%05d", internal_temp_celsius / 1000, abs(internal_temp_celsius) % 1000, external_temp_celsius / 100000, abs(external_temp_celsius) % 100000); hd44780_goto_addr(20); hd44780_puts(buffer, len); len = snprintf(buffer, sizeof(buffer), "%lu.%03lu", vdd / 1000, vdd % 1000); hd44780_goto_addr(84); hd44780_puts(buffer, len); delay_1ms(1000); } }