mbed Dev board test program
Dependencies: EthernetNetIf mbed HTTPServer SerialLCD
SerialLCD.h@0:0f36b9fac4c5, 2011-07-11 (annotated)
- Committer:
- pangsk
- Date:
- Mon Jul 11 15:02:04 2011 +0000
- Revision:
- 0:0f36b9fac4c5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pangsk | 0:0f36b9fac4c5 | 1 | #pragma once |
pangsk | 0:0f36b9fac4c5 | 2 | |
pangsk | 0:0f36b9fac4c5 | 3 | //! class that implements an interface like TextLCD, for a serial LCD :) |
pangsk | 0:0f36b9fac4c5 | 4 | class SerialLCD : public Serial |
pangsk | 0:0f36b9fac4c5 | 5 | { |
pangsk | 0:0f36b9fac4c5 | 6 | public: |
pangsk | 0:0f36b9fac4c5 | 7 | //! Constructor |
pangsk | 0:0f36b9fac4c5 | 8 | SerialLCD(PinName tx, PinName rx) |
pangsk | 0:0f36b9fac4c5 | 9 | : Serial(tx, rx) |
pangsk | 0:0f36b9fac4c5 | 10 | { |
pangsk | 0:0f36b9fac4c5 | 11 | baud(9600); |
pangsk | 0:0f36b9fac4c5 | 12 | } |
pangsk | 0:0f36b9fac4c5 | 13 | |
pangsk | 0:0f36b9fac4c5 | 14 | //! Enum with command codes. |
pangsk | 0:0f36b9fac4c5 | 15 | struct Codes |
pangsk | 0:0f36b9fac4c5 | 16 | { |
pangsk | 0:0f36b9fac4c5 | 17 | enum Enum |
pangsk | 0:0f36b9fac4c5 | 18 | { |
pangsk | 0:0f36b9fac4c5 | 19 | BackLight = 0x7C, |
pangsk | 0:0f36b9fac4c5 | 20 | Command = 0xFE, |
pangsk | 0:0f36b9fac4c5 | 21 | Clear = 0x01, |
pangsk | 0:0f36b9fac4c5 | 22 | DisplayOn = 0x0C, |
pangsk | 0:0f36b9fac4c5 | 23 | DisplayOff = 0x08, |
pangsk | 0:0f36b9fac4c5 | 24 | UnderlineCursorOn = 0x0E, |
pangsk | 0:0f36b9fac4c5 | 25 | UnderlineCursorOff = 0x0C, |
pangsk | 0:0f36b9fac4c5 | 26 | BlinkingCursorOn = 0x0D, |
pangsk | 0:0f36b9fac4c5 | 27 | BlinkingCursorOff = 0x0C, |
pangsk | 0:0f36b9fac4c5 | 28 | CursorLeft = 0x10, |
pangsk | 0:0f36b9fac4c5 | 29 | CursorRight = 0x14, |
pangsk | 0:0f36b9fac4c5 | 30 | ScrollLeft = 0x18, |
pangsk | 0:0f36b9fac4c5 | 31 | ScrollRight = 0x1C, |
pangsk | 0:0f36b9fac4c5 | 32 | |
pangsk | 0:0f36b9fac4c5 | 33 | Position = 0x80, |
pangsk | 0:0f36b9fac4c5 | 34 | |
pangsk | 0:0f36b9fac4c5 | 35 | }; |
pangsk | 0:0f36b9fac4c5 | 36 | }; |
pangsk | 0:0f36b9fac4c5 | 37 | |
pangsk | 0:0f36b9fac4c5 | 38 | /** Locate to a screen column and row |
pangsk | 0:0f36b9fac4c5 | 39 | * |
pangsk | 0:0f36b9fac4c5 | 40 | * @param column The horizontal position from the left, indexed from 0 |
pangsk | 0:0f36b9fac4c5 | 41 | * @param row The vertical position from the top, indexed from 0 |
pangsk | 0:0f36b9fac4c5 | 42 | */ |
pangsk | 0:0f36b9fac4c5 | 43 | void locate(int column, int row) |
pangsk | 0:0f36b9fac4c5 | 44 | { |
pangsk | 0:0f36b9fac4c5 | 45 | unsigned char const code = Codes::Position | ((row & 0x1) << 6) | (column % 0x3F); |
pangsk | 0:0f36b9fac4c5 | 46 | |
pangsk | 0:0f36b9fac4c5 | 47 | send_command(code); |
pangsk | 0:0f36b9fac4c5 | 48 | } |
pangsk | 0:0f36b9fac4c5 | 49 | |
pangsk | 0:0f36b9fac4c5 | 50 | /** Clear the screen and locate to 0,0 */ |
pangsk | 0:0f36b9fac4c5 | 51 | void cls() |
pangsk | 0:0f36b9fac4c5 | 52 | { |
pangsk | 0:0f36b9fac4c5 | 53 | send_command(Codes::Clear); |
pangsk | 0:0f36b9fac4c5 | 54 | |
pangsk | 0:0f36b9fac4c5 | 55 | locate(0,0); |
pangsk | 0:0f36b9fac4c5 | 56 | } |
pangsk | 0:0f36b9fac4c5 | 57 | |
pangsk | 0:0f36b9fac4c5 | 58 | //!Send a command |
pangsk | 0:0f36b9fac4c5 | 59 | void send_command(int const command_code) |
pangsk | 0:0f36b9fac4c5 | 60 | { |
pangsk | 0:0f36b9fac4c5 | 61 | putc(Codes::Command); |
pangsk | 0:0f36b9fac4c5 | 62 | putc(command_code); |
pangsk | 0:0f36b9fac4c5 | 63 | } |
pangsk | 0:0f36b9fac4c5 | 64 | }; |