void hd44780fw_write_len(struct hd44780fw_conf* conf, const char* msg, uint8_t msg_len, uint8_t index, uint8_t cb) { uint8_t up_len = 0, i; /* Disable blink while appending chars: */ const uint8_t blink_en_bkup = conf->blink_en; const uint8_t cur_en_bkup = conf->cur_en; hd44780fw_en_blink(conf, HD44780_L_DISP_B_OFF); hd44780fw_en_cursor(conf, HD44780_L_DISP_C_OFF); /* Frequently used constants: */ const uint8_t line1_base_addr = conf->low_conf->line1_base_addr; const uint8_t line2_base_addr = conf->low_conf->line2_base_addr; const uint8_t total_chars = conf->total_chars; const uint8_t half_chars = conf->half_chars; if (cb) { hd44780fw_clear(conf); } if (index >= total_chars || total_chars - index < msg_len) { return; } if (index < half_chars) { if (msg_len + index < line1_base_addr + half_chars) { up_len = msg_len; } else { up_len = half_chars - index; } hd44780_l_set_ddram_addr(conf->low_conf, index + line1_base_addr); for (i = 0; i < up_len; ++i) { hd44780_l_write(conf->low_conf, msg[i]); } hd44780_l_set_ddram_addr(conf->low_conf, line2_base_addr); for (i = up_len; i < msg_len; ++i) { hd44780_l_write(conf->low_conf, msg[i]); } } else { hd44780_l_set_ddram_addr(conf->low_conf, index + line2_base_addr - half_chars); for (i = 0; i < msg_len; ++i) { hd44780_l_write(conf->low_conf, msg[i]); } } /* Enable last blink/cursor state: */ hd44780fw_set_bc_index(conf, conf->last_bc_index); hd44780fw_en_blink(conf, blink_en_bkup); hd44780fw_en_cursor(conf, cur_en_bkup); /* Fix v. cursor: */ conf->last_index = index + msg_len; }
void hd44780fw_build_cc(struct hd44780fw_conf* conf, uint8_t index, const uint8_t* rows) { uint8_t i; uint8_t mult = (conf->font == HD44780_L_FS_F_58 ? 8 : 10); if (conf->font == HD44780_L_FS_F_510) { return; /* Not yet implemented */ } if (index > 7) { return; } hd44780_l_set_cgram_addr(conf->low_conf, index * mult); for (i = 0; i < mult; ++i) { hd44780_l_write(conf->low_conf, rows[i]); /* Write cur. row */ } }
/* Prints the entire RFID tag on the display. */ void printOnLCD(_Bool shipment){ //Eventuellt göra generisk om vi vill skicka in andra värden än cargo hd44780_l_clear_disp(&low_conf); if (shipment == 1) { hd44780_l_write(&low_conf, 0x52); //R hd44780_l_write(&low_conf, 0x46); //F hd44780_l_write(&low_conf, 0x49); //I hd44780_l_write(&low_conf, 0x44); //D hd44780_l_write(&low_conf, 0x3A); //: for(int i = 1; i<11; i++) //Prints the tag's ID bytes. { hd44780_l_write(&low_conf, cargo[i]); } } else { hd44780_l_write(&low_conf, 0x4E); //N hd44780_l_write(&low_conf, 0x4F); //O hd44780_l_write(&low_conf, 0x20); //_ hd44780_l_write(&low_conf, 0x43); //C hd44780_l_write(&low_conf, 0x41); //A hd44780_l_write(&low_conf, 0x52); //R hd44780_l_write(&low_conf, 0x47); //G hd44780_l_write(&low_conf, 0x4F); //O } }
int main(void) { DDRA = 0xFF; DDRD = (1 << DDD5)|(1 << DDD6)|(1 << DDD7); struct hd44780_l_conf low_conf; low_conf.rs_i = 5; low_conf.rw_i = 6; low_conf.en_i = 7; low_conf.db7_i = 7; low_conf.db6_i = 6; low_conf.db5_i = 5; low_conf.db4_i = 4; low_conf.db3_i = 3; low_conf.db2_i = 2; low_conf.db1_i = 1; low_conf.db0_i = 0; low_conf.rs_port = &PORTD; low_conf.rw_port = &PORTD; low_conf.en_port = &PORTD; low_conf.db7_port = &PORTA; low_conf.db6_port = &PORTA; low_conf.db5_port = &PORTA; low_conf.db4_port = &PORTA; low_conf.db3_port = &PORTA; low_conf.db2_port = &PORTA; low_conf.db1_port = &PORTA; low_conf.db0_port = &PORTA; low_conf.line1_base_addr = 0x00; low_conf.line2_base_addr = 0x40; low_conf.dl = HD44780_L_FS_DL_8BIT; hd44780_l_init(&low_conf, HD44780_L_FS_N_DUAL, HD44780_L_FS_F_58, HD44780_L_EMS_ID_INC, HD44780_L_EMS_S_OFF); hd44780_l_disp(&low_conf, HD44780_L_DISP_D_ON, HD44780_L_DISP_C_ON, HD44780_L_DISP_B_ON); //0x42 0x4f 0x4f 0x42 0x49 0x45 0x53 hd44780_l_write(&low_conf, 0x42); hd44780_l_write(&low_conf, 0x4f); hd44780_l_write(&low_conf, 0x4f); hd44780_l_write(&low_conf, 0x42); hd44780_l_write(&low_conf, 0x49); hd44780_l_write(&low_conf, 0x45); hd44780_l_write(&low_conf, 0x53); hd44780_l_write(&low_conf, 0x42); hd44780_l_write(&low_conf, 0x4f); hd44780_l_write(&low_conf, 0x4f); hd44780_l_write(&low_conf, 0x42); hd44780_l_write(&low_conf, 0x49); hd44780_l_write(&low_conf, 0x45); hd44780_l_write(&low_conf, 0x53); while(1) { //TODO:: Please write your application code } }