root/twiLCD/twiLCD.h

Revision 9, 5.5 KB (checked in by mlalondesvn, 15 months ago)

DS1337:

FIXED - All callback functions now work properly
FIXED - Oscillator startup so that it resets the status register
FIXED - All alarm mode bitmasks
MODIF - clockStart() from macro to function
MODIF - clockSave() to reset the clock so that the status flags are reset

twiLCD:

MODIF - setClrscreenCallback() renamed clrsSetCallback()

Line 
1#ifndef twiLCD_H
2#define twiLCD_H
3    #include "../global.h"
4   
5    #include "../configs/LCD/lcd.h"
6    #include "../configs/twiLCD/twiLCD.h"
7   
8#ifndef PCF8574_A0
9    #define PCF8574_A0          0
10#endif
11#ifndef PCF8574_A1
12    #define PCF8574_A1          0
13#endif
14#ifndef PCF8574_A2
15    #define PCF8574_A2          0
16#endif
17   
18    #define PCF8574_BASE_ADDR   B00100000
19    #define PCF8574_WADDR       PCF8574_BASE_ADDR | (PCF8574_A0 * B00000001) | (PCF8574_A1 * B00000010) | (PCF8574_A2 * B00000100)
20    #define PCF8574_RADDR       PCF8574_WADDR | 0x01
21   
22    #define TWI_LCD_RS          0   /* RS pin */
23    #define TWI_LCD_RW          1   /* RW pin */
24    #define TWI_LCD_ENABLE      2   /* Enable pin */
25#ifdef TWI_LCD_CTRL
26#ifdef TWI_LCD_BL_PWM
27    #define TWI_LCD_BACKLIGHT   9   /* This is an Arduino pin number! */
28#else
29    #define TWI_LCD_BACKLIGHT   3   /* Backlight pin */
30#endif
31#endif
32   
33    #define TWI_LCD_CONTROL     B00000111   /* Mask for the 3 control bits (E, RS, RW) */
34    #define TWI_LCD_DATA        B11110000   /* Mask for the 4 bit word */
35    #define TWI_LCD_DATAH       B11110000
36    #define TWI_LCD_DATAL       B00001111
37    #define TWI_LCD_BUSY        B00001000
38   
39#ifndef printString
40    #define printString(str)    printString_P(PSTR(str))
41#endif
42   
43#ifdef LCD_USE_CLRSCREEN_CALLBACK
44    volatile static voidFuncPtr twiLCDcallbackFunc[1];
45#endif
46   
47    class twiLCD {
48        public:
49            /**
50             * Constructor: initializes this class
51            **/
52            twiLCD();
53           
54            /**
55             * LCD Initilization method
56            **/
57            void    Init();
58           
59            /**
60             * writeData: write a byte of data to the LCD
61             * @param: value: the byte to write
62            **/
63            void    writeData(uint8_t);
64           
65            /**
66             * clearScreen: clears the LCD and resets the cursor position to 0,0
67            **/
68            void    clearScreen(void);
69           
70            /**
71             * printString_P: prints a program string to the LCD
72             *  To call this function, use the LCD.printString() macro!
73            **/
74            void    printString_P(const char *);
75           
76        #ifdef LCD_USE_CLRSCREEN_CALLBACK
77            void    clrsSetCallback(void (*)(void));
78        #endif
79    /**
80     * These function are only available on the mega168 for space reasons
81    **/
82    #if defined(__AVR_ATmega168__) && !defined(TWI_LCD_SMALL)
83       
84        /**
85         * Methods for dealing with LCD timeout
86         * Returns true if the time is expired
87        **/
88        #ifdef TWI_LCD_USE_TIMEOUT
89            boolean checkTimeout(void);
90        #endif
91       
92        /**
93         * Backlight control functions
94         * Optionally enabled above
95        **/
96        #ifdef TWI_LCD_CTRL
97            /**
98             * backlightOn: Turn on the backlight at full brightness
99            **/
100            void    backlightOn(void);
101           
102            /**
103             * backlightOff: turn off the LCD backlight
104            **/
105            void    backlightOff(void);
106           
107            // PWM Backlight Control
108            #if defined(TWI_LCD_BL_PWM) || defined(TWI_LCD_DPOT_CTRL)
109                /**
110                 * backlightOn: turns on the backlight with a specific brightness
111                **/
112                void backlightOn(uint8_t);
113            #endif
114           
115            #ifdef TWI_LCD_DPOT_CTRL
116                /**
117                 * setBrightness: sets the brightness level using a digital pot
118                 * If no param is passed TWI_LCD_DB_LEVEL is used
119                **/
120                void setBrightness(void);
121                void setBrightness(uint8_t);
122            #endif
123        #endif
124       
125            /**
126             * setCursor: set cursor a position "index"
127            **/
128            void setCursor(int);
129           
130            /**
131             * moveToXY: moves the cursor to position (row,column)
132            **/
133            void moveToXY(uint8_t, uint8_t);
134           
135            /**
136             * Turn off the LCD (will turn off the backlight if control is enabled)
137            **/
138            void turnOff(void);
139           
140            /**
141             * goToLine: Allows to move at the beginning of a specific line
142            **/
143            void goToLine(uint8_t);
144           
145            /**
146             * goToNextLine: goes to the next line, wraps arround at the end
147            **/
148            void goToNextLine(void);
149           
150            /**
151             * goHome: goes to position (0,0)
152            **/
153            void goHome(void);
154           
155            /**
156             * clearLine: clears the current line
157            **/
158            void clearLine(void);
159           
160            /**
161             * shiftDisplayLeft: shift all lines of the display one position to the left
162            **/
163            void shiftDisplayLeft(void);
164           
165            /**
166             * shiftDisplayRight: shift all lines of the display one position to the right
167            **/
168            void shiftDisplayRight(void);
169           
170            /**
171             * getCurrentLine: returns the current line
172            **/
173            uint8_t getCurrentLine(void);
174           
175            /**
176             * getCurrentStatus: returns whether the display is on or off
177            **/
178            bool getCurrentStatus(void);
179           
180            /**
181             * printInteger: writes an interger as text on the lcd
182             * The second version is only good for intergers < 99 and will add a leading zero
183            **/
184            void printInteger(int16_t);
185            void printInteger(uint16_t integer, bool leadingZero);
186    #endif
187        private:
188    #if defined(__AVR_ATmega168__) && !defined(TWI_LCD_SMALL)
189        #ifdef TWI_LCD_USE_TIMEOUT
190            unsigned long   previousMillis;
191        #endif
192       
193        #if defined(TWI_LCD_CTRL) && !defined(TWI_LCD_BL_PWM)
194            /**
195             * backlightStatus: used to keep track of the backlight status
196            **/
197            uint8_t     backlightStatus;
198        #endif
199           
200            /**
201             * currentLine: keeps track of the current line
202            **/
203            uint8_t     currentLine;
204           
205            /**
206             * displayStatus: keeps track of whether the display is on or off
207            **/
208            bool        displayStatus;
209    #endif
210            /**
211             * sendPulse: sends a byte of data with the appropiate Enable pulse
212            **/
213            void        sendPulse(int);
214           
215            /**
216             * writeToPCF: writes a new byte of data using twi
217             *  This function is used to preserve some data through writes
218             *  such as when bit3 of the expander is used to control the backlight
219            **/
220            void        writeToPCF(int);
221           
222            /**
223             * writeCommand: Writes an LCD command
224             * @param: value: the value to write
225            **/
226            void        writeCommand(uint8_t value);
227           
228            /**
229             * checkLCDBusy: reads the busy state bit from the LCD
230            **/
231            boolean     checkLCDBusy(void);
232    };
233
234    /**
235     * Define the object's name
236    **/
237    extern twiLCD LCD;
238
239#endif
Note: See TracBrowser for help on using the browser.