Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed_PT6302 mbed_PT6301
PT6302.h
00001 /* mbed PT6302 Library, for Princeton PT6302 VFD controller 00002 * Note the PT6302 is identical to the OKI ML9208 00003 * 00004 * Copyright (c) 2017, v01: WH, Initial version 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a copy 00007 * of this software and associated documentation files (the "Software"), to deal 00008 * in the Software without restriction, including without limitation the rights 00009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00010 * copies of the Software, and to permit persons to whom the Software is 00011 * furnished to do so, subject to the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be included in 00014 * all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00022 * THE SOFTWARE. 00023 */ 00024 00025 #ifndef PT6302_H 00026 #define PT6302_H 00027 00028 // Select one of the testboards for Princeton PT6302 VFD controller 00029 #include "PT6302_Config.h" 00030 #include "PT6302_UDC.h" 00031 00032 /** An interface for driving Princeton PT6302 VFD controller 00033 * 00034 * @code 00035 * 00036 * #if (PT6302_TEST == 1) 00037 * // Direct driving of PT6302 Test 00038 * 00039 * #include "mbed.h" 00040 * #include "PT6302.h" 00041 * 00042 * DigitalOut myled(LED1); 00043 * Serial pc(USBTX, USBRX); 00044 * 00045 * // PT6302 declaration, Default setting 16 Grids @ 35 Segments 00046 * PT6302 PT6302(p5, p7, p8); // DI, CLK, CS 00047 * 00048 * int main() { 00049 * pc.printf("Hello World: PT6302 test\n\r"); 00050 * 00051 * PT6302.cls(); 00052 * 00053 * PT6302.writeData((char)'H', 9); 00054 * PT6302.writeData((char)'e', 8); 00055 * PT6302.writeData((char)'l', 7); 00056 * PT6302.writeData((char)'l', 6); 00057 * PT6302.writeData((char)'o', 5); 00058 * wait(2); 00059 * PT6302.setBrightness(PT6302_BRT0); 00060 * wait(2); 00061 * PT6302.setBrightness(PT6302_BRT3); 00062 * 00063 * while(1) { 00064 * myled = !myled; 00065 * wait(1); 00066 * } 00067 * } 00068 * #endif 00069 * 00070 * @endcode 00071 */ 00072 00073 00074 //PT6302 Display and Annunciator data 00075 #define PT6302_MAX_NR_GRIDS 16 00076 #define PT6302_BYTES_PER_GRID 1 00077 00078 //Memory size in bytes for Display and Annunciators 00079 #define PT6302_DSP_MEM 16 00080 #define PT6302_ADD_MEM 16 00081 //#define PT6302_UDC_MEM 8 00082 00083 //SPI Serial control data consists of an 8-bit command and one or more data bytes. 00084 //Command and data are sent LSB first and latched on rising edge of CLK. Idle CLK is high. 00085 //Data address is auto incremented. 00086 //The commands and data are transmitted during CE low and latched on rising CE edge. 00087 //Multiple PT6302 devices on the same bus can only be distinguised by the CE control. 00088 00089 //Command delay 00090 #define PT6302_CMD_DLY 8 00091 #define PT6302_CS_DLY 16 00092 00093 // 00094 //Set Char data command (DCRAM) 00095 // 0 0 0 1 DA3 DA2 DA1 DA0 00096 #define PT6302_DATA_REG 0x10 00097 00098 //DA3..DA0 DCRAM Address 00099 #define PT6302_DADR_MSK 0x0F 00100 00101 //Char data (2nd byte, 3rd byte ...) 00102 //DA7..DA0 Character Data 00103 #define PT6302_DATA_MSK 0xFF 00104 00105 00106 // 00107 //Set UDC data command (CGRAM) 00108 // 0 0 1 0 * UA2 UA1 UA0 00109 #define PT6302_UDC_REG 0x20 00110 00111 //UA2..UA0 CGRAM Address (UDC RAM address) 00112 #define PT6302_UADR_MSK 0x07 00113 #define PT6302_NR_UDC 8 00114 00115 //User Defined Characters (UDCs) consist of 5x7 dots and are defined by a 5 byte bitpattern. 00116 //UDC data (2nd byte .. 6th byte) 00117 // D7 D6 D5 D4.. D1 D0 00118 // 0 * CD30 CD25 ...... CD0 00119 // 1 * CD31 CD26 ...... CD1 00120 // 2 * CD32 CD27 ...... CD2 00121 // 3 * CD33 CD28 ...... CD3 00122 // 4 * CD34 CD29 ...... CD4 00123 // 00124 #define PT6302_UDC_MSK 0x7F 00125 00126 //CD34..CD0 UDC Data 00127 //UDC is a 5x7 Matrix pattern that will show on the VFD as 00128 // 0 C0 C1 C2 C3 C4 00129 // 1 C5 C6 ..... C9 00130 // . ............. 00131 // . ............. 00132 // . ............. 00133 // 6 C30 C31 ... C34 00134 // 00135 00136 //UDCs are defined by a 5x7 matrix and stored as 5 bytes 00137 typedef char UDCData_t[5]; 00138 00139 00140 // 00141 //Set Additional data command (ADRAM), Used for annunciators etc 00142 // 0 0 1 1 AA3 AA2 AA1 AA0 00143 #define PT6302_ADAT_REG 0x30 00144 00145 //AA3..AA0 ADRAM Address (Additional data) 00146 #define PT6302_AADR_MSK 0x0F 00147 00148 //* * * * * * AD1 AD0 Additional Data (2nd byte, 3rd byte, ..) 00149 #define PT6302_ADAT_MSK 0x03 00150 00151 00152 // 00153 //Set Port data command (General output) 00154 // 0 1 0 0 * * P1 P0 00155 #define PT6302_PDAT_REG 0x40 00156 00157 //P1 P0 Port data 00158 #define PT6302_PDAT_MSK 0x03 00159 00160 00161 00162 // 00163 //Set Brightness command 00164 // 0 1 0 1 * DC2 DC1 DC0 00165 #define PT6302_BRT_REG 0x50 00166 #define PT6302_BRT_MSK 0x07 00167 00168 //DC2..DC0 Brightness Level (0..7) 00169 //Note Brightness relationship between the number of active Grids (period) and the BRT value (duty cycle) 00170 #define PT6302_BRT_0 0x00 //Duty 8/16 (Default) 00171 #define PT6302_BRT_1 0x01 00172 #define PT6302_BRT_2 0x02 00173 #define PT6302_BRT_3 0x03 00174 #define PT6302_BRT_4 0x04 00175 #define PT6302_BRT_5 0x05 00176 #define PT6302_BRT_6 0x06 00177 #define PT6302_BRT_7 0x07 //Duty 15/16 00178 00179 #define PT6302_BRT_DEF (PT6302_BRT_2) 00180 00181 00182 // 00183 //Grid control command 00184 // 0 1 1 0 * GN2 GN1 GN0 00185 #define PT6302_GRID_REG 0x60 00186 #define PT6302_GRID_MSK 0x07 00187 00188 //Grids 00189 // 00190 // GN2 GN1 GN0 00191 // 0 0 0 G1 to G16 // Default 00192 // 0 0 1 G1 to G9 00193 // 0 1 0 G1 to G10 00194 // 0 1 1 G1 to G11 00195 // 1 0 0 G1 to G12 00196 // 1 0 1 G1 to G13 00197 // 1 1 0 G1 to G14 00198 // 1 1 1 G1 to G15 00199 #define PT6302_GR1_GR9 0x01 00200 #define PT6302_GR1_GR10 0x02 00201 #define PT6302_GR1_GR11 0x03 00202 #define PT6302_GR1_GR12 0x04 00203 #define PT6302_GR1_GR13 0x05 00204 #define PT6302_GR1_GR14 0x06 00205 #define PT6302_GR1_GR15 0x07 00206 #define PT6302_GR1_GR16 0x00 00207 00208 00209 // 00210 //Display On/Off command 00211 // 0 1 1 1 * * H L 00212 #define PT6302_DSPL_REG 0x70 00213 #define PT6302_DSPL_MSK 0x03 00214 00215 //Display Mode 00216 // H L Display operating state 00217 // 0 0 Normal (default) 00218 // 0 1 Off 00219 // 1 0 All Segments and Additional Segments On 00220 // 1 1 All Segments and Additional Segments On 00221 #define PT6302_DSPL_NRM 0x00 00222 #define PT6302_DSPL_OFF 0x01 00223 #define PT6302_DSPL_ON 0x02 00224 00225 00226 /** A class for driving Princeton PT6302 VFD controller 00227 * 00228 * @brief Supports upto 16 Grids of 35 matrix segments. 00229 * Also supports 2 additional segments and 2 port pins. 00230 * SPI bus interface device. 00231 */ 00232 class PT6302 { 00233 public: 00234 00235 /** Enums for display mode */ 00236 enum Mode { 00237 Grid9_Add2 = PT6302_GR1_GR9, 00238 Grid10_Add2 = PT6302_GR1_GR10, 00239 Grid11_Add2 = PT6302_GR1_GR11, 00240 Grid12_Add2 = PT6302_GR1_GR12, 00241 Grid13_Add2 = PT6302_GR1_GR13, 00242 Grid14_Add2 = PT6302_GR1_GR14, 00243 Grid15_Add2 = PT6302_GR1_GR15, 00244 Grid16_Add2 = PT6302_GR1_GR16 00245 }; 00246 00247 /** Datatypes for display data */ 00248 // typedef char DisplayData_t[PT6302_DISPLAY_MEM]; 00249 // typedef char DisplayAdd_t[PT6302_ADD_MEM]; 00250 00251 /** Constructor for class for driving Princeton PT6302 VFD controller 00252 * 00253 * @brief Supports upto 16 Grids of 35 matrix segments. 00254 * Also supports 2 additional segments and 2 port pins. 00255 * SPI bus interface device. 00256 * @param PinName mosi, sclk, cs SPI bus pins 00257 * @param Mode selects number of Grids and Segments (default 16 Grids, 2 additional segments) 00258 */ 00259 PT6302(PinName mosi, PinName sclk, PinName cs, Mode mode = Grid16_Add2); 00260 00261 /** Clear the screen 00262 * 00263 * @param none 00264 * @return none 00265 */ 00266 void cls(); 00267 00268 /** Set Brightness 00269 * 00270 * @param char brightness (3 significant bits, valid range 0..7 (dutycycle linked to number of grids) 00271 * @return none 00272 */ 00273 void setBrightness(char brightness = PT6302_BRT_DEF); 00274 00275 /** Set the Display mode On/off 00276 * 00277 * @param bool display mode 00278 * @return none 00279 */ 00280 void setDisplay(bool on); 00281 00282 00283 /** Set Port 00284 * 00285 * @param char port (2 least significant bits) 00286 * @return none 00287 */ 00288 void setPort (char port = 0); 00289 00290 /** Set User Defined Characters (UDC) 00291 * 00292 * @param unsigned char udc_idx The Index of the UDC (0..7) 00293 * @param UDCData_t udc_data The bitpattern for the UDC (5 bytes) 00294 * @return none 00295 */ 00296 void setUDC(unsigned char udc_idx, UDCData_t udc_data); 00297 00298 00299 /** Write Data to PT6302 00300 * 00301 * @param char data Character code 00302 * @param char address Parameter for data 00303 * @return none 00304 */ 00305 void writeData(char data, char address); 00306 00307 /** Write Additional Data to PT6302 00308 * 00309 * @param char adata Additional code (annunciator) 00310 * @param char address Parameter for data 00311 * @return none 00312 */ 00313 void writeAData(char adata, char address); 00314 00315 protected: 00316 /** Write command and parameters to PT6302 00317 * 00318 * @param char cmd Command byte 00319 * @param char data Parameter for command 00320 * @return none 00321 */ 00322 void _writeCmd(char cmd, char data); 00323 00324 /** Write command to PT6302 00325 * 00326 * @param char cmd Command byte 00327 * @return none 00328 */ 00329 void _writeCmd(char cmd); 00330 00331 char _port; 00332 00333 private: 00334 SPI _spi; 00335 DigitalOut _cs; 00336 Mode _mode; 00337 00338 /** Init the SPI interface and the controller 00339 * 00340 * @param none 00341 * @return none 00342 */ 00343 void _init(); 00344 00345 /** Helper to reverse all command or databits. The PT6302 expects LSB first, whereas SPI is MSB first 00346 * 00347 * @param char data 00348 * @return bitreversed data 00349 */ 00350 char _flip(char data); 00351 00352 }; 00353 00354 00355 #if (HANNSTAR_TEST == 1) 00356 // Derived class for HANNSTAR display unit 00357 // Grids 1-16 all display 35 segment matrix characters and no Additional segments. 00358 // 00359 00360 //HANNSTAR Display data 00361 #define HANNSTAR_NR_GRIDS 16 00362 #define HANNSTAR_NR_DIGITS 16 00363 //#define HANNSTAR_NR_UDC 8 00364 00365 //HANNSTAR Memory size in bytes for Display 00366 //#define HANNSTAR_DISPLAY_MEM (HANNSTAR_NR_GRIDS * PT6302_BYTES_PER_GRID) 00367 00368 00369 // 00370 //Set Port data command (General output) 00371 // 0 1 0 0 * * P1 P0 00372 00373 //P0 P1 Port data, P0 is used for VGen control 00374 #define PT6302_HANN_PDAT_MSK 0x02 00375 00376 //P0 is used to control the VFD Voltage generator (-24V and Filament) 00377 #define PT6302_HANN_VGEN 0x01 00378 00379 00380 00381 /** Constructor for class for driving Princeton PT6302 VFD controller as used in HANNSTAR 00382 * 00383 * @brief Supports 16 Grids of 35 Segments without additional Segments. 00384 * 00385 * @param PinName mosi, sclk, cs SPI bus pins 00386 */ 00387 class PT6302_HANNSTAR : public PT6302, public Stream { 00388 public: 00389 00390 /** Constructor for class for driving Princeton PT6302 VFD controller as used in HANNSTAR 00391 * 00392 * @brief Supports 16 Grids of 35 Segments without additional Segments. 00393 * 00394 * @param PinName mosi, sclk, cs SPI bus pins 00395 */ 00396 PT6302_HANNSTAR(PinName mosi, PinName sclk, PinName cs); 00397 00398 #if DOXYGEN_ONLY 00399 /** Write a character to the Display 00400 * 00401 * @param c The character to write to the display 00402 * @return char written 00403 */ 00404 int putc(int c); 00405 00406 /** Write a formatted string to the Display 00407 * 00408 * @param format A printf-style format string, followed by the 00409 * variables to use in formatting the string. 00410 */ 00411 int printf(const char* format, ...); 00412 #endif 00413 00414 /** Locate cursor to a screen column 00415 * 00416 * @param column The horizontal position from the left, indexed from 0 00417 * @return none 00418 */ 00419 void locate(int column); 00420 00421 /** Clear the screen and locate to 0 00422 * 00423 * @param bool clrAll Clear Icons also (default = false) 00424 */ 00425 void cls(bool clrAll = false); 00426 00427 /** Number of screen columns 00428 * 00429 * @param none 00430 * @return columns 00431 */ 00432 int columns(); 00433 00434 /** Set Port 00435 * 00436 * @param char port (Only Bit 1 is used) 00437 * @return none 00438 */ 00439 void setPort (char port = 0); 00440 00441 /** Set VFD VGen 00442 * 00443 * @param bool on 00444 * @return none 00445 */ 00446 void setVGen (bool on = true); 00447 00448 protected: 00449 // Stream implementation functions 00450 virtual int _putc(int value); 00451 virtual int _getc(); 00452 00453 private: 00454 int _column; // Current cursor location 00455 int _columns; // Max number of columns 00456 00457 // DisplayData_t _displaybuffer; // Local mirror for all chars and icons 00458 }; 00459 #endif 00460 00461 #endif
Generated on Thu Jul 14 2022 03:33:37 by
1.7.2
PT6302 VFD Driver for upto 16 Dot Matrix Characters and two icons per digit.