#ifndef __AMS_20x4LCD_HPP__ #define __AMS_20x4LCD_HPP__ #include #include //https://electronicsforu.com/resources/learn-electronics/16x2-lcd-pinout-diagram // Most LCDs contain Hitachi HD4478 controller. // Arduino may already have a driver for this, but I need to learn // to write my own drivers. class lcd20x4 { public: lcd20x4(); ~lcd20x4(); uint8_t cursx,cursy; void setup(uint8_t RSpin, uint8_t RWpin, uint8_t Epin, const uint8_t* DBpins); void loop(); //11 pin control for 16-pin LCD screen uint8_t pin_RS; //pin 4 register-select //-0 instruction register (read), 1 data register (read/write) uint8_t pin_RW; //pin 5 (read-write) //-0 write, 1 read uint8_t pin_E; //pin 6 enable //high - enable read/write (clock for read/write?) uint8_t pin_DB[8]; //pins 7-14 on LCD //data bus //blocking read/write operations uint8_t read_op(uint8_t b, uint8_t RS); void write_op(uint8_t b, uint8_t RS); //control commands void display_clear(); void cursor_home(); void entrymode(bool ID, bool S); //cursor advance direction and shift mode //I/D - 1:increment/0:decrement S:1 display shift 0:cursor shift? void display_toggle(bool display, bool cursor, bool charblink); void cursor_shift(bool screen_cursor, bool left_right); void CGRAM_set(uint8_t Acg_6bits); //sets CGRAM address - subsequent data is CG data //user generated characters void DDRAM_set(uint8_t Add_7bits); //sets DDRAM address - subsequent data is DD data //00 - 4F (when display not shifted) //DL: data length: 0 - 4-bit, 1 - 8-bit //N: display lines: 0 - 1-line-mode 1 - 2-line-mode //F: font: 0 - 5x8 1 - 5x10 void function_set(bool DL,bool N,bool F); //D: display //C: cursor //B: blink void displayonoff(bool D, bool C, bool B); void setmydefs(); //sets reasonable screen defaults and clears screen //writes a char and advances cursor void set_pos(uint8_t x, uint8_t y); void write_char(char b, uint8_t x, uint8_t y); void write_char(char b); //clears screen and writes a string (32 bytes max) void write_chars(const char *bytes); void newline(); }; #endif