Matthew Waddilove / Mbed 2 deprecated SerialLCD

Dependencies:   mbed

Dependents:   dev_board_test

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SerialLCD.h Source File

SerialLCD.h

00001 #pragma once
00002 
00003 //! class that implements an interface like TextLCD, for a serial LCD :)
00004 class SerialLCD : public Serial
00005 {
00006 public:
00007     //! Constructor
00008     SerialLCD(PinName tx, PinName rx)
00009         : Serial(tx, rx) 
00010     {
00011         baud(9600);
00012     }
00013     
00014     //! Enum with command codes.
00015     struct Codes
00016     {
00017         enum Enum
00018         {
00019             BackLight   = 0x7C,
00020             Command     = 0xFE,
00021             Clear       = 0x01,
00022             DisplayOn   = 0x0C,
00023             DisplayOff  = 0x08,
00024             UnderlineCursorOn  = 0x0E,
00025             UnderlineCursorOff = 0x0C,
00026             BlinkingCursorOn   = 0x0D,
00027             BlinkingCursorOff  = 0x0C,
00028             CursorLeft  = 0x10,
00029             CursorRight = 0x14,
00030             ScrollLeft  = 0x18,
00031             ScrollRight = 0x1C,
00032             
00033             Position    = 0x80,
00034             
00035         };
00036     };
00037 
00038     /** Locate to a screen column and row
00039     *
00040     * @param column  The horizontal position from the left, indexed from 0
00041     * @param row     The vertical position from the top, indexed from 0
00042     */
00043     void locate(int column, int row)
00044     {
00045         unsigned char const code = Codes::Position | ((row & 0x1) << 6) | (column % 0x3F);
00046         
00047         send_command(code);
00048     }
00049  
00050     /** Clear the screen and locate to 0,0 */
00051     void cls()
00052     {
00053         send_command(Codes::Clear);
00054         
00055         locate(0,0);
00056     }
00057     
00058     //!Send a command
00059     void send_command(int const command_code)
00060     {
00061         putc(Codes::Command);
00062         putc(command_code);
00063     }
00064 };