w m / Mbed 2 deprecated DISTANCE_PROJECT1

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WattBob_TextLCD.h Source File

WattBob_TextLCD.h

00001 /* draft mbed TextLCD 
00002  * (c) 2007/8, sford
00003  */
00004  
00005 #ifndef WATTBOB_TEXTLCD_H
00006 #define WATTBOB_TEXTLCD_H
00007 
00008 #include "mbed.h"
00009 #include "Stream.h"
00010 #include "MCP23017.h"
00011 
00012 #define     RS_BIT      7
00013 #define     RW_BIT      6
00014 #define     E_BIT       5
00015 #define     BL_BIT      4   
00016 
00017 //
00018 // Registers and bit definitions for 2*16 character display chip
00019 //
00020 #define     CMD_NULL                0x00
00021 
00022 #define     CMD_CLEAR_DISPLAY       0x01
00023 
00024 #define     CMD_RETURN_HOME         0x02
00025 
00026 #define     CMD_ENTRY_MODE          0x04
00027 #define       CURSOR_STEP_LEFT      0x00
00028 #define       CURSOR_STEP_RIGHT     0x02
00029 #define       DISPLAY_SHIFT_OFF     0x00
00030 #define       DISPLAY_SHIFT_ON      0x01
00031        
00032 #define     CMD_DISPLAY_CONTROL     0x08
00033 #define       DISPLAY_OFF           0x00
00034 #define       DISPLAY_ON            0x04
00035 #define       CURSOR_OFF            0x00
00036 #define       CURSOR_ON             0x02
00037 #define       CURSOR_CHAR_BLINK_OFF 0x00
00038 #define       CURSOR_CHAR_BLINK_ON  0x01
00039 
00040 #define     CMD_CURSOR_SHIFT        0x10
00041 #define       SHIFT_CURSOR_LEFT     0x00
00042 #define       SHIFT_CURSOR_RIGHT    0x04
00043 #define       SHIFT_DISPLAY_LEFT    0x08
00044 #define       SHIFT_DISPLAY_RIGHT   0x0C
00045 
00046 #define     CMD_MODE_POWER          0x13
00047 #define       CHARACTER_MODE        0x00
00048 #define       GRAPHICS_MODE         0x08
00049 #define       INTERNAL_POWER_OFF    0x00
00050 #define       INTERNAL_POWER_ON     0x04
00051 
00052 #define     CMD_FUNCTION_SET        0x20
00053 #define       ENGL_JAPAN_FONT_SET   0x00
00054 #define       EUROPE_FONT_SET       0x01
00055 #define       ENGL_RUSSIAN_FONT_SET 0x20
00056 #define       FONT_5x8              0x00
00057 #define       FONT_5x10             0x04
00058 #define       ONE_LINE_DISPLAY      0x00
00059 #define       TWO_LINE_DISPLAY      0x08
00060 #define       INTERFACE_4_BIT       0x00
00061 #define       INTERFACE_8_BIT       0x10
00062 
00063 #define     CMD_SET_CGRAM_ADDRESS   0x40
00064 
00065 #define     CMD_SET_DDRAM_ADDRESS   0x80
00066 //
00067 // nibble commands
00068 //
00069 #define     CMD4_SET_4_BIT_INTERFACE 0x2
00070 #define     CMD4_SET_8_BIT_INTERFACE 0x3
00071 //
00072 // Misc 2*16 character display constants
00073 //
00074 #define     DISPLAY_INIT_DELAY_SECS    0.5f       // 500mS
00075 #define     DISPLAY_CLEAR_DELAY        0.01f      // 10 mS (spec is 6.2mS)
00076 
00077 /** Class to access 16*2 LCD display connected to an MCP23017 I/O extender chip
00078  *
00079  * Derived from the "stream" class to be able to use methods such as "printf"
00080  *
00081  * Example :
00082  * @code
00083  * .....
00084  * #include "MCP23017.h"
00085  * #include "WattBob_TextLCD.h"
00086  * .....
00087  * MCP23017            *par_port;
00088  * WattBob_TextLCD     *lcd;
00089  *      .....
00090  * int main()
00091  *      par_port = new MCP23017(p9, p10, 0x40);
00092  *      par_port->config(0x0F00, 0x0F00, 0x0F00);           // configure MCP23017 chip on WattBob       
00093  *      lcd = new WattBob_TextLCD(par_port);
00094  *
00095  *      par_port->write_bit(1,BL_BIT);   // turn LCD backlight ON
00096  *      lcd->cls(); lcd->locate(0,0);
00097  *      lcd->printf("%s", message);
00098  *      lcd->locate(1,0);lcd->printf("press 1 to cont"); 
00099  * @endcode
00100  */ 
00101 class WattBob_TextLCD : public Stream {
00102 
00103 public:
00104     /** Create TextLCD object connected to a MCP23017 device
00105      *
00106      * @param   port    pointer to MCP23017 object
00107      */ 
00108     WattBob_TextLCD(MCP23017 *port);
00109     
00110     /** Set cursor to a known point
00111      *
00112      * Virtual function for stream class
00113      *
00114      * @param   row   integer row number (0 or 1)
00115      * @param   col   integer column number (0 or 15)     
00116      */            
00117     virtual void locate(int row, int column);
00118     
00119     /** clear display
00120      *
00121      * Virtual function for stream class
00122      */     
00123     virtual void cls();
00124 
00125     /** reset the display
00126      *
00127      * Virtual function for stream class
00128      */             
00129     virtual void reset();
00130         
00131 protected:
00132 
00133     virtual int _putc(int c);        
00134     virtual int _getc();
00135     virtual void newline();      
00136     
00137     void clock();
00138     void writeData(int data);
00139     void writeCommand(int command);
00140     void writeByte(int value);
00141     void writeNibble(int value);
00142     
00143     void _rs (int data);
00144     void _rw (int data);    
00145     void _e (int data);
00146     void _d (int data);
00147            
00148     int _rows;
00149     int _columns;
00150     int _row;
00151     int _column;   
00152     
00153 private:
00154     MCP23017    *par_port; 
00155 };
00156 
00157 #endif
00158