PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

LiquidCrystalFast.h 4.7KB

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef LiquidCrystalFast_h
  2. #define LiquidCrystalFast_h
  3. #include <inttypes.h>
  4. #if defined(ARDUINO) && ARDUINO >= 100
  5. #include "Arduino.h" // for digitalRead, digitalWrite, pinMode, delayMicroseconds
  6. #else
  7. #include "WProgram.h"
  8. #endif
  9. // commands
  10. #define LCD_CLEARDISPLAY 0x01
  11. #define LCD_RETURNHOME 0x02
  12. #define LCD_ENTRYMODESET 0x04
  13. #define LCD_DISPLAYCONTROL 0x08
  14. #define LCD_CURSORSHIFT 0x10
  15. #define LCD_FUNCTIONSET 0x20
  16. #define LCD_SETCGRAMADDR 0x40
  17. #define LCD_SETDDRAMADDR 0x80
  18. // flags for display entry mode
  19. #define LCD_ENTRYRIGHT 0x00
  20. #define LCD_ENTRYLEFT 0x02
  21. #define LCD_ENTRYSHIFTINCREMENT 0x01
  22. #define LCD_ENTRYSHIFTDECREMENT 0x00
  23. // flags for display on/off control
  24. #define LCD_DISPLAYON 0x04
  25. #define LCD_DISPLAYOFF 0x00
  26. #define LCD_CURSORON 0x02
  27. #define LCD_CURSOROFF 0x00
  28. #define LCD_BLINKON 0x01
  29. #define LCD_BLINKOFF 0x00
  30. // flags for display/cursor shift
  31. #define LCD_DISPLAYMOVE 0x08
  32. #define LCD_CURSORMOVE 0x00
  33. #define LCD_MOVERIGHT 0x04
  34. #define LCD_MOVELEFT 0x00
  35. // flags for function set
  36. //#define LCD_8BITMODE 0x10
  37. #define LCD_4BITMODE 0x00
  38. #define LCD_2LINE 0x08
  39. #define LCD_1LINE 0x00
  40. #define LCD_5x10DOTS 0x04
  41. #define LCD_5x8DOTS 0x00
  42. #define LCD_Right 0
  43. #define LCD_Left 1
  44. #define DELAYPERCHAR 320
  45. class LiquidCrystalFast : public Print {
  46. public:
  47. // 6 pin connection (slow): normal LCD, single HD44780 controller
  48. LiquidCrystalFast(uint8_t rs, uint8_t enable,
  49. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) {
  50. init(rs, 255, enable, 255, d4, d5, d6, d7);
  51. }
  52. // 7 pin connection (fast): normal LCD, single HD44780 controller
  53. LiquidCrystalFast(uint8_t rs, uint8_t rw, uint8_t enable,
  54. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) {
  55. init(rs, rw, enable, 255, d4, d5, d6, d7);
  56. }
  57. // 8 pin connection (fast): 4x40 LCD, two HD44780 controller chips
  58. LiquidCrystalFast(uint8_t rs, uint8_t rw, uint8_t enable1, uint8_t enable2,
  59. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) {
  60. init(rs, rw, enable1, enable2, d4, d5, d6, d7);
  61. }
  62. // 10 pin connection - not recommended, for backwards compatibility only
  63. LiquidCrystalFast(uint8_t rs, uint8_t enable,
  64. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  65. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) {
  66. init(rs, 255, enable, 255, d4, d5, d6, d7);
  67. }
  68. // 11 pin connection - not recommended, for backwards compatibility only
  69. LiquidCrystalFast(uint8_t rs, uint8_t rw, uint8_t enable,
  70. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  71. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) {
  72. init(rs, rw, enable, 255, d4, d5, d6, d7);
  73. }
  74. void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
  75. void clear();
  76. void home();
  77. void noDisplay();
  78. void display();
  79. void noBlink();
  80. void blink();
  81. void noCursor();
  82. void cursor();
  83. void scrollDisplayLeft();
  84. void scrollDisplayRight();
  85. void leftToRight();
  86. void rightToLeft();
  87. void autoscroll();
  88. void noAutoscroll();
  89. void createChar(uint8_t, uint8_t[]);
  90. void setCursor(uint8_t, uint8_t);
  91. #if defined(ARDUINO) && ARDUINO >= 100
  92. virtual size_t write(uint8_t);
  93. inline size_t write(unsigned long n) { return write((uint8_t)n); }
  94. inline size_t write(long n) { return write((uint8_t)n); }
  95. inline size_t write(unsigned int n) { return write((uint8_t)n); }
  96. inline size_t write(int n) { return write((uint8_t)n); }
  97. #else
  98. virtual void write(uint8_t);
  99. inline void write(unsigned long n) { write((uint8_t)n); }
  100. inline void write(long n) { write((uint8_t)n); }
  101. inline void write(unsigned int n) { write((uint8_t)n); }
  102. inline void write(int n) { write((uint8_t)n); }
  103. #endif
  104. using Print::write;
  105. void command(uint8_t);
  106. void commandBoth(uint8_t);
  107. inline LiquidCrystalFast& operator() (uint8_t x, uint8_t y) {setCursor(x,y); return *this;} //use along w Streaming.h to support: lcd(col,line)<<"a="<<a;
  108. uint8_t numlines;
  109. uint8_t numcols;
  110. protected:
  111. void init(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
  112. uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
  113. void send(uint8_t, uint8_t);
  114. void write4bits(uint8_t);
  115. void begin2(uint8_t cols, uint8_t rows, uint8_t charsize, uint8_t chip);
  116. inline void delayPerHome(void) { if (_rw_pin == 255) delayMicroseconds(2900);}
  117. uint8_t _rs_pin; // LOW: command. HIGH: character.
  118. uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
  119. uint8_t _enable_pin; // activated by a HIGH pulse.
  120. uint8_t _en2; //4x40 LCD
  121. uint8_t _chip; //4x40
  122. int8_t _scroll_count;
  123. int8_t _x, _y,_setCursFlag;
  124. uint8_t _direction;
  125. uint8_t _busyPin; // for reading the busy flag on the LCD synonmymous w last pin number specified to constructor
  126. uint8_t _data_pins[4];
  127. uint8_t _numcols;
  128. uint8_t _numlines;
  129. uint8_t row_offsets[4];
  130. uint8_t _displaycontrol; //display on/off, cursor on/off, blink on/off
  131. uint8_t _displaymode; //text direction
  132. };
  133. #endif