123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- #include "LiquidCrystal_I2C.h"
- #include <inttypes.h>
- #if defined(ARDUINO) && ARDUINO >= 100
- #include "Arduino.h"
- #define printIIC(args) Wire.write(args)
- inline size_t LiquidCrystal_I2C::write(uint8_t value) {
- send(value, Rs);
- return 1;
- }
- #else
- #include "WProgram.h"
- #define printIIC(args) Wire.send(args)
- inline void LiquidCrystal_I2C::write(uint8_t value) {
- send(value, Rs);
- }
- #endif
- #include "Wire.h"
- LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows)
- {
- _Addr = lcd_Addr;
- _cols = lcd_cols;
- _rows = lcd_rows;
- _backlightval = LCD_NOBACKLIGHT;
- }
- void LiquidCrystal_I2C::init(){
- init_priv();
- }
- void LiquidCrystal_I2C::init_priv()
- {
- Wire.begin();
- _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
- begin(_cols, _rows);
- }
- void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
- if (lines > 1) {
- _displayfunction |= LCD_2LINE;
- }
- _numlines = lines;
-
- if ((dotsize != 0) && (lines == 1)) {
- _displayfunction |= LCD_5x10DOTS;
- }
-
-
-
- delay(50);
-
-
- expanderWrite(_backlightval);
- delay(1000);
-
-
-
-
-
- write4bits(0x03 << 4);
- delayMicroseconds(4500);
-
-
- write4bits(0x03 << 4);
- delayMicroseconds(4500);
-
-
- write4bits(0x03 << 4);
- delayMicroseconds(150);
-
-
- write4bits(0x02 << 4);
-
- command(LCD_FUNCTIONSET | _displayfunction);
-
-
- _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
- display();
-
-
- clear();
-
-
- _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
-
-
- command(LCD_ENTRYMODESET | _displaymode);
-
- home();
-
- }
- void LiquidCrystal_I2C::clear(){
- command(LCD_CLEARDISPLAY);
- delayMicroseconds(2000);
- }
- void LiquidCrystal_I2C::home(){
- command(LCD_RETURNHOME);
- delayMicroseconds(2000);
- }
- void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){
- int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
- if ( row > _numlines ) {
- row = _numlines-1;
- }
- command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
- }
- void LiquidCrystal_I2C::noDisplay() {
- _displaycontrol &= ~LCD_DISPLAYON;
- command(LCD_DISPLAYCONTROL | _displaycontrol);
- }
- void LiquidCrystal_I2C::display() {
- _displaycontrol |= LCD_DISPLAYON;
- command(LCD_DISPLAYCONTROL | _displaycontrol);
- }
- void LiquidCrystal_I2C::noCursor() {
- _displaycontrol &= ~LCD_CURSORON;
- command(LCD_DISPLAYCONTROL | _displaycontrol);
- }
- void LiquidCrystal_I2C::cursor() {
- _displaycontrol |= LCD_CURSORON;
- command(LCD_DISPLAYCONTROL | _displaycontrol);
- }
- void LiquidCrystal_I2C::noBlink() {
- _displaycontrol &= ~LCD_BLINKON;
- command(LCD_DISPLAYCONTROL | _displaycontrol);
- }
- void LiquidCrystal_I2C::blink() {
- _displaycontrol |= LCD_BLINKON;
- command(LCD_DISPLAYCONTROL | _displaycontrol);
- }
- void LiquidCrystal_I2C::scrollDisplayLeft(void) {
- command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
- }
- void LiquidCrystal_I2C::scrollDisplayRight(void) {
- command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
- }
- void LiquidCrystal_I2C::leftToRight(void) {
- _displaymode |= LCD_ENTRYLEFT;
- command(LCD_ENTRYMODESET | _displaymode);
- }
- void LiquidCrystal_I2C::rightToLeft(void) {
- _displaymode &= ~LCD_ENTRYLEFT;
- command(LCD_ENTRYMODESET | _displaymode);
- }
- void LiquidCrystal_I2C::autoscroll(void) {
- _displaymode |= LCD_ENTRYSHIFTINCREMENT;
- command(LCD_ENTRYMODESET | _displaymode);
- }
- void LiquidCrystal_I2C::noAutoscroll(void) {
- _displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
- command(LCD_ENTRYMODESET | _displaymode);
- }
- void LiquidCrystal_I2C::createChar(uint8_t location, uint8_t charmap[]) {
- location &= 0x7;
- command(LCD_SETCGRAMADDR | (location << 3));
- for (int i=0; i<8; i++) {
- write(charmap[i]);
- }
- }
- void LiquidCrystal_I2C::noBacklight(void) {
- _backlightval=LCD_NOBACKLIGHT;
- expanderWrite(0);
- }
- void LiquidCrystal_I2C::backlight(void) {
- _backlightval=LCD_BACKLIGHT;
- expanderWrite(0);
- }
- inline void LiquidCrystal_I2C::command(uint8_t value) {
- send(value, 0);
- }
- void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) {
- uint8_t highnib=value&0xf0;
- uint8_t lownib=(value<<4)&0xf0;
- write4bits((highnib)|mode);
- write4bits((lownib)|mode);
- }
- void LiquidCrystal_I2C::write4bits(uint8_t value) {
- expanderWrite(value);
- pulseEnable(value);
- }
- void LiquidCrystal_I2C::expanderWrite(uint8_t _data){
- Wire.beginTransmission(_Addr);
- printIIC((int)(_data) | _backlightval);
- Wire.endTransmission();
- }
- void LiquidCrystal_I2C::pulseEnable(uint8_t _data){
- expanderWrite(_data | En);
- delayMicroseconds(1);
-
- expanderWrite(_data & ~En);
- delayMicroseconds(50);
- }
- void LiquidCrystal_I2C::cursor_on(){
- cursor();
- }
- void LiquidCrystal_I2C::cursor_off(){
- noCursor();
- }
- void LiquidCrystal_I2C::blink_on(){
- blink();
- }
- void LiquidCrystal_I2C::blink_off(){
- noBlink();
- }
- void LiquidCrystal_I2C::load_custom_character(uint8_t char_num, uint8_t *rows){
- createChar(char_num, rows);
- }
- void LiquidCrystal_I2C::setBacklight(uint8_t new_val){
- if(new_val){
- backlight();
- }else{
- noBacklight();
- }
- }
- void LiquidCrystal_I2C::printstr(const char c[]){
-
-
- print(c);
- }
- void LiquidCrystal_I2C::off(){}
- void LiquidCrystal_I2C::on(){}
- void LiquidCrystal_I2C::setDelay (int cmdDelay,int charDelay) {}
- uint8_t LiquidCrystal_I2C::status(){return 0;}
- uint8_t LiquidCrystal_I2C::keypad (){return 0;}
- uint8_t LiquidCrystal_I2C::init_bargraph(uint8_t graphtype){return 0;}
- void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end){}
- void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_row_end){}
- void LiquidCrystal_I2C::setContrast(uint8_t new_val){}
-
|