fm_LiquidCrystal_I2C.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // ---------------------------------------------------------------------------
  2. // Created by Francisco Malpartida on 20/08/11.
  3. // Copyright 2011 - Under creative commons license 3.0:
  4. // Attribution-ShareAlike CC BY-SA
  5. //
  6. // This software is furnished "as is", without technical support, and with no
  7. // warranty, express or implied, as to its usefulness for any purpose.
  8. //
  9. // Thread Safe: No
  10. // Extendable: Yes
  11. //
  12. // @file fm_LiquidCrystal_I2C.h
  13. // This file implements a basic liquid crystal library that comes as standard
  14. // in the Arduino SDK but using an I2C IO extension board.
  15. //
  16. // @brief
  17. // This is a basic implementation of the LiquidCrystal library of the
  18. // Arduino SDK. The original library has been reworked in such a way that
  19. // this class implements the all methods to command an fm_LCD based
  20. // on the Hitachi HD44780 and compatible chipsets using I2C extension
  21. // backpacks such as the I2CLCDextraIO with the PCF8574* I2C IO Expander ASIC.
  22. //
  23. // The functionality provided by this class and its base class is identical
  24. // to the original functionality of the Arduino LiquidCrystal library.
  25. //
  26. //
  27. // @author F. Malpartida - fmalpartida@gmail.com
  28. // ---------------------------------------------------------------------------
  29. #ifndef fm_LiquidCrystal_I2C_h
  30. #define fm_LiquidCrystal_I2C_h
  31. //#include <inttypes.h>
  32. //#include <Print.h>
  33. #include "fm_I2CIO.h"
  34. #include "fm_LCD.h"
  35. class fm_LiquidCrystal_I2C : public fm_LCD
  36. {
  37. public:
  38. /*!
  39. @method
  40. @abstract Class constructor.
  41. @discussion Initializes class variables and defines the I2C address of the
  42. fm_LCD. The constructor does not initialize the fm_LCD.
  43. @param lcd_Addr[in] I2C address of the IO expansion module. For I2CLCDextraIO,
  44. the address can be configured using the on board jumpers.
  45. */
  46. fm_LiquidCrystal_I2C (uint8_t lcd_Addr);
  47. // Constructor with backlight control
  48. fm_LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol);
  49. /*!
  50. @method
  51. @abstract Class constructor.
  52. @discussion Initializes class variables and defines the I2C address of the
  53. fm_LCD. The constructor does not initialize the fm_LCD.
  54. @param lcd_Addr[in] I2C address of the IO expansion module. For I2CLCDextraIO,
  55. the address can be configured using the on board jumpers.
  56. @param En[in] fm_LCD En (Enable) pin connected to the IO extender module
  57. @param Rw[in] fm_LCD Rw (Read/write) pin connected to the IO extender module
  58. @param Rs[in] fm_LCD Rs (Reset) pin connected to the IO extender module
  59. */
  60. fm_LiquidCrystal_I2C( uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs);
  61. // Constructor with backlight control
  62. fm_LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
  63. uint8_t backlighPin, t_backlighPol pol);
  64. /*!
  65. @method
  66. @abstract Class constructor.
  67. @discussion Initializes class variables and defines the I2C address of the
  68. fm_LCD. The constructor does not initialize the fm_LCD.
  69. @param lcd_Addr[in] I2C address of the IO expansion module. For I2CLCDextraIO,
  70. the address can be configured using the on board jumpers.
  71. @param En[in] fm_LCD En (Enable) pin connected to the IO extender module
  72. @param Rw[in] fm_LCD Rw (Read/write) pin connected to the IO extender module
  73. @param Rs[in] fm_LCD Rs (Reset) pin connected to the IO extender module
  74. @param d4[in] fm_LCD data 0 pin map on IO extender module
  75. @param d5[in] fm_LCD data 1 pin map on IO extender module
  76. @param d6[in] fm_LCD data 2 pin map on IO extender module
  77. @param d7[in] fm_LCD data 3 pin map on IO extender module
  78. */
  79. fm_LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
  80. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7 );
  81. // Constructor with backlight control
  82. fm_LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
  83. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
  84. uint8_t backlighPin, t_backlighPol pol);
  85. /*!
  86. @function
  87. @abstract fm_LCD initialization and associated HW.
  88. @discussion Initializes the fm_LCD to a given size (col, row). This methods
  89. initializes the fm_LCD, therefore, it MUST be called prior to using any other
  90. method from this class or parent class.
  91. The begin method can be overloaded if necessary to initialize any HW that
  92. is implemented by a library and can't be done during construction, here
  93. we use the Wire class.
  94. @param cols[in] the number of columns that the display has
  95. @param rows[in] the number of rows that the display has
  96. @param charsize[in] size of the characters of the fm_LCD: LCD_5x8DOTS or
  97. LCD_5x10DOTS.
  98. */
  99. virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
  100. /*!
  101. @function
  102. @abstract Send a particular value to the fm_LCD.
  103. @discussion Sends a particular value to the fm_LCD for writing to the fm_LCD or
  104. as an fm_LCD command.
  105. Users should never call this method.
  106. @param value[in] Value to send to the fm_LCD.
  107. @param mode[in] LCD_SEND_DATA - write to the fm_LCD CGRAM, LCD_SEND_CMD - write a
  108. command to the fm_LCD.
  109. */
  110. virtual void send(uint8_t value, uint8_t mode);
  111. virtual void wait(uint16_t us);
  112. /*!
  113. @function
  114. @abstract Sets the pin to control the backlight.
  115. @discussion Sets the pin in the device to control the backlight. This device
  116. doesn't support dimming backlight capability.
  117. @param 0: backlight off, 1..255: backlight on.
  118. */
  119. void setBacklightPin ( uint8_t value, t_backlighPol pol );
  120. /*!
  121. @function
  122. @abstract Switch-on/off the fm_LCD backlight.
  123. @discussion Switch-on/off the fm_LCD backlight.
  124. The setBacklightPin has to be called before setting the backlight for
  125. this method to work. @see setBacklightPin.
  126. @param value: backlight mode (HIGH|LOW)
  127. */
  128. void setBacklight ( uint8_t value );
  129. //private:
  130. /*!
  131. @method
  132. @abstract Initializes the fm_LCD class
  133. @discussion Initializes the fm_LCD class and IO expansion module.
  134. */
  135. int init();
  136. /*!
  137. @function
  138. @abstract Initialises class private variables
  139. @discussion This is the class single point for initialising private variables.
  140. @param lcd_Addr[in] I2C address of the IO expansion module. For I2CLCDextraIO,
  141. the address can be configured using the on board jumpers.
  142. @param En[in] fm_LCD En (Enable) pin connected to the IO extender module
  143. @param Rw[in] fm_LCD Rw (Read/write) pin connected to the IO extender module
  144. @param Rs[in] fm_LCD Rs (Reset) pin connected to the IO extender module
  145. @param d4[in] fm_LCD data 0 pin map on IO extender module
  146. @param d5[in] fm_LCD data 1 pin map on IO extender module
  147. @param d6[in] fm_LCD data 2 pin map on IO extender module
  148. @param d7[in] fm_LCD data 3 pin map on IO extender module
  149. */
  150. void config (uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
  151. uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7 );
  152. /*!
  153. @method
  154. @abstract Writes an 4 bit value to the fm_LCD.
  155. @discussion Writes 4 bits (the least significant) to the fm_LCD control data lines.
  156. @param value[in] Value to write to the fm_LCD
  157. @param more[in] Value to distinguish between command and data.
  158. LCD_SEND_CMD == command, LCD_SEND_DATA == data.
  159. */
  160. void write4bits(uint8_t value, uint8_t mode);
  161. /*!
  162. @method
  163. @abstract Pulse the fm_LCD enable line (En).
  164. @discussion Sends a pulse of 1 uS to the Enable pin to execute an command
  165. or write operation.
  166. */
  167. void pulseEnable(uint8_t);
  168. uint8_t _Addr; // I2C Address of the IO expander
  169. uint8_t _backlightPinMask; // Backlight IO pin mask
  170. uint8_t _backlightStsMask; // Backlight status mask
  171. fm_I2CIO _i2cio; // fm_I2CIO PCF8574* expansion module driver I2CLCDextraIO
  172. uint8_t _En; // fm_LCD expander word for enable pin
  173. uint8_t _Rw; // fm_LCD expander word for R/W pin
  174. uint8_t _Rs; // fm_LCD expander word for Register Select pin
  175. uint8_t _data_pins[4]; // fm_LCD data lines
  176. };
  177. #endif