Set of routines to access 16*32character LCD display on WattBob I board.
Dependents: Assignment_2_herpe Final_V1 ass2 ass2 ... more
WattBob_TextLCD.h@8:5a1c4254e4a6, 2011-12-08 (annotated)
- Committer:
- jimherd
- Date:
- Thu Dec 08 16:22:17 2011 +0000
- Revision:
- 8:5a1c4254e4a6
- Parent:
- 7:020722c18a8b
- Child:
- 9:3b26cd028e85
Update to deal the 2*16 OLED display
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jimherd | 0:e5b7c70254ac | 1 | /* draft mbed TextLCD |
jimherd | 0:e5b7c70254ac | 2 | * (c) 2007/8, sford |
jimherd | 0:e5b7c70254ac | 3 | */ |
jimherd | 0:e5b7c70254ac | 4 | |
jimherd | 0:e5b7c70254ac | 5 | #ifndef WATTBOB_TEXTLCD_H |
jimherd | 0:e5b7c70254ac | 6 | #define WATTBOB_TEXTLCD_H |
jimherd | 0:e5b7c70254ac | 7 | |
jimherd | 0:e5b7c70254ac | 8 | #include "mbed.h" |
jimherd | 0:e5b7c70254ac | 9 | #include "Stream.h" |
jimherd | 0:e5b7c70254ac | 10 | #include "MCP23017.h" |
jimherd | 0:e5b7c70254ac | 11 | |
jimherd | 0:e5b7c70254ac | 12 | #define RS_BIT 7 |
jimherd | 0:e5b7c70254ac | 13 | #define RW_BIT 6 |
jimherd | 0:e5b7c70254ac | 14 | #define E_BIT 5 |
jimherd | 0:e5b7c70254ac | 15 | #define BL_BIT 4 |
jimherd | 0:e5b7c70254ac | 16 | |
jimherd | 8:5a1c4254e4a6 | 17 | // |
jimherd | 8:5a1c4254e4a6 | 18 | // Registers and bit definitions for 2*16 character display chip |
jimherd | 8:5a1c4254e4a6 | 19 | // |
jimherd | 8:5a1c4254e4a6 | 20 | #define CMD_CLEAR_DISPLAY 0x01 |
jimherd | 8:5a1c4254e4a6 | 21 | |
jimherd | 8:5a1c4254e4a6 | 22 | #define CMD_RETURN_HOME 0x02 |
jimherd | 8:5a1c4254e4a6 | 23 | |
jimherd | 8:5a1c4254e4a6 | 24 | #define CMD_ENTRY_MODE 0x04 |
jimherd | 8:5a1c4254e4a6 | 25 | #define CURSOR_STEP_LEFT 0x00 |
jimherd | 8:5a1c4254e4a6 | 26 | #define CURSOR_STEP_RIGHT 0x02 |
jimherd | 8:5a1c4254e4a6 | 27 | #define DISPLAY_SHIFT_OFF 0x00 |
jimherd | 8:5a1c4254e4a6 | 28 | #define DISPLAY_SHIFT_ON 0x01 |
jimherd | 8:5a1c4254e4a6 | 29 | |
jimherd | 8:5a1c4254e4a6 | 30 | #define CMD_DISPLAY_CONTROL 0x08 |
jimherd | 8:5a1c4254e4a6 | 31 | #define DISPLAY_OFF 0x00 |
jimherd | 8:5a1c4254e4a6 | 32 | #define DISPLAY_ON 0x04 |
jimherd | 8:5a1c4254e4a6 | 33 | #define CURSOR_OFF 0x00 |
jimherd | 8:5a1c4254e4a6 | 34 | #define CURSOR_ON 0x02 |
jimherd | 8:5a1c4254e4a6 | 35 | #define CURSOR_CHAR_BLINK_OFF 0x00 |
jimherd | 8:5a1c4254e4a6 | 36 | #define CURSOR_CHAR_BLINK_ON 0x01 |
jimherd | 8:5a1c4254e4a6 | 37 | |
jimherd | 8:5a1c4254e4a6 | 38 | #define CMD_CURSOR_SHIFT 0x10 |
jimherd | 8:5a1c4254e4a6 | 39 | #define SHIFT_CURSOR_LEFT 0x00 |
jimherd | 8:5a1c4254e4a6 | 40 | #define SHIFT_CURSOR_RIGHT 0x04 |
jimherd | 8:5a1c4254e4a6 | 41 | #define SHIFT_DISPLAY_LEFT 0x08 |
jimherd | 8:5a1c4254e4a6 | 42 | #define SHIFT_DISPLAY_RIGHT 0x0C |
jimherd | 8:5a1c4254e4a6 | 43 | |
jimherd | 8:5a1c4254e4a6 | 44 | #define CMD_MODE_POWER 0x13 |
jimherd | 8:5a1c4254e4a6 | 45 | #define CHARACTER_MODE 0x00 |
jimherd | 8:5a1c4254e4a6 | 46 | #define GRAPHICS_MODE 0x08 |
jimherd | 8:5a1c4254e4a6 | 47 | #define INTERNAL_POWER_OFF 0x00 |
jimherd | 8:5a1c4254e4a6 | 48 | #define INTERNAL_POWER_ON 0x04 |
jimherd | 8:5a1c4254e4a6 | 49 | |
jimherd | 8:5a1c4254e4a6 | 50 | #define CMD_FUNCTION_SET 0x20 |
jimherd | 8:5a1c4254e4a6 | 51 | #define ENGL_JAPAN_FONT_SET 0x00 |
jimherd | 8:5a1c4254e4a6 | 52 | #define EUROPE_FONT_SET 0x01 |
jimherd | 8:5a1c4254e4a6 | 53 | #define ENGL_RUSSIAN_FONT_SET 0x20 |
jimherd | 8:5a1c4254e4a6 | 54 | #define FONT_5x8 0x00 |
jimherd | 8:5a1c4254e4a6 | 55 | #define FONT_5x10 0x04 |
jimherd | 8:5a1c4254e4a6 | 56 | #define ONE_LINE_DISPLAY 0x00 |
jimherd | 8:5a1c4254e4a6 | 57 | #define TWO_LINE_DISPLAY 0x08 |
jimherd | 8:5a1c4254e4a6 | 58 | #define INTERFACE_4_BIT 0x00 |
jimherd | 8:5a1c4254e4a6 | 59 | #define INTERFACE_8_BIT 0x10 |
jimherd | 8:5a1c4254e4a6 | 60 | |
jimherd | 8:5a1c4254e4a6 | 61 | #define CMD_SET_CGRAM_ADDRESS 0x40 |
jimherd | 8:5a1c4254e4a6 | 62 | |
jimherd | 8:5a1c4254e4a6 | 63 | #define CMD_SET_DDRAM_ADDRESS 0x80 |
jimherd | 8:5a1c4254e4a6 | 64 | // |
jimherd | 8:5a1c4254e4a6 | 65 | // nibble commands |
jimherd | 8:5a1c4254e4a6 | 66 | // |
jimherd | 8:5a1c4254e4a6 | 67 | #define CMD4_SET_4_BIT_INTERFACE 0x2 |
jimherd | 8:5a1c4254e4a6 | 68 | #define CMD4_SET_8_BIT_INTERFACE 0x3 |
jimherd | 8:5a1c4254e4a6 | 69 | // |
jimherd | 8:5a1c4254e4a6 | 70 | // Misc 2*16 character display constants |
jimherd | 8:5a1c4254e4a6 | 71 | // |
jimherd | 8:5a1c4254e4a6 | 72 | #define DISPLAY_INIT_DELAY_SECS 0.025f // 25mS |
jimherd | 8:5a1c4254e4a6 | 73 | |
jimherd | 1:190b705fb9e1 | 74 | /** Class to access 16*2 LCD display connected to an MCP23017 I/O extender chip |
jimherd | 1:190b705fb9e1 | 75 | * |
jimherd | 1:190b705fb9e1 | 76 | * Derived from the "stream" class to be able to use methods such as "printf" |
jimherd | 1:190b705fb9e1 | 77 | * |
jimherd | 1:190b705fb9e1 | 78 | * Example : |
jimherd | 1:190b705fb9e1 | 79 | * @code |
jimherd | 4:f06e69c4c7f3 | 80 | * ..... |
jimherd | 7:020722c18a8b | 81 | * #include "MCP23017.h" |
jimherd | 4:f06e69c4c7f3 | 82 | * #include "WattBob_TextLCD.h" |
jimherd | 4:f06e69c4c7f3 | 83 | * ..... |
jimherd | 1:190b705fb9e1 | 84 | * MCP23017 *par_port; |
jimherd | 1:190b705fb9e1 | 85 | * WattBob_TextLCD *lcd; |
jimherd | 1:190b705fb9e1 | 86 | * ..... |
jimherd | 3:9c142edbfae8 | 87 | * int main() |
jimherd | 7:020722c18a8b | 88 | * par_port = new MCP23017(p9, p10, 0x40); |
jimherd | 7:020722c18a8b | 89 | * par_port->config(0x0F00, 0x0F00, 0x0F00); // configure MCP23017 chip on WattBob |
jimherd | 3:9c142edbfae8 | 90 | * lcd = new WattBob_TextLCD(par_port); |
jimherd | 3:9c142edbfae8 | 91 | * |
jimherd | 1:190b705fb9e1 | 92 | * par_port->write_bit(1,BL_BIT); // turn LCD backlight ON |
jimherd | 1:190b705fb9e1 | 93 | * lcd->cls(); lcd->locate(0,0); |
jimherd | 1:190b705fb9e1 | 94 | * lcd->printf("%s", message); |
jimherd | 1:190b705fb9e1 | 95 | * lcd->locate(1,0);lcd->printf("press 1 to cont"); |
jimherd | 1:190b705fb9e1 | 96 | * @endcode |
jimherd | 1:190b705fb9e1 | 97 | */ |
jimherd | 0:e5b7c70254ac | 98 | class WattBob_TextLCD : public Stream { |
jimherd | 0:e5b7c70254ac | 99 | |
jimherd | 0:e5b7c70254ac | 100 | public: |
jimherd | 1:190b705fb9e1 | 101 | /** Create TextLCD object connected to a MCP23017 device |
jimherd | 1:190b705fb9e1 | 102 | * |
jimherd | 1:190b705fb9e1 | 103 | * @param port pointer to MCP23017 object |
jimherd | 1:190b705fb9e1 | 104 | */ |
jimherd | 1:190b705fb9e1 | 105 | WattBob_TextLCD(MCP23017 *port); |
jimherd | 1:190b705fb9e1 | 106 | |
jimherd | 1:190b705fb9e1 | 107 | /** Set cursor to a known point |
jimherd | 1:190b705fb9e1 | 108 | * |
jimherd | 1:190b705fb9e1 | 109 | * Virtual function for stream class |
jimherd | 1:190b705fb9e1 | 110 | * |
jimherd | 1:190b705fb9e1 | 111 | * @param row integer row number (0 or 1) |
jimherd | 1:190b705fb9e1 | 112 | * @param col integer column number (0 or 15) |
jimherd | 1:190b705fb9e1 | 113 | */ |
jimherd | 0:e5b7c70254ac | 114 | virtual void locate(int row, int column); |
jimherd | 1:190b705fb9e1 | 115 | |
jimherd | 1:190b705fb9e1 | 116 | /** clear display |
jimherd | 1:190b705fb9e1 | 117 | * |
jimherd | 1:190b705fb9e1 | 118 | * Virtual function for stream class |
jimherd | 1:190b705fb9e1 | 119 | */ |
jimherd | 1:190b705fb9e1 | 120 | virtual void cls(); |
jimherd | 1:190b705fb9e1 | 121 | |
jimherd | 1:190b705fb9e1 | 122 | /** reset the display |
jimherd | 1:190b705fb9e1 | 123 | * |
jimherd | 1:190b705fb9e1 | 124 | * Virtual function for stream class |
jimherd | 1:190b705fb9e1 | 125 | */ |
jimherd | 0:e5b7c70254ac | 126 | virtual void reset(); |
jimherd | 0:e5b7c70254ac | 127 | |
jimherd | 0:e5b7c70254ac | 128 | protected: |
jimherd | 0:e5b7c70254ac | 129 | |
jimherd | 1:190b705fb9e1 | 130 | virtual int _putc(int c); |
jimherd | 1:190b705fb9e1 | 131 | virtual int _getc(); |
jimherd | 1:190b705fb9e1 | 132 | virtual void newline(); |
jimherd | 1:190b705fb9e1 | 133 | |
jimherd | 0:e5b7c70254ac | 134 | void clock(); |
jimherd | 0:e5b7c70254ac | 135 | void writeData(int data); |
jimherd | 0:e5b7c70254ac | 136 | void writeCommand(int command); |
jimherd | 0:e5b7c70254ac | 137 | void writeByte(int value); |
jimherd | 0:e5b7c70254ac | 138 | void writeNibble(int value); |
jimherd | 0:e5b7c70254ac | 139 | |
jimherd | 0:e5b7c70254ac | 140 | void _rs (int data); |
jimherd | 0:e5b7c70254ac | 141 | void _rw (int data); |
jimherd | 0:e5b7c70254ac | 142 | void _e (int data); |
jimherd | 0:e5b7c70254ac | 143 | void _d (int data); |
jimherd | 1:190b705fb9e1 | 144 | |
jimherd | 0:e5b7c70254ac | 145 | int _rows; |
jimherd | 0:e5b7c70254ac | 146 | int _columns; |
jimherd | 0:e5b7c70254ac | 147 | int _row; |
jimherd | 0:e5b7c70254ac | 148 | int _column; |
jimherd | 0:e5b7c70254ac | 149 | |
jimherd | 0:e5b7c70254ac | 150 | private: |
jimherd | 0:e5b7c70254ac | 151 | MCP23017 *par_port; |
jimherd | 0:e5b7c70254ac | 152 | }; |
jimherd | 0:e5b7c70254ac | 153 | |
jimherd | 0:e5b7c70254ac | 154 | #endif |