You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
238 lines
5.5 KiB
238 lines
5.5 KiB
#ifndef twiLCD_H
|
|
#define twiLCD_H
|
|
#include "../global.h"
|
|
|
|
#include "../configs/LCD/lcd.h"
|
|
#include "twiLCDConfig.h"
|
|
|
|
/**
|
|
* Address byte selection
|
|
* Select 0 for low and 1 for high
|
|
**/
|
|
#define PCF8574_A0 0
|
|
#define PCF8574_A1 0
|
|
#define PCF8574_A2 0
|
|
|
|
#define PCF8574_BASE_ADDR B00100000
|
|
#define PCF8574_WADDR PCF8574_BASE_ADDR | (PCF8574_A0 * B00000001) | (PCF8574_A1 * B00000010) | (PCF8574_A2 * B00000100)
|
|
#define PCF8574_RADDR PCF8574_WADDR | 0x01
|
|
|
|
#define TWI_LCD_RS 0 /* RS pin */
|
|
#define TWI_LCD_RW 1 /* RW pin */
|
|
#define TWI_LCD_ENABLE 2 /* Enable pin */
|
|
#ifdef TWI_LCD_CTRL
|
|
#ifdef TWI_LCD_BL_PWM
|
|
#define TWI_LCD_BACKLIGHT 9 /* This is an Arduino pin number! */
|
|
#else
|
|
#define TWI_LCD_BACKLIGHT 3 /* Backlight pin */
|
|
#endif
|
|
#endif
|
|
|
|
#define TWI_LCD_CONTROL B00000111 /* Mask for the 3 control bits (E, RS, RW) */
|
|
#define TWI_LCD_DATA B11110000 /* Mask for the 4 bit word */
|
|
#define TWI_LCD_DATAH B11110000
|
|
#define TWI_LCD_DATAL B00001111
|
|
#define TWI_LCD_BUSY B00001000
|
|
|
|
#ifndef printString
|
|
#define printString(str) printString_P(PSTR(str))
|
|
#endif
|
|
|
|
#ifdef LCD_USE_CLRSCREEN_CALLBACK
|
|
volatile static voidFuncPtr twiLCDcallbackFunc[1];
|
|
#endif
|
|
|
|
class twiLCD {
|
|
public:
|
|
/**
|
|
* Constructor: initializes this class
|
|
**/
|
|
twiLCD();
|
|
|
|
/**
|
|
* LCD Initilization method
|
|
**/
|
|
void Init();
|
|
|
|
/**
|
|
* writeData: write a byte of data to the LCD
|
|
* @param: value: the byte to write
|
|
**/
|
|
void writeData(uint8_t);
|
|
|
|
/**
|
|
* clearScreen: clears the LCD and resets the cursor position to 0,0
|
|
**/
|
|
void clearScreen(void);
|
|
|
|
/**
|
|
* printString_P: prints a program string to the LCD
|
|
* To call this function, use the LCD.printString() macro!
|
|
**/
|
|
void printString_P(const char *);
|
|
|
|
#ifdef LCD_USE_CLRSCREEN_CALLBACK
|
|
void setClrscreenCallback(void (*)(void));
|
|
#endif
|
|
/**
|
|
* These function are only available on the mega168 for space reasons
|
|
**/
|
|
#if defined(__AVR_ATmega168__) && !defined(TWI_LCD_SMALL)
|
|
|
|
/**
|
|
* Methods for dealing with LCD timeout
|
|
* Returns true if the time is expired
|
|
**/
|
|
#ifdef TWI_LCD_USE_TIMEOUT
|
|
boolean checkTimeout(void);
|
|
#endif
|
|
|
|
/**
|
|
* Backlight control functions
|
|
* Optionally enabled above
|
|
**/
|
|
#ifdef TWI_LCD_CTRL
|
|
/**
|
|
* backlightOn: Turn on the backlight at full brightness
|
|
**/
|
|
void backlightOn(void);
|
|
|
|
/**
|
|
* backlightOff: turn off the LCD backlight
|
|
**/
|
|
void backlightOff(void);
|
|
|
|
// PWM Backlight Control
|
|
#if defined(TWI_LCD_BL_PWM) || defined(TWI_LCD_DPOT_CTRL)
|
|
/**
|
|
* backlightOn: turns on the backlight with a specific brightness
|
|
**/
|
|
void backlightOn(uint8_t);
|
|
#endif
|
|
|
|
#ifdef TWI_LCD_DPOT_CTRL
|
|
/**
|
|
* setBrightness: sets the brightness level using a digital pot
|
|
* If no param is passed TWI_LCD_DB_LEVEL is used
|
|
**/
|
|
void setBrightness(void);
|
|
void setBrightness(uint8_t);
|
|
#endif
|
|
#endif
|
|
|
|
/**
|
|
* setCursor: set cursor a position "index"
|
|
**/
|
|
void setCursor(int);
|
|
|
|
/**
|
|
* moveToXY: moves the cursor to position (row,column)
|
|
**/
|
|
void moveToXY(uint8_t, uint8_t);
|
|
|
|
/**
|
|
* Turn off the LCD (will turn off the backlight if control is enabled)
|
|
**/
|
|
void turnOff(void);
|
|
|
|
/**
|
|
* goToLine: Allows to move at the beginning of a specific line
|
|
**/
|
|
void goToLine(uint8_t);
|
|
|
|
/**
|
|
* goToNextLine: goes to the next line, wraps arround at the end
|
|
**/
|
|
void goToNextLine(void);
|
|
|
|
/**
|
|
* goHome: goes to position (0,0)
|
|
**/
|
|
void goHome(void);
|
|
|
|
/**
|
|
* clearLine: clears the current line
|
|
**/
|
|
void clearLine(void);
|
|
|
|
/**
|
|
* shiftDisplayLeft: shift all lines of the display one position to the left
|
|
**/
|
|
void shiftDisplayLeft(void);
|
|
|
|
/**
|
|
* shiftDisplayRight: shift all lines of the display one position to the right
|
|
**/
|
|
void shiftDisplayRight(void);
|
|
|
|
/**
|
|
* getCurrentLine: returns the current line
|
|
**/
|
|
uint8_t getCurrentLine(void);
|
|
|
|
/**
|
|
* getCurrentStatus: returns whether the display is on or off
|
|
**/
|
|
bool getCurrentStatus(void);
|
|
|
|
/**
|
|
* printInteger: writes an interger as text on the lcd
|
|
* The second version is only good for intergers < 99 and will add a leading zero
|
|
**/
|
|
void printInteger(int16_t);
|
|
void printInteger(uint16_t integer, bool leadingZero);
|
|
#endif
|
|
private:
|
|
#if defined(__AVR_ATmega168__) && !defined(TWI_LCD_SMALL)
|
|
#ifdef TWI_LCD_USE_TIMEOUT
|
|
unsigned long previousMillis;
|
|
#endif
|
|
|
|
#if defined(TWI_LCD_CTRL) && !defined(TWI_LCD_BL_PWM)
|
|
/**
|
|
* backlightStatus: used to keep track of the backlight status
|
|
**/
|
|
uint8_t backlightStatus;
|
|
#endif
|
|
|
|
/**
|
|
* currentLine: keeps track of the current line
|
|
**/
|
|
uint8_t currentLine;
|
|
|
|
/**
|
|
* displayStatus: keeps track of whether the display is on or off
|
|
**/
|
|
bool displayStatus;
|
|
#endif
|
|
/**
|
|
* sendPulse: sends a byte of data with the appropiate Enable pulse
|
|
**/
|
|
void sendPulse(int);
|
|
|
|
/**
|
|
* writeToPCF: writes a new byte of data using twi
|
|
* This function is used to preserve some data through writes
|
|
* such as when bit3 of the expander is used to control the backlight
|
|
**/
|
|
void writeToPCF(int);
|
|
|
|
/**
|
|
* writeCommand: Writes an LCD command
|
|
* @param: value: the value to write
|
|
**/
|
|
void writeCommand(uint8_t value);
|
|
|
|
/**
|
|
* checkLCDBusy: reads the busy state bit from the LCD
|
|
**/
|
|
boolean checkLCDBusy(void);
|
|
};
|
|
|
|
/**
|
|
* Define the object's name
|
|
**/
|
|
extern twiLCD LCD;
|
|
|
|
#endif
|