LiquidCrystal.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef LiquidCrystal_h
  2. #define LiquidCrystal_h
  3. #include <inttypes.h>
  4. #include "Print.h"
  5. // commands
  6. #define LCD_CLEARDISPLAY 0x01
  7. #define LCD_RETURNHOME 0x02
  8. #define LCD_ENTRYMODESET 0x04
  9. #define LCD_DISPLAYCONTROL 0x08
  10. #define LCD_CURSORSHIFT 0x10
  11. #define LCD_FUNCTIONSET 0x20
  12. #define LCD_SETCGRAMADDR 0x40
  13. #define LCD_SETDDRAMADDR 0x80
  14. // flags for display entry mode
  15. #define LCD_ENTRYRIGHT 0x00
  16. #define LCD_ENTRYLEFT 0x02
  17. #define LCD_ENTRYSHIFTINCREMENT 0x01
  18. #define LCD_ENTRYSHIFTDECREMENT 0x00
  19. // flags for display on/off control
  20. #define LCD_DISPLAYON 0x04
  21. #define LCD_DISPLAYOFF 0x00
  22. #define LCD_CURSORON 0x02
  23. #define LCD_CURSOROFF 0x00
  24. #define LCD_BLINKON 0x01
  25. #define LCD_BLINKOFF 0x00
  26. // flags for display/cursor shift
  27. #define LCD_DISPLAYMOVE 0x08
  28. #define LCD_CURSORMOVE 0x00
  29. #define LCD_MOVERIGHT 0x04
  30. #define LCD_MOVELEFT 0x00
  31. // flags for function set
  32. #define LCD_8BITMODE 0x10
  33. #define LCD_4BITMODE 0x00
  34. #define LCD_2LINE 0x08
  35. #define LCD_1LINE 0x00
  36. #define LCD_5x10DOTS 0x04
  37. #define LCD_5x8DOTS 0x00
  38. class LiquidCrystal : public Print {
  39. public:
  40. LiquidCrystal(uint8_t rs, uint8_t enable,
  41. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  42. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  43. LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  44. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  45. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  46. LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  47. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
  48. LiquidCrystal(uint8_t rs, uint8_t enable,
  49. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
  50. void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
  51. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  52. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  53. void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
  54. void begin_noclear(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
  55. void clear();
  56. void home();
  57. void noDisplay();
  58. void display();
  59. void noBlink();
  60. void blink();
  61. void noCursor();
  62. void cursor();
  63. void scrollDisplayLeft();
  64. void scrollDisplayRight();
  65. void leftToRight();
  66. void rightToLeft();
  67. void autoscroll();
  68. void noAutoscroll();
  69. void createChar(uint8_t, uint8_t[]);
  70. void setCursor(uint8_t, uint8_t);
  71. virtual size_t write(uint8_t);
  72. void command(uint8_t);
  73. using Print::write;
  74. private:
  75. void send(uint8_t, uint8_t);
  76. void write4bits(uint8_t);
  77. void write8bits(uint8_t);
  78. void pulseEnable();
  79. uint8_t _rs_pin; // LOW: command. HIGH: character.
  80. uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
  81. uint8_t _enable_pin; // activated by a HIGH pulse.
  82. uint8_t _data_pins[8];
  83. uint8_t _displayfunction;
  84. uint8_t _displaycontrol;
  85. uint8_t _displaymode;
  86. uint8_t _initialized;
  87. uint8_t _numlines,_currline;
  88. uint8_t _escape[8];
  89. size_t escape_write(uint8_t value);
  90. };
  91. #define ESC_2J "\x1b[2J"
  92. #define ESC_25h "\x1b[?25h"
  93. #define ESC_25l "\x1b[?25l"
  94. #define ESC_H(c,r) "\x1b["#r";"#c"H"
  95. #endif