Shinichiro Nakamura / TextLCD_SR4

Dependents:   TextLCD_SR4_TestProgram ServoInterfaceBoardExample1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TextLCD_SR4.h Source File

TextLCD_SR4.h

00001 
00002 #ifndef _TEXT_LCD_SR4_H
00003 #define _TEXT_LCD_SR4_H
00004 
00005 #include "mbed.h"
00006 
00007 /*
00008  * Modified for http://mbed.org/users/shintamainjp/notebook/textlcd_sr4_en/
00009  * Shinichiro Nakamura
00010  */
00011 
00012 /**
00013  * A TextLCD_SR4 interface for driving 4-bit HD44780-based LCDs with shift register.
00014  *
00015  * Currently supports 16x2, 20x2 and 20x4 panels
00016  *
00017  * @code
00018  * #include "mbed.h"
00019  * #include "TextLCD_SR4.h"
00020  *
00021  * TextLCD_SR4 lcd(p29, p30, p28, p27); // rs, e, dat, clk
00022  *
00023  * int main() {
00024  *     lcd.printf("Hello World!\n");
00025  * }
00026  * @endcode
00027  */
00028 class TextLCD_SR4 : public Stream {
00029 public:
00030     /** LCD panel format */
00031     enum LCDType {
00032         LCD16x2     /**< 16x2 LCD panel (default) */
00033         , LCD16x2B  /**< 16x2 LCD panel alternate addressing */
00034         , LCD20x2   /**< 20x2 LCD panel */
00035         , LCD20x4   /**< 20x4 LCD panel */
00036     };
00037     
00038     /** Create a TextLCD_SR4 interface
00039      *
00040      * @param rs    Instruction/data control line
00041      * @param e     Enable line (clock)
00042      * @param dat   Data line
00043      * @param clk   Clock line
00044      */
00045     TextLCD_SR4(PinName rs, PinName e, PinName dat, PinName clk, LCDType type = LCD16x2);
00046 
00047 #if DOXYGEN_ONLY
00048     /** Write a character to the LCD
00049      *
00050      * @param c The character to write to the display
00051      */
00052     int putc(int c);
00053 
00054     /** Write a formated string to the LCD
00055      *
00056      * @param format A printf-style format string, followed by the
00057      *               variables to use in formating the string.
00058      */
00059     int printf(const char* format, ...);
00060 #endif
00061 
00062     /** Locate to a screen column and row
00063      *
00064      * @param column  The horizontal position from the left, indexed from 0
00065      * @param row     The vertical position from the top, indexed from 0
00066      */
00067     void locate(int column, int row);
00068 
00069     /** Clear the screen and locate to 0,0 */
00070     void cls();
00071 
00072     int rows();
00073     int columns();
00074 
00075 protected:
00076 
00077     // Stream implementation functions
00078     virtual int _putc(int value);
00079     virtual int _getc();
00080 
00081     int address(int column, int row);
00082     void character(int column, int row, int c);
00083     void writeByte(int value);
00084     void writeCommand(int command);
00085     void writeData(int data);
00086 
00087     void writeToShiftRegister(int value);
00088 
00089     DigitalOut _rs, _e, _dat, _clk;
00090     LCDType _type;
00091 
00092     int _column;
00093     int _row;
00094 };
00095 
00096 #endif