/* * 20180128 Initial release version 1.00 * 20180129 Version 1.10 * 20180201 Version 1.20 */ #ifndef LiquidCrystal_7228_h #define LiquidCrystal_7228_h #include #include "Print.h" // lcd commands #define LCD_SFF 0x10 //Set LCD frame rate #define LCD_SMM 0x18 //Set LCD multiplex mode #define LCD_DISP_OFF 0x08 //Turn display off #define LCD_DISP_ON 0x09 //Turn display on #define LCD_LDPI 0x80 //Move cursor (load data immediate) #define LCD_SRM 0x60 //Set read mode #define LCD_SWM 0x64 //Set write mode #define LCD_SORM 0x68 //Set data OR mode #define LCD_SANDM 0x6C //Set data AND mode #define LCD_SCML 0x71 //Set character left-to-right entry mode #define LCD_SCMR 0x72 //Set character right-to-left entry mode #define LCD_BRESET 0x20 //Clear a data bit #define LCD_BSET 0x40 //Set a data bit #define LCD_CLCURS 0x7C //Clear character cursor #define LCD_WRCURS 0x7D //Set (write) character cursor #define LCD_STOP 0x01 //Halt the LCD controller // There are three modes of display, can write characters, 8 bit bytes, or individual bits // Writing characters or their cursor inc/dec the internal column counter by 5 #define left 0x00 //left chip, master chip always 0x00 #define right 0x01 //right chip, usually 0x01 or 0x11 #define cmd_flag 1 //writing a command #define data_flag 0 //writing data #define auto_inc 0x00 //auto increment #define auto_dec 0x01 //auto decrement #define auto_none 0x03 //don't move data cursor after operation #define TRUE 1; #define FALSE 0; #define pwmRegister OCR1B //the logical pin, can be set to OCR1A or B class LiquidCrystal_7228 : public Print { public: LiquidCrystal_7228(uint8_t bsy, uint8_t stb, uint8_t cs, uint8_t c_d, uint8_t rst, int clk, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); void init(uint8_t bsy, uint8_t stb, uint8_t cs, uint8_t c_d, uint8_t rst, int clk, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); void begin(uint8_t cols, uint8_t rows); void clear(); void home(); void noDisplay(); void display(); void noBlink(); void blink(); void noCursor(); void cursor(); void scrollDisplayLeft(); void scrollDisplayRight(); void leftToRight(); void rightToLeft(); void autoScroll(); void noAutoscroll(); void lineWrap(); void noLinewrap(); void dataMode(uint8_t data_mode); void noDataMode(); // void setRowOffsets(int row1, int row2, int row3, int row4); void createChar(uint8_t, uint8_t[]); void setCursor(uint8_t, uint8_t); void dataPlot(uint8_t x, uint8_t y, uint8_t plot_type); void barGraph(uint8_t x, uint8_t bank); virtual size_t write(uint8_t); void command(uint8_t); using Print::write; private: void setup_nibble(uint8_t value); void write_nibble(uint8_t code, uint8_t chip, uint8_t flag); void lcd_cmd(uint8_t cmd); void lcd_char(char asci); void chip_init(); void fillDisplay(void); void scrollBackward(void); void scrollForward(void); void write_data(uint8_t aByte, uint8_t chip); //our character cursor position uint8_t col; uint8_t row; uint8_t num_cols; //number of character columns on the display uint8_t num_rows; //number of character rows (prog only tested with 2 lines) uint8_t text_dir; //left-to-right or right-to-left entry mode? uint8_t autoscroll_on; //autoscroll the line as characters entered? uint8_t cursor_on; //display visible cursor? uint8_t wrap_on; //wrap lines back to start of line? uint8_t data_on; //data mode or character mode char buffer[20][2]; //Arduino pins, allocated at run time uint8_t _busy_pin; uint8_t _strobe_pin; uint8_t _select_pin; uint8_t _command_pin; uint8_t _reset_pin; int outPin; //the clock physical pin uint8_t _data_pins[4]; //settings for pwm clock pin long period = 1; //the LCD clock period in microseconds (1=1MHz, 2=500MHz) int duty = 512; //duty as a range from 0 to 1024, 512 is 50% duty cycle int prescale[6] = {0, 1, 8, 64, 256, 1024}; //the range of prescale values }; #endif