static void write_register(uint8_t data, bool register_sel) { busy_wait(); if(register_sel) set_rs(); else clear_rs(); clear_rw(); config_bus_output(); output_nibble(data); output_nibble(data << 4); config_bus_input(); }
/* * Writes a byte to the pin register in 2 4 bit nibbles * Uses append/remove functions such that it maintains current pin state */ void write_4_bits(int bits, int char_mode) { usleep(1000); reset_all(); set_rs(char_mode); write_pins_append(bits>>4); pulse_enable(); write_pins_remove(0xf); write_pins_append(bits&0xf); pulse_enable(); usleep(500); reset_all(); }
uint8_t read_register(bool register_sel) { uint8_t data = 0; uint8_t upper4 = 0; uint8_t lower4 = 0; if(register_sel) set_rs(); else clear_rs(); set_rw(); config_bus_input(); upper4 = pulse_e(); lower4 = pulse_e(); data |= upper4; data |= (lower4 >> 4); return data; }