|
| 1 | +# LiquidCrystal_pcf2119 Library |
| 2 | + |
| 3 | +This library is for character LCDs based on the PCF2119 controller and |
| 4 | +connected via I2C. PCF2119 based displays are pretty rare in the wild, it is |
| 5 | +very likely that this is the wrong library for your display. |
| 6 | + |
| 7 | +The more common case is a LCD based on the HD44780 controller and a parallel |
| 8 | +interface connected to a small interface PCB with an I2C parallel interface |
| 9 | +PCF8544. These two interfaces are **not compatible** with each other. That |
| 10 | +kind of display will require the [LiquidCrystal_I2C](../LiquidCrystal_I2C) |
| 11 | +library instead. |
| 12 | + |
| 13 | +PCF2119 based displays seem to have been used in older fax machines and |
| 14 | +multi function printers, but thery are hard to come by nowerdays (read: |
| 15 | +expensive. North of 20€ at Farnell). |
| 16 | + |
| 17 | +This Library is derived from the Arduino LiquidCrystal library v1.8.0 with |
| 18 | +some additions from the LiquidCrystal_I2C library. |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +## API |
| 23 | + |
| 24 | +This library is a singleton library, it is not possible to use more than one |
| 25 | +instance per sketch. |
| 26 | + |
| 27 | +This Library is an SDuino original: There is no preexisting Arduino library |
| 28 | +for this controller. The API syntax is designed to be very similar to the |
| 29 | +regular [LiquidCrystal library](../LiquidCrystal) for LCDs with a parallel |
| 30 | +interface. The API syntax is very similar to the original C++ syntax, thanks |
| 31 | +to some [c preprocessor macro magic](../../developer/macro). |
| 32 | + |
| 33 | +Apart from the usual name mangeling for polymorph functions (mostly the |
| 34 | +different variants of the Print::print method) moving the opening bracket at |
| 35 | +the class declarator line and replacing the dots in the method names for |
| 36 | +underscores is all it needs. |
| 37 | + |
| 38 | + |
| 39 | +(hypotetical) Arduino syntax |sduino syntax |
| 40 | +-------------------- |--------------------- |
| 41 | +`LiquidCrystal lcd(adr)` |`LiquidCrystal (adr)` |
| 42 | +`LiquidCrystal lcd(adr,reset)` |`LiquidCrystal (adr,reset)` |
| 43 | +`LiquidCrystal lcd(adr,reset,charset)` |`LiquidCrystal (adr,reset,charset)` |
| 44 | +`lcd.init(adr,reset,charset)` |`lcd_init(adr,reset,charset)` |
| 45 | +`lcd.begin(cols,lines)` |`lcd_begin(cols,lines)` |
| 46 | +`lcd.begin(cols,lines,charsize)` |`lcd_begin_charsize(cols,lines,charsize)` |
| 47 | +`lcd.clear()` |`lcd_clear()` |
| 48 | +`lcd.home()` |`lcd_home()` |
| 49 | +`lcd.noDisplay()` |`lcd_noDisplay()` |
| 50 | +`lcd.display()` |`lcd_display()` |
| 51 | +`lcd.noBlink()` |`lcd_noBlink()` |
| 52 | +`lcd.blink()` |`lcd_blink()` |
| 53 | +`lcd.noCursor()` |`lcd_noCursor()` |
| 54 | +`lcd.cursor()` |`lcd_cursor()` |
| 55 | +`lcd.scrollDisplayLeft()` |`lcd_scrollDisplayLeft()` |
| 56 | +`lcd.scrollDisplayRight()` |`lcd_scrollDisplayRight()` |
| 57 | +`lcd.leftToRight()` |`lcd_leftToRight()` |
| 58 | +`lcd.rightToLeft()` |`lcd_rightToLeft()` |
| 59 | +`lcd.noAutoscroll()` |`lcd_noAutoscroll()` |
| 60 | +`lcd.autoscroll()` |`lcd_autoscroll()` |
| 61 | +`lcd.createChar(number, data[])` |`lcd_createChar(number, data[])` |
| 62 | +`lcd.setCursor(col,row)` |`lcd_setCursor(col,row)` |
| 63 | +`result = lcd.write(value)` |`result = lcd_write(value)` |
| 64 | +`result = lcd.data(value)` |`result = lcd_data(value)` |
| 65 | +`lcd.command(value)` |`lcd_command(value)` |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +## Example |
| 70 | + |
| 71 | +Output some Text and count the time since the last reset. Notice the |
| 72 | +slightly different position of the opening parenthesis at the "class |
| 73 | +constructor" function LiquidCrystal compared to the C++ instatiation. |
| 74 | + |
| 75 | +```c |
| 76 | +#include <Arduino.h> |
| 77 | +#include <LiquidCrystal_pcf2119.h> |
| 78 | + |
| 79 | +// initialize the library with the number of the reset pin |
| 80 | +// The instance name "lcd" is *within* the brackets |
| 81 | +LiquidCrystal_pcf2119 (lcd,PA3); |
| 82 | + |
| 83 | +void setup() { |
| 84 | + lcd_begin(16, 2); |
| 85 | + lcd_print_s("hello, world!"); |
| 86 | +} |
| 87 | + |
| 88 | + |
| 89 | +void loop() { |
| 90 | + lcd_setCursor(0, 1); |
| 91 | + lcd_print_u(millis() / 1000); |
| 92 | +} |
| 93 | +``` |
| 94 | +
|
| 95 | +
|
| 96 | +Compare it to the (hypotetical) Arduino C++-Sytax: |
| 97 | +```c |
| 98 | +#include <LiquidCrystal_pcf2119.h> |
| 99 | +
|
| 100 | +// initialize the library with the number of the reset pin |
| 101 | +// The instance name "lcd" is *before* the brackets |
| 102 | +LiquidCrystal_pcf2119 lcd(2); |
| 103 | +
|
| 104 | +void setup() { |
| 105 | + lcd.begin(16, 2); |
| 106 | + lcd.print("hello, world!"); |
| 107 | +} |
| 108 | +
|
| 109 | +void loop() { |
| 110 | + lcd.setCursor(0, 1); |
| 111 | + lcd.print(millis() / 1000); |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | + |
| 116 | +## Differences between this lib and LiquidCrystal_I2C |
| 117 | + |
| 118 | +### Physical interface |
| 119 | + |
| 120 | +The PCF2119 supports the standard command set as the HD44780, the only |
| 121 | +visible difference is the physical interface. Supporting I2C natively means |
| 122 | +very easy read and write access, very similar to the ease of use of a fully |
| 123 | +connected 8 bit parallel interface without losing so many port pins. |
| 124 | + |
| 125 | +This library can be seen as an extended version of the regular |
| 126 | +LiquidCrystal_I2C using 8 bit mode instead of bit-banging a four bit |
| 127 | +interface. Or as an I2C-enabled version of LiquidCrystal in 8-bit mode. |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +### Character mapping |
| 133 | + |
| 134 | +This is a head-banging one. Such an engineering nonsense. The PCF2119 exists |
| 135 | +in six different versions, supporting six different character sets named A, |
| 136 | +D, F, I, R and S. See page 19ff in [the |
| 137 | +datasheet](https://www.nxp.com/docs/en/data-sheet/PCF2119X.pdf). |
| 138 | + |
| 139 | +A is a standard ASCII mapping, R is the most random one where not even space |
| 140 | +is at the position it is supposed to be. And guess which character set is |
| 141 | +used by the modules still available at Farnell? Right, the R set. The left |
| 142 | +over ones no one was willing to buy so far. |
| 143 | + |
| 144 | +This means that the build-in clear function can't be used and the |
| 145 | +ShiftLeft/ShiftRight modes are not useful as they fill up the free space |
| 146 | +with 0x20 - which happens to be an arrow in this character set. Who came up |
| 147 | +with *that* idea? |
| 148 | + |
| 149 | +For character set A, D and I all data is always transferd unmodified. |
| 150 | + |
| 151 | +For character sets F, R and S the `write()` method transparently swaps the |
| 152 | +ASCII ranges 0x20..0x7f and 0xa0..0xff. This allows the use of the regular |
| 153 | +print functions without the need to think about the character encoding. The |
| 154 | +ranges 0x00..0x1f and 0x80..0x9f are transfered unmodified to enable the use |
| 155 | +of user defined characters. |
| 156 | + |
| 157 | +The additional function `data()` writes data directly into the display RAM, |
| 158 | +without any modifications and independed from the chosen character set. |
| 159 | + |
| 160 | +The R set is the default case if no other character is specified at |
| 161 | +instantiation time. So if you were lucky enough to lay your hands on a |
| 162 | +display with a more useful character set, this is the way to tell the |
| 163 | +library about your success: |
| 164 | + |
| 165 | +```c |
| 166 | +// Use character set A instead of the dreaded R |
| 167 | +LiquidCrystal_pcf2119 (lcd,PA3,'A'); |
| 168 | +``` |
| 169 | +
|
| 170 | +
|
| 171 | +
|
| 172 | +## Possible improvements |
| 173 | +
|
| 174 | +This is not a to-do-list, just brainstorming and a collection of random |
| 175 | +thoughts. |
| 176 | +
|
| 177 | +### Unify all the LiquidCrystal libraries |
| 178 | +It would be very slick to unify all three libraries/four interface modes |
| 179 | +into one, similar to |
| 180 | +[NewLiquidCrystal](https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home) |
| 181 | +by Francisco Malpartida. |
0 commit comments