kopia lustrzana https://github.com/k3ng/k3ng_cw_keyer
Added support for LCD type: I2C 1602 with backlight using TwiLiquidCrystal-library (#117)
rodzic
f41d349a4e
commit
56067b18b5
|
@ -1545,6 +1545,11 @@ If you offer a hardware kit using this software, show your appreciation by sendi
|
|||
#include <LiquidCrystal_I2C.h>
|
||||
#endif
|
||||
|
||||
#if defined(FEATURE_LCD_TWILIQUIDCRYSTAL)
|
||||
#include <TwiLiquidCrystal.h>
|
||||
#include <Wire.h>
|
||||
#endif
|
||||
|
||||
#if defined(FEATURE_LCD_ADAFRUIT_I2C)
|
||||
#include <Adafruit_MCP23017.h>
|
||||
#include <Adafruit_RGBLCDShield.h>
|
||||
|
@ -1995,6 +2000,10 @@ byte send_buffer_status = SERIAL_SEND_BUFFER_NORMAL;
|
|||
LiquidCrystal_I2C lcd(lcd_i2c_address_ydv1_lcd, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // for FEATURE_LCD_YDv1; set the LCD I2C address needed for LCM1602 IC V1
|
||||
#endif
|
||||
|
||||
#if defined(FEATURE_LCD_TWILIQUIDCRYSTAL)
|
||||
TwiLiquidCrystal lcd(lcd_i2c_address_twiliquidcrystal_lcd);
|
||||
#endif
|
||||
|
||||
#if defined(FEATURE_LCD_FABO_PCF8574)
|
||||
FaBoLCD_PCF8574 lcd;
|
||||
#endif
|
||||
|
@ -18285,7 +18294,9 @@ void initialize_display(){
|
|||
#ifdef FEATURE_LCD_ADAFRUIT_I2C
|
||||
lcd.setBacklight(lcdcolor);
|
||||
#endif //FEATURE_LCD_ADAFRUIT_I2C
|
||||
|
||||
#ifdef FEATURE_LCD_TWILIQUIDCRYSTAL
|
||||
lcd.backlight();
|
||||
#endif
|
||||
#ifdef FEATURE_LCD_ADAFRUIT_BACKPACK
|
||||
lcd.setBacklight(HIGH);
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#if defined(FEATURE_LCD_4BIT) || defined(FEATURE_LCD_8BIT) || defined(FEATURE_LCD_ADAFRUIT_I2C) || defined(FEATURE_LCD_ADAFRUIT_BACKPACK) || defined(FEATURE_LCD_YDv1) ||defined(FEATURE_LCD1602_N07DH) || defined(FEATURE_LCD_SAINSMART_I2C) || defined(FEATURE_LCD_FABO_PCF8574) || defined(FEATURE_LCD_MATHERTEL_PCF8574) || defined(FEATURE_LCD_HD44780) || defined(FEATURE_LCD_I2C_FDEBRABANDER)
|
||||
#if defined(FEATURE_LCD_4BIT) || defined(FEATURE_LCD_8BIT) || defined(FEATURE_LCD_ADAFRUIT_I2C) || defined(FEATURE_LCD_ADAFRUIT_BACKPACK) || defined(FEATURE_LCD_YDv1) ||defined(FEATURE_LCD1602_N07DH) || defined(FEATURE_LCD_SAINSMART_I2C) || defined(FEATURE_LCD_FABO_PCF8574) || defined(FEATURE_LCD_MATHERTEL_PCF8574) || defined(FEATURE_LCD_HD44780) || defined(FEATURE_LCD_I2C_FDEBRABANDER) || defined(FEATURE_LCD_TWILIQUIDCRYSTAL)
|
||||
#define FEATURE_DISPLAY
|
||||
#endif
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
// #define FEATURE_LCD_ADAFRUIT_I2C // Adafruit I2C LCD display using MCP23017 at addr 0x20
|
||||
// #define FEATURE_LCD_ADAFRUIT_BACKPACK // Adafruit I2C LCD Backup using MCP23008 (courtesy Josiah Ritchie, KE0BLL)
|
||||
// #define FEATURE_LCD_YDv1 // YourDuino I2C LCD display with old LCM 1602 V1 ic
|
||||
// #define FEATURE_LCD_TWILIQUIDCRYSTAL // I2C 1602 with backlight using https://github.com/arnakazim/TwiLiquidCrystal-library
|
||||
// #define FEATURE_LCD1602_N07DH // http://linksprite.com/wiki/index.php5?title=16_X_2_LCD_Keypad_Shield_for_Arduino
|
||||
// #define FEATURE_LCD_SAINSMART_I2C
|
||||
// #define FEATURE_LCD_FABO_PCF8574 // https://github.com/FaBoPlatform/FaBoLCD-PCF8574-Library
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#define lcd_i2c_address_ydv1_lcd 0x27 // I2C address of display for FEATURE_LCD_YDv1
|
||||
//#define lcd_i2c_address_ydv1_lcd 0x38 // I2C address of display for FEATURE_LCD_YDv1
|
||||
#define lcd_i2c_address_sainsmart_lcd 0x27 // I2C address of display for FEATURE_LCD_SAINSMART_I2C
|
||||
#define lcd_i2c_address_twiliquidcrystal_lcd 0x27 // I2C address of display for FEATURE_LCD_TWILIQUIDCRYSTAL
|
||||
#define hell_pixel_microseconds 4025
|
||||
#define program_memory_limit_consec_spaces 1
|
||||
#define serial_leading_zeros 1 // set to 1 to activate leading zeros in serial numbers (i.e. #1 = 001)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
|
@ -0,0 +1,71 @@
|
|||
# Arnakazim's TwiLiquidCrystal Arduino Library
|
||||
|
||||
## About
|
||||
|
||||
A library to interface an HD44780 based LCD via I2C (or TWI in Arduino terms).
|
||||
|
||||
Like its counterpart the LiquidCrystal library, this library allows an Arduino board to control Liquid Crystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The difference is that instead of using multiple digital pins, it communicates with the Arduino via TWI (I2C) with the help of an I2C backpack attached to the LCD.
|
||||
|
||||
## Q&A
|
||||
|
||||
__Why another I2C/TWI LCD display library for Arduino?__
|
||||
|
||||
That's a good question with a simple answer: there is no need for another one. I am in the process on making a board around an ATMega328P and I am planning to use a HD44780 base 16x2 display over I2C.
|
||||
|
||||
I was using LiquidCrystal_I2C at first, but it is not well maintained and is basically a copy/paste of LiquidCrystal with a different write4bits() function. It is nice from far, but the LiquidCrystal library isn't so perfect...
|
||||
|
||||
So, I have retrieved the HD44780 datasheet, read from it and started writing my own library. It worked fine for what I needed, but then I was "why not making it LiquidCrystal compatible?". And there I am.
|
||||
|
||||
At the moment it is 99% compatible. Timings are improved from the original library.
|
||||
|
||||
__What is a TWI/I2C backpack for my LCD?__
|
||||
|
||||
An I2C backpack is a module you connect in between your LCD and your Arduino. It enables communicating with the LCD via I2C. You willl be able to communicate via only two pins from your Arduino, instead of six or 10.
|
||||
|
||||
You can buy I2C backpack on [Adafruit shop](https://www.adafruit.com/product/292) for example.
|
||||
|
||||
The pinout to communicate using I2C on your Arduino depends on its model. You can find more information on the [Arduino website](https://www.arduino.cc/en/reference/wire).
|
||||
|
||||
__What's the difference with the Arduino LiquidCrystal library?__
|
||||
|
||||
For you? Not much. If you have a sketch using the LiquidCrystal library, you can easily switch to this one. The only thing is that you will need an I2C backpack for your LCD.
|
||||
|
||||
To switch from the LiquidCrystal library to the TwiLiquidCrystal it is simple. After rewiring your LCD screen, simply replace the library include and the type of your lcd variable and its parameters. That's all! Here is an example:
|
||||
|
||||
With the LiquidCrystal library you would use:
|
||||
|
||||
```cpp
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
|
||||
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
|
||||
```
|
||||
|
||||
And to use the same code with TwiLiquidCrystal you would simple replace this code by:
|
||||
|
||||
```cpp
|
||||
#include <TwiLiquidCrystal.h>
|
||||
|
||||
const int twiAddress = 0x27; // The I2C address of your LCD backpack
|
||||
TwiLiquidCrystal lcd(twiAddress);
|
||||
```
|
||||
|
||||
__Can I help improve this library?__
|
||||
|
||||
Of course you can help! One of my goals is to keep this library active, bug free and updated. If you've seen a problem with this library or you think you can improve it I am open to all suggestions!
|
||||
|
||||
__Why so many delays in the library code?__
|
||||
|
||||
The HD44780 is a time sensitive chipset. It needs delays to register commands and execute them. I have reduced them as much as I can, according to the HD44780 datasheet (<https://www.sparkfun.com/datasheets/LCD/HD44780.pdf>). The thing is, the datasheet says that it takes nano seconds for certain action. The library does at best microseconds so there is a bit of time loss there. Also transmitting data over I2C takes time. I don't have an oscilloscope at hand, but I am pretty sure some delays aren't needed anymore or can be shortened...
|
||||
|
||||
__Hey! I find your library usefull. Can I buy you a beer?__
|
||||
|
||||
Yes of course! You can tip me via my Ko-fi page. If I don't invest it in my future projects, I'll make sure to at least invest it in a beer ;)
|
||||
|
||||
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/B0B03OTWP)
|
||||
|
||||
__Can I sell a product using your library?__
|
||||
|
||||
Haven't you read the licence file? Of course you can! I've made this project in the public domain via the Unlicense license. I did not wrote this library to make money and if it can help others, even to make money, I would make me really happy. And if you make a few bucks with it and you want to thank me, you can help me with a tip (see previous answer).
|
||||
|
||||
This is free and unencumbered software released into the public domain. For more information, see http://unlicense.org/ or the accompanying (un)LICENSE file.
|
|
@ -0,0 +1,260 @@
|
|||
/*
|
||||
Library created in February 2021
|
||||
by Arnaud Ouvrier (http://www.arnaudouvrier.fr)
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
For more information, see http://unlicense.org/ or
|
||||
the accompanying (un)LICENSE file
|
||||
|
||||
https://github.com/arnakazim/TwiLiquidCrystal-library
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
#include "TwiLiquidCrystal.h"
|
||||
|
||||
TwiLiquidCrystal::TwiLiquidCrystal(uint8_t address) {
|
||||
_i2cLcdAddress = address;
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::setRowOffsets(int row1, int row2, int row3, int row4) {
|
||||
_rowOffsets[0] = row1;
|
||||
_rowOffsets[1] = row2;
|
||||
_rowOffsets[2] = row3;
|
||||
_rowOffsets[3] = row4;
|
||||
}
|
||||
|
||||
// write a byte to the I2C bus
|
||||
size_t TwiLiquidCrystal::write(uint8_t byte) {
|
||||
_ctrlRegister |= RS_BIT; // Set register to DATA
|
||||
sendCmd(byte);
|
||||
_ctrlRegister &= ~RS_BIT; // Reset register to INSTRUCTION
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::send(uint8_t byte) {
|
||||
Wire.beginTransmission(_i2cLcdAddress);
|
||||
Wire.write(byte);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
// Set the state of a bit in the Control register
|
||||
void TwiLiquidCrystal::setCtrlRegisterBit(uint8_t bit, bool state) {
|
||||
if(state) _ctrlRegister |= bit;
|
||||
else _ctrlRegister &= ~bit;
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::setDsplRegisterBit(uint8_t bit, bool state) {
|
||||
if(state) _dsplRegister |= bit;
|
||||
else _dsplRegister &= ~bit;
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::setEntryModeBit(uint8_t bit, bool state) {
|
||||
if(state) _modeRegister |= bit;
|
||||
else _modeRegister &= ~bit;
|
||||
}
|
||||
|
||||
// Merge the command quartet with the control command (BL EN RW RS)
|
||||
void TwiLiquidCrystal::sendQuartet(uint8_t data) {
|
||||
data |= _ctrlRegister;
|
||||
|
||||
send(data);
|
||||
send(data | EN_BIT); // pulse enable
|
||||
delayMicroseconds(1);
|
||||
send(data);
|
||||
delayMicroseconds(42);
|
||||
}
|
||||
|
||||
// Take a command byte and split it in two quartets (LCD in 4 bit mode)
|
||||
void TwiLiquidCrystal::sendCmd(uint8_t data) {
|
||||
sendQuartet(data & DATA_PORTION);
|
||||
sendQuartet((data << 4) & DATA_PORTION);
|
||||
}
|
||||
|
||||
// Initialization routine to set the LCD to 4 bit mode
|
||||
void TwiLiquidCrystal::initializationRoutine() {
|
||||
// Init in 8-bit
|
||||
// LiquidCrystal was outputing 0x30 4500µs - 0x30 4500µs 0x30 150µs
|
||||
// The datasheet for the HD44780 says 0x30 4100µs - 0x30 100µs 0x30 no delay...
|
||||
// (HD44780U datasheet, page 45)
|
||||
// It also may be optionnal, useful only when "the power supply conditions for correctly operating the internal reset circuit are not met"
|
||||
sendQuartet(LCD_FUNCTIONSET | LCD_FUNCTIONSET_DL_BIT);
|
||||
delayMicroseconds(4200);
|
||||
sendQuartet(LCD_FUNCTIONSET | LCD_FUNCTIONSET_DL_BIT);
|
||||
delayMicroseconds(110);
|
||||
sendQuartet(LCD_FUNCTIONSET | LCD_FUNCTIONSET_DL_BIT);
|
||||
|
||||
// set in 4-bit mode (Function set)
|
||||
sendQuartet(LCD_FUNCTIONSET);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::setBacklight(bool state) {
|
||||
setCtrlRegisterBit(BL_BIT, state);
|
||||
send(_ctrlRegister);
|
||||
}
|
||||
|
||||
// set the function register
|
||||
// bytemode = 0 -> 4-bit mode; twoLines = 1 -> 2 lines; font = 0 -> 5x8 dots, 1 = 5x10
|
||||
void TwiLiquidCrystal::setFctnRegister(uint8_t bytemode, uint8_t twoLines, uint8_t font) {
|
||||
_fctnRegister = 0 | (bytemode << 4) | (twoLines << 3) | (font << 2);
|
||||
sendCmd(LCD_FUNCTIONSET | _fctnRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::setDsplControl(uint8_t display, uint8_t cursor, uint8_t blink) {
|
||||
_dsplRegister = 0 | (display << 2) | (cursor << 1) | blink;
|
||||
sendCmd(LCD_DISPLAYCONTROL | _dsplRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::setEntryMode(uint8_t increment, uint8_t shift) {
|
||||
_modeRegister = 0 | (increment << 1) | shift;
|
||||
sendCmd(LCD_ENTRYMODESET | _modeRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::setCursor(uint8_t col, uint8_t row) {
|
||||
if ((row >= _rows) | (row >= 4)) {
|
||||
row = _rows - 1;
|
||||
}
|
||||
sendCmd(LCD_SETDDRAMADDR | (col + _rowOffsets[row]));
|
||||
}
|
||||
|
||||
// Clear the display
|
||||
void TwiLiquidCrystal::clear() {
|
||||
sendCmd(LCD_CLEARDISPLAY);
|
||||
delay(2);
|
||||
}
|
||||
|
||||
// Set cursor to 0;0 position
|
||||
void TwiLiquidCrystal::home() {
|
||||
sendCmd(LCD_RETURNHOME);
|
||||
delay(2);
|
||||
}
|
||||
|
||||
// Setting up and initializig the LCD
|
||||
void TwiLiquidCrystal::begin(uint8_t cols, uint8_t rows, uint8_t font) {
|
||||
Wire.begin();
|
||||
|
||||
_cols = cols;
|
||||
_rows = rows;
|
||||
_font = font;
|
||||
|
||||
// set rows start address
|
||||
// On a 16x2:
|
||||
// line 1, screen 1 [0x00 ; 0x0F]
|
||||
// line 2, screen 1 [0x40 ; 0x4F]
|
||||
// line 1, screen 2 [0x10 ; 0x1F]
|
||||
// line 2, screen 2 [0x50 ; 0x5F]
|
||||
// On a 20x4 (only one screen, HD44780 can only store 80 characters):
|
||||
// (Remark: on a 20x4, incrementing the cursor col give this result:
|
||||
// Line 1 -> Line 3 -> Line 2 -> Line 4)
|
||||
// line 1, screen 1 [0x00 ; 0x13]
|
||||
// line 2, screen 1 [0x40 ; 0x53]
|
||||
// line 3, screen 1 [0x14 ; 0x27]
|
||||
// line 4, screen 1 [0x54 ; 0x67]
|
||||
setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols);
|
||||
|
||||
|
||||
delay(1000); // LCD power up time
|
||||
|
||||
send(0x00); // clear data line
|
||||
initializationRoutine();
|
||||
|
||||
// first params(byte) = 0 -> Always 4bit
|
||||
setFctnRegister(0, (rows != 1), font);
|
||||
|
||||
clear();
|
||||
setDsplControl(1, 0, 0);
|
||||
setEntryMode(1, 0);
|
||||
home();
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::createChar(uint8_t index, uint8_t character[]) {
|
||||
index &= 0x7; // 7 editable characters
|
||||
|
||||
sendCmd(LCD_SETCGRAMADDR | (index << 3));
|
||||
_ctrlRegister |= RS_BIT; // Set register to DATA
|
||||
for (uint8_t i=0; i<8; i++) {
|
||||
sendCmd(character[i]);
|
||||
}
|
||||
_ctrlRegister &= ~RS_BIT; // Reset register to INSTRUCTION
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::selectScreen(uint8_t index) {
|
||||
home();
|
||||
|
||||
for (uint8_t i = 0; i < index * _cols; i++) {
|
||||
sendCmd(LCD_CURSORSHIFT | LCD_CURSORSHIFT_SC_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::backlight() {
|
||||
setBacklight(true);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::noBacklight() {
|
||||
setBacklight(false);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::display() {
|
||||
setDsplRegisterBit(LCD_DISPLAYCONTROL_D_BIT, true);
|
||||
sendCmd(LCD_DISPLAYCONTROL | _dsplRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::noDisplay() {
|
||||
setDsplRegisterBit(LCD_DISPLAYCONTROL_D_BIT, false);
|
||||
sendCmd(LCD_DISPLAYCONTROL | _dsplRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::blink(){
|
||||
setDsplRegisterBit(LCD_DISPLAYCONTROL_B_BIT, true);
|
||||
sendCmd(LCD_DISPLAYCONTROL | _dsplRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::noBlink() {
|
||||
setDsplRegisterBit(LCD_DISPLAYCONTROL_B_BIT, false);
|
||||
sendCmd(LCD_DISPLAYCONTROL | _dsplRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::cursor() {
|
||||
setDsplRegisterBit(LCD_DISPLAYCONTROL_C_BIT, true);
|
||||
sendCmd(LCD_DISPLAYCONTROL | _dsplRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::noCursor() {
|
||||
setDsplRegisterBit(LCD_DISPLAYCONTROL_C_BIT, false);
|
||||
sendCmd(LCD_DISPLAYCONTROL | _dsplRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::leftToRight() {
|
||||
setEntryModeBit(LCD_ENTRYMODESET_ID_BIT, true);
|
||||
sendCmd(LCD_ENTRYMODESET | _modeRegister);
|
||||
}
|
||||
|
||||
// This is for text that flows Right to Left
|
||||
void TwiLiquidCrystal::rightToLeft() {
|
||||
setEntryModeBit(LCD_ENTRYMODESET_ID_BIT, false);
|
||||
sendCmd(LCD_ENTRYMODESET | _modeRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::autoscroll(void) {
|
||||
setEntryModeBit(LCD_ENTRYMODESET_S_BIT, true);
|
||||
sendCmd(LCD_ENTRYMODESET | _modeRegister);
|
||||
}
|
||||
|
||||
// This will 'left justify' text from the cursor
|
||||
void TwiLiquidCrystal::noAutoscroll(void) {
|
||||
setEntryModeBit(LCD_ENTRYMODESET_S_BIT, false);
|
||||
sendCmd(LCD_ENTRYMODESET | _modeRegister);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::scrollDisplayLeft(void) {
|
||||
sendCmd(LCD_CURSORSHIFT | LCD_CURSORSHIFT_SC_BIT);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::scrollDisplayRight(void) {
|
||||
sendCmd(LCD_CURSORSHIFT | LCD_CURSORSHIFT_RL_BIT | LCD_CURSORSHIFT_SC_BIT);
|
||||
}
|
||||
|
||||
void TwiLiquidCrystal::command(uint8_t value) {
|
||||
sendCmd(value);
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
Library created in February 2021
|
||||
by Arnaud Ouvrier (http://www.arnaudouvrier.fr)
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
For more information, see http://unlicense.org/ or
|
||||
the accompanying (un)LICENSE file
|
||||
|
||||
https://github.com/arnakazim/TwiLiquidCrystal-library
|
||||
*/
|
||||
|
||||
#ifndef TwiLiquidCrystal_h
|
||||
#define TwiLiquidCrystal_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
#include "Print.h"
|
||||
|
||||
/*
|
||||
* Control bit defintions
|
||||
*/
|
||||
|
||||
#define BL_BIT 0b00001000 // Backlight bit
|
||||
#define EN_BIT 0b00000100 // Enable bit
|
||||
#define RW_BIT 0b00000010 // Read/Write bit
|
||||
#define RS_BIT 0b00000001 // Register select bit
|
||||
|
||||
#define DATA_PORTION 0b11110000 // D7 D6 D5 D4
|
||||
#define CTRL_PORTION 0b00001111 // BL EN RW RS
|
||||
|
||||
#define LCD_5x10DOTS 1
|
||||
#define LCD_5x8DOTS 0
|
||||
|
||||
/*
|
||||
* Command definitions
|
||||
*
|
||||
* LCD_CLEARDISPLAY
|
||||
* LCD_RETURNHOME
|
||||
* LCD_ENTRYMODESET
|
||||
* I/D = 1 -> Increment cursor pos
|
||||
* S = 0 -> No shift
|
||||
* LCD_DISPLAYCONTROL
|
||||
* D = 0 -> Display off
|
||||
* C = 0 -> Cursor off
|
||||
* B = 0 -> Blinking off
|
||||
* LCD_CURSORSHIFT
|
||||
* S/C = 0 -> Shift cursor (1 for screen)
|
||||
* R/L = 0 -> To the right
|
||||
* LCD_FUNCTIONSET
|
||||
* DL = 1 -> 8-bit interface data
|
||||
* N = 0 -> 1-line display
|
||||
* F = 0 -> 5 × 8 dot character font
|
||||
* LCD_SETCGRAMADDR
|
||||
* LCD_SETDDRAMADDR
|
||||
*/
|
||||
|
||||
#define LCD_CLEARDISPLAY 0b00000001 // 0 0 0 0 0 0 0 1
|
||||
#define LCD_RETURNHOME 0b00000010 // 0 0 0 0 0 0 1 -
|
||||
#define LCD_ENTRYMODESET 0b00000100 // 0 0 0 0 0 1 I/D S
|
||||
#define LCD_DISPLAYCONTROL 0b00001000 // 0 0 0 0 1 D C B
|
||||
#define LCD_CURSORSHIFT 0b00010000 // 0 0 0 1 S/C R/L - -
|
||||
#define LCD_FUNCTIONSET 0b00100000 // 0 0 1 DL N F - -
|
||||
#define LCD_SETCGRAMADDR 0b01000000 // 0 1 ACG ACG ACG ACG ACG ACG
|
||||
#define LCD_SETDDRAMADDR 0b10000000 // 1 ADD ADD ADD ADD ADD ADD ADD
|
||||
|
||||
/*
|
||||
* Command parameters
|
||||
*/
|
||||
#define LCD_ENTRYMODESET_ID_BIT 0b00000010
|
||||
#define LCD_ENTRYMODESET_S_BIT 0b00000001
|
||||
|
||||
#define LCD_DISPLAYCONTROL_D_BIT 0b00000100
|
||||
#define LCD_DISPLAYCONTROL_C_BIT 0b00000010
|
||||
#define LCD_DISPLAYCONTROL_B_BIT 0b00000001
|
||||
|
||||
#define LCD_CURSORSHIFT_SC_BIT 0b00001000
|
||||
#define LCD_CURSORSHIFT_RL_BIT 0b00000100
|
||||
|
||||
#define LCD_FUNCTIONSET_DL_BIT 0b00010000
|
||||
#define LCD_FUNCTIONSET_N_BIT 0b00001000
|
||||
#define LCD_FUNCTIONSET_F_BIT 0b00000100
|
||||
|
||||
class TwiLiquidCrystal : public Print
|
||||
{
|
||||
private:
|
||||
/*
|
||||
* Registers to store settings
|
||||
*/
|
||||
uint8_t _ctrlRegister = 0b00000000; // To store BL EN RS RW bits state
|
||||
uint8_t _dsplRegister = 0b00000000; // To store the display settings
|
||||
uint8_t _modeRegister = 0b00000000; // To store the mode settings
|
||||
uint8_t _fctnRegister = 0b00000000; // To store the function settings
|
||||
|
||||
/*
|
||||
* LCD settings
|
||||
*/
|
||||
uint8_t _i2cLcdAddress;
|
||||
uint8_t _cols;
|
||||
uint8_t _rows;
|
||||
uint8_t _font;
|
||||
|
||||
uint8_t _rowOffsets[4];
|
||||
|
||||
void initializationRoutine();
|
||||
|
||||
void send(uint8_t data);
|
||||
void sendQuartet(uint8_t data);
|
||||
void setCtrlRegisterBit(uint8_t bit, bool state);
|
||||
void setDsplRegisterBit(uint8_t bit, bool state);
|
||||
void setEntryModeBit(uint8_t bit, bool state);
|
||||
void sendCmd(uint8_t data);
|
||||
public:
|
||||
TwiLiquidCrystal(uint8_t address);
|
||||
|
||||
void begin(uint8_t cols, uint8_t rows, uint8_t font = LCD_5x8DOTS);
|
||||
|
||||
void setCursor(uint8_t col, uint8_t row = 0);
|
||||
void setBacklight(bool state);
|
||||
void clear();
|
||||
void home();
|
||||
void createChar(uint8_t index, uint8_t character[]);
|
||||
void selectScreen(uint8_t index);
|
||||
|
||||
virtual size_t write(uint8_t);
|
||||
|
||||
// Faster than using LiquidCrystal Library compatible functions
|
||||
// Set multiple bits, send one time
|
||||
void setFctnRegister(uint8_t bytemode, uint8_t lines, uint8_t font = LCD_5x8DOTS);
|
||||
void setDsplControl(uint8_t display, uint8_t cursor, uint8_t blink);
|
||||
void setEntryMode(uint8_t increment, uint8_t shift);
|
||||
void setRowOffsets(int row1, int row2, int row3, int row4);
|
||||
|
||||
// LiquidCrystal Library compatible functions
|
||||
// Set one bit, send one time
|
||||
void backlight();
|
||||
void noBacklight();
|
||||
void display();
|
||||
void noDisplay();
|
||||
void blink();
|
||||
void noBlink();
|
||||
void cursor();
|
||||
void noCursor();
|
||||
void leftToRight();
|
||||
void rightToLeft();
|
||||
void autoscroll();
|
||||
void noAutoscroll();
|
||||
void scrollDisplayLeft();
|
||||
void scrollDisplayRight();
|
||||
inline void command(uint8_t value);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
name=TwiLiquidCrytal by Arnakazim
|
||||
version=1.0.1
|
||||
author=Arnaud Ouvrier (Arnakazim) <arnaud@arnaudouvrier.fr>
|
||||
maintainer=Arnaud Ouvrier (Arnakazim) <arnaud@arnaudouvrier.fr>
|
||||
sentence=A library to interface an HD44780 based LCD via I2C (or TWI in Arduino terms).
|
||||
paragraph=Like its counterpart the LiquidCrystal library, this library allows an Arduino board to control Liquid Crystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The difference is that instead of using multiple digital pins, it communicates with the Arduino via TWI (I2C) with the help of an I2C backpack attached to the LCD.
|
||||
category=Display
|
||||
url=https://github.com/arnakazim/TwiLiquidCrystal-library
|
||||
architectures=avr
|
||||
includes=TwiLiquidCrystal.h
|
||||
depends=Wire
|
Ładowanie…
Reference in New Issue