Lib for Noritake Itron CU209SCPB VFD Module (1 Line, 20 Chars), Serial interface

Dependents:   mbed_CU209SCPB_T20

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CU209SCPB.h Source File

CU209SCPB.h

00001 /* mbed CU209SCPB Library, for Noritake Itron CU209SCPB VFD module
00002  *
00003  * Copyright (c) 2017, v01: WH, Initial version
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  */
00023 
00024 #ifndef CU209SCPB_H
00025 #define CU209SCPB_H
00026 
00027 // Select Noritake Itron CU209SCPB VFD module settings
00028 #include "CU209SCPB_Config.h"
00029 
00030 #include "CU209SCPB_UDC.h"
00031 
00032 /** An interface for driving Noritake Itron CU209SCPB VFD module
00033  *
00034  * @code
00035  *
00036  * #include "mbed.h"
00037  * #include "CU209SCPB.h" 
00038  *
00039  * DigitalOut myled(LED1);
00040  * Serial pc(USBTX, USBRX);
00041  * 
00042  * // CU209SCPB declaration, Default setting
00043  * CU209SCPB CU209SCPB(p9); // TXD
00044  *
00045  * int main() {
00046  *   pc.printf("Hello World: CU209SCPB test\n\r");
00047  *
00048  *   CU209SCPB.cls(); 
00049  *
00050  *   CU209SCPB.putc('H');
00051  *   CU209SCPB.putc('e');
00052  *   CU209SCPB.putc('l');
00053  *   CU209SCPB.putc('l');
00054  *   CU209SCPB.putc('0');
00055  *   CU209SCPB.putc(' ');  
00056  *   CU209SCPB.printf("World);
00057  *   wait(2);
00058  *   CU209SCPB.setBrightness(CU209SCPB_BRT0);
00059  *   wait(2);
00060  *   CU209SCPB.setBrightness(CU209SCPB_BRT3);
00061  *           
00062  *   while(1) {
00063  *     myled = !myled;
00064  *     wait(1);
00065  *   }
00066  * }
00067  * #endif
00068  *
00069  * @endcode
00070  */
00071 
00072 
00073 //CU209SCPB Display data
00074 #define CU209SCPB_MAX_NR_GRIDS   20
00075 #define CU209SCPB_BYTES_PER_GRID  1
00076 
00077 //Memory size in bytes for Display
00078 #define CU209SCPB_DSP_MEM    (CU209SCPB_MAX_NR_GRIDS * CU209SCPB_BYTES_PER_GRID)
00079 
00080 //CU209SCPB Characters per line
00081 #define CU209SCPB_NR_COLS     CU209SCPB_MAX_NR_GRIDS
00082 
00083 //CU209SCPB User Defined Characters
00084 #define CU209SCPB_NR_UDC          8
00085 //#define CU209SCPB_UDC_MEM         8
00086 
00087 
00088 //Serial control data consists of an 8-bit command and one or more data bytes.
00089 //Command and data are sent LSB first. Data address is auto incremented.
00090 
00091 //Command delay
00092 #define CU209SCPB_CMD_DLY         8
00093 
00094 //Commands Characters
00095 #define D_BS                   0x08
00096 #define D_HT                   0x09
00097 #define D_LF                   0x0A
00098 #define D_FF                   0x0C
00099 #define D_CR                   0x0D
00100 #define D_CLR                  0x0E
00101 
00102 #define D_DC1                  0x11
00103 #define D_DC2                  0x12
00104 #define D_DC3                  0x13
00105 #define D_DC4                  0x14
00106 #define D_DC5                  0x15
00107 #define D_DC6                  0x16
00108 #define D_DC7                  0x17
00109 #define D_CT0                  0x18
00110 #define D_CT1                  0x19
00111 #define D_ESC                  0x1B
00112 
00113 //Display Characters
00114 #define CU209SCPB_CHR_STRT     0x20
00115 #define CU209SCPB_CHR_END      0xFF
00116 
00117 
00118 //User Defined Characters (UDCs) are a 5x7 Matrix pattern that will show on the VFD as
00119 // 0   P1  P2  P3  P4  P5
00120 // 1   P6  P7 .....    P10
00121 // .    .............
00122 // .    .............
00123 // .    .............
00124 // 6   P31 P32 ...     P35
00125 //
00126 
00127 //UDCs are defined by sending a 5 byte bitpattern to the display.
00128 //UDC Command: ESC, 'C', UDC idx
00129 //Followed by:
00130 //UDC Data (4th byte .. 8th byte)
00131 //    D7  D6   D5   D4  D3  D2  D1  D0 
00132 // 0  P8  P7   P6   ......  P3  P2  P1
00133 // 1  P16 P15  P14  ........    P10 P9
00134 // 2  P24 P23  P22  ..........      P17
00135 // 3  P32 P31  P30  ............    P25
00136 // 4  *   *    *    .... *  P35 P34 P33
00137 //
00138 //UDCs are defined by a 5x7 matrix and stored for convenience as 7 bytes with 5 significant bits
00139 typedef char UDCData_t[7];
00140 
00141 //Any character in the CU209SCPB ROM can be redefined as UDC.
00142 //However, the lib restricts UDCs to the first 8 characters (which are not in use anyhow).
00143 #define CU209SCPB_UADR_MSK     0x07
00144 
00145 
00146 //Brightness Level (0..3)
00147 #define CU209SCPB_BRT_0        0x00   //Duty  25%
00148 #define CU209SCPB_BRT_1        0x40   //Duty  50%
00149 #define CU209SCPB_BRT_2        0x80   //Duty  75%
00150 #define CU209SCPB_BRT_3        0xC0   //Duty 100% (Default)
00151 
00152 #define CU209SCPB_BRT_DEF      (CU209SCPB_BRT_1)
00153 
00154 #define CU209SCPB_BRT_MSK      0xFF
00155 
00156 
00157 
00158 /** A class for driving Noritake Itron CU209SCPB VFD module
00159  *
00160  *  @brief Supports 1 line of 20 chars (5x7 matrix segments).
00161  *         Serial bus interface device. 
00162  *  @param  PinName TX Serial bus pin
00163  *  @param  Baud baud selects baudrate (default 19200)
00164  *  @param  Int Parity selects paritybits (default Even)  
00165  */
00166 class CU209SCPB : public Stream {
00167 
00168  public:
00169 
00170 /** Enums
00171   */
00172   enum Baud {
00173     B_300   = 300,
00174     B_600   = 600,
00175     B_1200  = 1200,
00176     B_2400  = 2400,
00177     B_9600  = 9600,
00178     B_19200 = 19200
00179   };
00180 
00181 /** Constructor for class for driving Noritake Itron CU209SCPB VFD module
00182   *
00183   *  @brief Supports 1 line of 20 chars (5x7 matrix segments).
00184   *         Serial bus interface device. 
00185   *  @param  PinName TX Serial bus pin
00186   *  @param  Baud baud selects baudrate (default 19200)  
00187   *  @param  Parity parity selects paritybits (default Even)  
00188   */
00189   CU209SCPB(PinName TXD, Baud baud = B_19200, SerialBase::Parity parity = SerialBase::Even);
00190       
00191   /** Clear the screen and locate to 0
00192     *
00193     * @param none
00194     * @return none  
00195     */
00196   void cls();
00197 
00198   /** Locate cursor to a screen column
00199     *
00200     * @param column  The horizontal position from the left, indexed from 0
00201     * @return none     
00202     */
00203   void locate(int column);
00204     
00205   /** Number of screen columns
00206     *
00207     * @param none
00208     * @return columns
00209     */
00210   int columns();  
00211 
00212 #if DOXYGEN_ONLY
00213   /** Write a character to the Display
00214     *
00215     * @param c The character to write to the display
00216     * @return char written
00217     */
00218   int putc(int c);
00219 
00220   /** Write a formatted string to the Display
00221     *
00222     * @param format A printf-style format string, followed by the
00223     *               variables to use in formatting the string.
00224     */
00225   int printf(const char* format, ...);   
00226 #endif
00227 
00228   /** Set Brightness
00229     *
00230     * @param  char brightness (3 significant bits, valid range 0..7 (dutycycle linked to number of grids)  
00231     * @return none
00232     */    
00233   void setBrightness(char brightness = CU209SCPB_BRT_DEF);
00234   
00235   /** Set the Cursor mode On/off
00236     *
00237     * @param bool cursor mode
00238     * @return none    
00239     */
00240   void setCursor(bool on);
00241 
00242   /** Set Font
00243     *
00244     * @param  int font (valid range: 0 == International, other == Katakana)  
00245     * @return none
00246     */
00247   void setFont(int font = 0);
00248 
00249   /** Set User Defined Characters (UDC)
00250     *
00251     * @param unsigned char udc_idx   The Index of the UDC (0..7)
00252     * @param UDCData_t udc_data      The bitpattern for the UDC (7 bytes)
00253     * @return none    
00254     */
00255   void setUDC(unsigned char udc_idx, UDCData_t udc_data);
00256 
00257  protected:  
00258     // Stream implementation functions
00259     virtual int _putc(int value);
00260     virtual int _getc();
00261  
00262  
00263   /** Init the Serial interface and the module
00264     *
00265     * @param  none
00266     * @return none
00267     */ 
00268   void _init();
00269 
00270  private:  
00271    Serial _serial;
00272    Baud _baud;
00273    SerialBase::Parity _parity;
00274   
00275    int _column;                     // Current cursor location
00276    int _columns;                    // Max number of columns
00277 };
00278 #endif
00279