Fork of Freetronics_16x2_LCD class for HD4478 based LCDs with Cyrillic symbols like WH1602 etc. Use puts() for latin and cyrillic texts, symbols. ( ° included)

Fork of Freetronics_16x2_LCD by Components

Committer:
margadon
Date:
Thu Nov 27 12:00:09 2014 +0000
Revision:
6:9ef0091c2a4f
Child:
7:08abb319acab
Fork freetronics LCD class for HD4478 based LCDs with Cyrillic symbols. Use puts() for latin and Cyrillic texts.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
margadon 6:9ef0091c2a4f 1
margadon 6:9ef0091c2a4f 2 #ifndef freetronicsLCDShieldRus_H
margadon 6:9ef0091c2a4f 3 #define freetronicsLCDShieldRus_H
margadon 6:9ef0091c2a4f 4
margadon 6:9ef0091c2a4f 5 #define LEFT 0
margadon 6:9ef0091c2a4f 6 #define RIGHT 1
margadon 6:9ef0091c2a4f 7
margadon 6:9ef0091c2a4f 8 /**
margadon 6:9ef0091c2a4f 9 * Provides full LCD support for the HD44780 compatible LCD on the arduino shaped shield.
margadon 6:9ef0091c2a4f 10 * http://www.freetronics.com/products/lcd-keypad-shield#.UnIr6_nkq0M
margadon 6:9ef0091c2a4f 11 *
margadon 6:9ef0091c2a4f 12 */
margadon 6:9ef0091c2a4f 13 class freetronicsLCDShieldRus : public Stream {
margadon 6:9ef0091c2a4f 14 private:
margadon 6:9ef0091c2a4f 15 // Functions
margadon 6:9ef0091c2a4f 16 void writeByte (int byte);
margadon 6:9ef0091c2a4f 17 void writeCommand (int command);
margadon 6:9ef0091c2a4f 18 void writeData (int data);
margadon 6:9ef0091c2a4f 19 void character(int line, int col, int value);
margadon 6:9ef0091c2a4f 20
margadon 6:9ef0091c2a4f 21 // Hardware
margadon 6:9ef0091c2a4f 22 DigitalOut _rs, _e;
margadon 6:9ef0091c2a4f 23 BusOut _d;
margadon 6:9ef0091c2a4f 24 PwmOut _bl;
margadon 6:9ef0091c2a4f 25 AnalogIn _a0;
margadon 6:9ef0091c2a4f 26
margadon 6:9ef0091c2a4f 27 public:
margadon 6:9ef0091c2a4f 28 /**
margadon 6:9ef0091c2a4f 29 * The constructor creates an freeTronics LCD Shield object, the pins are to be provided by the user. In sequence, RegisterSelect, Enable, Data0
margadon 6:9ef0091c2a4f 30 * to Data3. Bl is the backlight and a0 is to be provided for button support.
margadon 6:9ef0091c2a4f 31 * Bl should be a pin with PWM capabilities and a0 should be an analogue input.
margadon 6:9ef0091c2a4f 32 *
margadon 6:9ef0091c2a4f 33 * The class inherits from stream, therfore writing to the display is as easy as calling printf() to display text or putc() to display a custom character
margadon 6:9ef0091c2a4f 34 *
margadon 6:9ef0091c2a4f 35 * Example:
margadon 6:9ef0091c2a4f 36 * @code
margadon 6:9ef0091c2a4f 37 * <instanceName>.printf("Hello World");
margadon 6:9ef0091c2a4f 38 * @endcode */
margadon 6:9ef0091c2a4f 39 freetronicsLCDShieldRus (PinName rs /*= PTA13*/,
margadon 6:9ef0091c2a4f 40 PinName e /*= PTD5*/,
margadon 6:9ef0091c2a4f 41 PinName d0 /*= PTA4*/,
margadon 6:9ef0091c2a4f 42 PinName d1 /*= PTA5*/,
margadon 6:9ef0091c2a4f 43 PinName d2 /*= PTC8*/,
margadon 6:9ef0091c2a4f 44 PinName d3 /*= PTC9*/,
margadon 6:9ef0091c2a4f 45 PinName bl /*= PTA12*/,
margadon 6:9ef0091c2a4f 46 PinName a0 /*= PTB0*/);
margadon 6:9ef0091c2a4f 47 /** Creates custom characters
margadon 6:9ef0091c2a4f 48 *
margadon 6:9ef0091c2a4f 49 * Characters that aren't included in the LCD controllers character map which includes typically all ASCII characters
margadon 6:9ef0091c2a4f 50 * can be generated by writing bitmaps to the character generator ram memory space. For instance the degree sign '°' is an
margadon 6:9ef0091c2a4f 51 * extended ASCII character not included in the character map.
margadon 6:9ef0091c2a4f 52 * It can however be generated using the writeCGRAM member function. Each line of the 5x7 dot matrix is represented by a byte in which
margadon 6:9ef0091c2a4f 53 * the lower 5 bits correspond to the pixel on the display. In total 8 bytes make up one custom character (the 8th byte represents the
margadon 6:9ef0091c2a4f 54 * cursor space)
margadon 6:9ef0091c2a4f 55 *
margadon 6:9ef0091c2a4f 56 * Example:
margadon 6:9ef0091c2a4f 57 * @code
margadon 6:9ef0091c2a4f 58 * CGRAM_DATA[] = {0xC0, //0b00001100
margadon 6:9ef0091c2a4f 59 * 0x12, //0b00010010
margadon 6:9ef0091c2a4f 60 * 0x12, //0b00010010
margadon 6:9ef0091c2a4f 61 * 0xC0, //0b00001100
margadon 6:9ef0091c2a4f 62 * 0x00, //0b00000000
margadon 6:9ef0091c2a4f 63 * 0x00, //0b00000000
margadon 6:9ef0091c2a4f 64 * 0x00, //0b00000000
margadon 6:9ef0091c2a4f 65 * 0x00}; //0b00000000
margadon 6:9ef0091c2a4f 66 *
margadon 6:9ef0091c2a4f 67 * <instanceName>.writeCGRAM (0x00, &CGRAM_DATA[0], 8);
margadon 6:9ef0091c2a4f 68 * @endcode
margadon 6:9ef0091c2a4f 69 *
margadon 6:9ef0091c2a4f 70 * The '°' can hereafter be displayed by calling:
margadon 6:9ef0091c2a4f 71 * @code
margadon 6:9ef0091c2a4f 72 * <instanceName>.putc (0);
margadon 6:9ef0091c2a4f 73 * @endcode
margadon 6:9ef0091c2a4f 74 *
margadon 6:9ef0091c2a4f 75 */
margadon 6:9ef0091c2a4f 76 void writeCGRAM (char address, const char *ptr, char nbytes);
margadon 6:9ef0091c2a4f 77
margadon 6:9ef0091c2a4f 78 /** Sets the current cursor position.
margadon 6:9ef0091c2a4f 79 *
margadon 6:9ef0091c2a4f 80 * To place the cursor at a specific location on the display call the setCursorPosition member function, the first argument is the line either 0
margadon 6:9ef0091c2a4f 81 * or 1, the second argument is the column 0 .. 15.
margadon 6:9ef0091c2a4f 82 *
margadon 6:9ef0091c2a4f 83 */
margadon 6:9ef0091c2a4f 84 void setCursorPosition (int line, int col);
margadon 6:9ef0091c2a4f 85
margadon 6:9ef0091c2a4f 86 /** Sets the backlight.
margadon 6:9ef0091c2a4f 87 *
margadon 6:9ef0091c2a4f 88 * The backlight is turned on (argument true) or off (false)
margadon 6:9ef0091c2a4f 89 */
margadon 6:9ef0091c2a4f 90 void setBackLight (bool blStatus);
margadon 6:9ef0091c2a4f 91
margadon 6:9ef0091c2a4f 92 /** Sets the backlight.
margadon 6:9ef0091c2a4f 93 *
margadon 6:9ef0091c2a4f 94 * The backlight intensity is specified by the normalized float argument 0 .. 1
margadon 6:9ef0091c2a4f 95 */
margadon 6:9ef0091c2a4f 96 void setBackLight (float blIntensity);
margadon 6:9ef0091c2a4f 97
margadon 6:9ef0091c2a4f 98 /** Sets cursor appearance.
margadon 6:9ef0091c2a4f 99 *
margadon 6:9ef0091c2a4f 100 * The cursor is set visible (1st argument true) or invisible (false). When the second argument is set when the cStatus is set the cursor blinks.
margadon 6:9ef0091c2a4f 101 */
margadon 6:9ef0091c2a4f 102 void setCursor (bool cStatus = true, bool blink = false);
margadon 6:9ef0091c2a4f 103
margadon 6:9ef0091c2a4f 104 /** Shifts text.
margadon 6:9ef0091c2a4f 105 *
margadon 6:9ef0091c2a4f 106 * Text on the display is shifted left.
margadon 6:9ef0091c2a4f 107 */
margadon 6:9ef0091c2a4f 108 void shiftLeft (void);
margadon 6:9ef0091c2a4f 109
margadon 6:9ef0091c2a4f 110 /** Shifts text.
margadon 6:9ef0091c2a4f 111 *
margadon 6:9ef0091c2a4f 112 * Text on the display is shifted right.
margadon 6:9ef0091c2a4f 113 */
margadon 6:9ef0091c2a4f 114 void shiftRight (void);
margadon 6:9ef0091c2a4f 115
margadon 6:9ef0091c2a4f 116
margadon 6:9ef0091c2a4f 117 /** Shifts text.
margadon 6:9ef0091c2a4f 118 *
margadon 6:9ef0091c2a4f 119 * Text on the display is shifted left if direction is set (true) or right is direction is reset (false)
margadon 6:9ef0091c2a4f 120 */
margadon 6:9ef0091c2a4f 121 void shift (bool direction);
margadon 6:9ef0091c2a4f 122
margadon 6:9ef0091c2a4f 123 /** Clears the display, the cursor returns to its home position (0,0).
margadon 6:9ef0091c2a4f 124 *
margadon 6:9ef0091c2a4f 125 * The user should preserve caution when clearing the display in the main program loop, this very quickly results in flickering. A better approach is to
margadon 6:9ef0091c2a4f 126 * overwrite the display.
margadon 6:9ef0091c2a4f 127 */
margadon 6:9ef0091c2a4f 128 void cls (void);
margadon 6:9ef0091c2a4f 129
margadon 6:9ef0091c2a4f 130 /** Returns the cursor to positition (0,0). The display is NOT cleared.
margadon 6:9ef0091c2a4f 131 *
margadon 6:9ef0091c2a4f 132 * This function differs from setCursorPosition(0,0) in the way that home() undoes all preceding shift operations. i.e. If the display is shifted
margadon 6:9ef0091c2a4f 133 * one position right, the setCursorPosition(0,0) function call would place the cursor physically at the second character of the first row while
margadon 6:9ef0091c2a4f 134 * home() places it at the first character of the first row.
margadon 6:9ef0091c2a4f 135 */
margadon 6:9ef0091c2a4f 136 void home(void);
margadon 6:9ef0091c2a4f 137
margadon 6:9ef0091c2a4f 138 /** Reads the status of the buttons
margadon 6:9ef0091c2a4f 139 *
margadon 6:9ef0091c2a4f 140 *
margadon 6:9ef0091c2a4f 141 */
margadon 6:9ef0091c2a4f 142 int puts(const char *str);
margadon 6:9ef0091c2a4f 143
margadon 6:9ef0091c2a4f 144 float readButton(void);
margadon 6:9ef0091c2a4f 145
margadon 6:9ef0091c2a4f 146 protected:
margadon 6:9ef0091c2a4f 147 // Stream implementation functions
margadon 6:9ef0091c2a4f 148 virtual int _putc(int value);
margadon 6:9ef0091c2a4f 149 virtual int _getc();
margadon 6:9ef0091c2a4f 150 };
margadon 6:9ef0091c2a4f 151
margadon 6:9ef0091c2a4f 152 #endif