|
| 1 | +# LiquidCrystal Library |
| 2 | + |
| 3 | +This library is for character LCDs based on the HD44780 controller. |
| 4 | +Derived from the Arduino LiquidCrystal library v1.8.0. |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +## Example |
| 9 | + |
| 10 | +Output some Text and count the time since the last reset. Mind the |
| 11 | +slightly different position of the opening parenthesis at the "class |
| 12 | +constructor" function LiquidCrystal_4bit_r compared to the C++ instatiation. |
| 13 | + |
| 14 | +```c |
| 15 | +#include <Arduino.h> |
| 16 | +#include <LiquidCrystal.h> |
| 17 | + |
| 18 | +// initialize the library with the numbers of the interface pins |
| 19 | +// The instance name "lcd" is _within_ the brackets |
| 20 | +LiquidCrystal_4bit_r (lcd,PA1,PA2, PA3,PD2,PD3,PD4); |
| 21 | + |
| 22 | +void setup() { |
| 23 | + lcd_begin(16, 2); |
| 24 | + lcd_print_s("hello, world!"); |
| 25 | +} |
| 26 | + |
| 27 | + |
| 28 | +void loop() { |
| 29 | + lcd_setCursor(0, 1); |
| 30 | + lcd_print_u(millis() / 1000); |
| 31 | +} |
| 32 | +``` |
| 33 | +
|
| 34 | +
|
| 35 | +Original Arduino C++-Sytax: |
| 36 | +```c |
| 37 | +#include <LiquidCrystal.h> |
| 38 | +
|
| 39 | +// initialize the library with the numbers of the interface pins |
| 40 | +// The instance name "lcd" is _before_ the brackets |
| 41 | +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); |
| 42 | +
|
| 43 | +void setup() { |
| 44 | + lcd.begin(16, 2); |
| 45 | + lcd.print("hello, world!"); |
| 46 | +} |
| 47 | +
|
| 48 | +void loop() { |
| 49 | + lcd.setCursor(0, 1); |
| 50 | + lcd.print(millis() / 1000); |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +## API |
| 57 | + |
| 58 | +This library is a singleton library, it is not possible to use more than one |
| 59 | +instance per sketch. |
| 60 | + |
| 61 | +The API syntax is very similar to the original C++ syntax, thanks to some |
| 62 | +[c preprocessor macro magic](macro.html). |
| 63 | +Apart from the usual name mangeling for polymorph functions replacing the |
| 64 | +dots in the method names for underscores and a small modification of the |
| 65 | +initializer code should be enough. |
| 66 | + |
| 67 | +The polymorph instantiation method is split into for different macros. Only |
| 68 | +one can be used per sketch. The choice for one of them has to be made at |
| 69 | +compile time. Changing the LCD mode at run time can be done by calling the |
| 70 | +`lcd_init(...)` function. |
| 71 | + |
| 72 | + |
| 73 | +Arduino syntax |sduino syntax |
| 74 | +-------------------- |--------------------- |
| 75 | +`LiquidCrystal lcd(rs,en,d0,d1,d2,d3)` |`LiquidCrystal_4bit_r (lcd,rs,en,d0,d1,d2,d3)` |
| 76 | +`LiquidCrystal lcd(rs,rw,en,d0,d1,d2,d3)` |`LiquidCrystal_4bit_rw (lcd,rs,rw,en,d0,d1,d2,d3)` |
| 77 | +`LiquidCrystal lcd(rs,en,d0,d1,d2,d3,d4,d5,d6,d7)` |`LiquidCrystal_8bit_r (lcd,rs,en,d0,d1,d2,d3,d4,d5,d6,d7)` |
| 78 | +`LiquidCrystal lcd(rs,rw,en,d0,d1,d2,d3,d4,d5,d6,d7)` |`LiquidCrystal_8bit_rw (lcd,rs,rw,en,d0,d1,d2,d3,d4,d5,d6,d7)` |
| 79 | +`lcd.init(rs,rw,en,d0,d1,d2,d3,d4,d5,d6,d7)`|`lcd_init(mode,rs,rw,en,d0,d1,d2,d3,d4,d5,d6,d7)` |
| 80 | +`lcd.begin(cols,lines)` |`lcd_begin(cols,lines)` |
| 81 | +`lcd.begin(cols,lines,charsize)` |`lcd_begin_charsize(cols,lines,charsize)` |
| 82 | +`lcd.clear()` |`lcd_clear()` |
| 83 | +`lcd.home()` |`lcd_home()` |
| 84 | +`lcd.noDisplay()` |`lcd_noDisplay()` |
| 85 | +`lcd.display()` |`lcd_display()` |
| 86 | +`lcd.noBlink()` |`lcd_noBlink()` |
| 87 | +`lcd.blink()` |`lcd_blink()` |
| 88 | +`lcd.noCursor()` |`lcd_noCursor()` |
| 89 | +`lcd.cursor()` |`lcd_cursor()` |
| 90 | +`lcd.scrollDisplayLeft()` |`lcd_scrollDisplayLeft()` |
| 91 | +`lcd.scrollDisplayRight()` |`lcd_scrollDisplayRight()` |
| 92 | +`lcd.leftToRight()` |`lcd_leftToRight()` |
| 93 | +`lcd.rightToLeft()` |`lcd_rightToLeft()` |
| 94 | +`lcd.noAutoscroll()` |`lcd_noAutoscroll()` |
| 95 | +`lcd.autoscroll()` |`lcd_autoscroll()` |
| 96 | +`lcd.setRowOffsets(row0,row1,row2,row3)`|`lcd_setRowOffsets(row0,row1,row2,row3)` |
| 97 | +`lcd.createChar(number, data[])` |`lcd_createChar(number, data[])` |
| 98 | +`lcd.setCursor(col,row)` |`lcd_setCursor(col,row)` |
| 99 | +`result = lcd.write(value)` |`result = lcd_write(value)` |
| 100 | +`lcd.command(value)` |`lcd_command(value)` |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +## Possible improvements |
| 105 | + |
| 106 | + |
| 107 | +### Direct port access |
| 108 | +As long as the pin numberings are known at compile time it would be possible |
| 109 | +use direct port register access and the access pattern could be optimized if |
| 110 | +all data pins are on the same port. |
| 111 | + |
| 112 | + |
| 113 | +### Auto-detect 4-bit mode |
| 114 | +The parameter `fourbitmode` of the init() function/method is not needed. It |
| 115 | +would be sufficient to check `d5` for a valid value. If it is not valid, |
| 116 | +assume 4-bit mode. |
| 117 | + |
| 118 | +As init() is not called very frequently the possible advantage would be small |
| 119 | +compared to the downside of breaking the Arduino compatibility. |
0 commit comments