Oliver Broad / Mbed 2 deprecated LCD_nonblocking_demo

Dependencies:   mbed

Fork of LCD_nonblocking_demo by Oliver Broad

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LCD_nonblocking.h Source File

LCD_nonblocking.h

00001 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
00002  * Copyright (c) 2013, oliverb, http://mbed.org
00003  * Copyright (c) 2007-2010, sford, http://mbed.org
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  */
00023 
00024 #ifndef MBED_LCDNB_H
00025 #define MBED_LCDNB_H
00026 
00027 #include "mbed.h"
00028 
00029 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
00030  *
00031  * Currently supports 16x2, 20x2 and 20x4 panels
00032  *
00033  * Implements a "Busy" flag to indicate when display is unavailable
00034  * Busy is currently set by a timer and not by polling actual module
00035  * 
00036  * 
00037  * @code
00038  * #include "mbed.h"
00039  * #include "TextLCD.h"
00040  *
00041  * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7
00042  *
00043  * int main() {
00044  *     lcd.printf("Hello World!\n");
00045  * }
00046  * @endcode
00047  */
00048 class TextLCD : public Stream
00049 {
00050 public:
00051 
00052     /** LCD panel format */
00053     enum LCDType {
00054         LCD16x2     /**< 16x2 LCD panel (default) */
00055         , LCD16x2B  /**< 16x2 LCD panel alternate addressing */
00056         , LCD20x2   /**< 20x2 LCD panel */
00057         , LCD20x4   /**< 20x4 LCD panel */
00058     };
00059 
00060     /** Create a TextLCD interface
00061      *
00062      * @param rs    Instruction/data control line
00063      * @param e     Enable line (clock)
00064      * @param d4-d7 Data lines for using as a 4-bit interface
00065      * @param type  Sets the panel size/addressing mode (default = LCD16x2)
00066      */
00067     TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
00068 
00069     void init();
00070 
00071 
00072 #if DOXYGEN_ONLY
00073     /** Write a character to the LCD
00074      *
00075      * @param c The character to write to the display
00076      */
00077     int putc(int c);
00078 
00079     /** Write a formated string to the LCD
00080      *
00081      * @param format A printf-style format string, followed by the
00082      *               variables to use in formating the string.
00083      */
00084     volatile   int printf(const char* format, ...);
00085 #endif
00086 
00087     /** Locate to a screen column and row
00088      *
00089      * @param column  The horizontal position from the left, indexed from 0
00090      * @param row     The vertical position from the top, indexed from 0
00091      */
00092     void locate(int column, int row);
00093 
00094     /** Clear the screen and locate to 0,0 */
00095     void cls();
00096 
00097     int rows();
00098     int columns();
00099     /// Status of display, wait for zero before writing
00100     volatile int busy;
00101 
00102 protected:
00103     Timeout timer;
00104 
00105 // callbacks used by "init" to carry out steps of initialisation
00106     void init2();
00107     void init2b();
00108 
00109     void init3();
00110     void init4();
00111     void init5();
00112     void init6();
00113     void init7();
00114     void init8();
00115 //    void init9();
00116     // Stream implementation functions
00117     virtual int _putc(int value);
00118     virtual int _getc();
00119 
00120     int address(int column, int row);
00121 //    void character(int column, int row, int c);
00122     void writeByte(int value);
00123     void writeCommand(int command);
00124     void writeData(int data);
00125     void callback();
00126     void locate_cb();
00127 
00128     DigitalOut _rs, _e;
00129     BusOut _d;
00130     LCDType _type;
00131 
00132     int _column;
00133     int _row;
00134     char _queue[40];
00135     volatile int _head;
00136     volatile int _tail;
00137 //   int _loop;
00138 };
00139 
00140 #endif