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.
main.cpp
00001 /* mbed PT6311 Test program, for Princeton PT6311 VFD controller 00002 * Copyright (c) 2016, v01: WH, Initial version, VFDEM2 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 * THE SOFTWARE. 00021 */ 00022 #include "mbed.h" 00023 #include "PT6311.h" 00024 00025 // Select one of the testboards for Princeton PT6311 VFD controller 00026 00027 #if (VFDEM2_TEST == 1) 00028 // VFDEM2 PT6311 Test 00029 #include "mbed.h" 00030 #include "PT6311.h" 00031 #include "Font_16Seg.h" 00032 00033 Serial pc(USBTX, USBRX); 00034 DigitalOut myled(LED1); 00035 00036 // DisplayData_t size is 24 bytes (8 grids @ max 20 segments) ... 48 bytes (16 grids @ max 12 segments) 00037 // DisplayData_t size for VFDEM2 is 36 bytes (12 Grids @ 16 Segments) 00038 PT6311::DisplayData_t all_str = {0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, \ 00039 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, \ 00040 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00}; 00041 00042 PT6311::DisplayData_t cls_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00043 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00044 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00}; 00045 00046 PT6311::DisplayData_t bye_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00047 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00048 LO(C16_E),MD(C16_E),HI(C16_E), LO(C16_Y),MD(C16_Y),HI(C16_Y), LO(C16_B),MD(C16_B),HI(C16_B), 0x00,0x00,0x00}; 00049 00050 PT6311::DisplayData_t hello_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00051 0x00,0x00,0x00, 0x00,0x00,0x00, LO(C16_O),MD(C16_O),HI(C16_O), LO(C16_L),MD(C16_L),HI(C16_L), \ 00052 LO(C16_L),MD(C16_L),HI(C16_L), LO(C16_E),MD(C16_E),HI(C16_E), LO(C16_H),MD(C16_H),HI(C16_H), 0x00,0x00,0x00}; 00053 00054 PT6311::DisplayData_t mbed_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00055 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, LO(C16_D),MD(C16_D),HI(C16_D), \ 00056 LO(C16_E),MD(C16_E),HI(C16_E), LO(C16_B),MD(C16_B),HI(C16_B), LO(C16_M),MD(C16_M),HI(C16_M), 0x00,0x00,0x00}; 00057 00058 // KeyData_t size is 3 bytes 00059 PT6311::KeyData_t keydata; 00060 00061 // Switchdata is 1 byte 00062 char switchdata; 00063 00064 //PT6311_VFDEM2 declaration, Setting 12 Grids @ 16 Segments 00065 PT6311_VFDEM2 VFDEM2(p5,p6,p7, p8); 00066 00067 char cmd, bits; 00068 int main() { 00069 00070 pc.printf("Hello World\r\n"); // 00071 00072 VFDEM2.cls(); 00073 VFDEM2.writeData(all_str); 00074 wait(4); 00075 VFDEM2.setBrightness(PT6311_BRT3); 00076 wait(1); 00077 VFDEM2.setBrightness(PT6311_BRT0); 00078 wait(1); 00079 VFDEM2.setBrightness(PT6311_BRT7); 00080 00081 while (1) { 00082 00083 // Check and read keydata 00084 if (VFDEM2.getKeys(&keydata)) { 00085 pc.printf("Keydata 0..5 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4], keydata[5]); 00086 00087 if (keydata[0] == 0x01) { //K1 00088 VFDEM2.cls(); 00089 VFDEM2.writeData(all_str); 00090 } 00091 00092 if (keydata[0] == 0x02) { //K2 00093 VFDEM2.cls(); 00094 00095 #if(1) 00096 //test to show all segs 00097 pc.printf("Show all segs\r\n"); 00098 wait(1); 00099 VFDEM2.cls(); 00100 00101 for (int i=0; i<PT6311_DISPLAY_MEM; i++) { 00102 for (int bit=0; bit<8; bit++) { 00103 VFDEM2.cls(); 00104 00105 bits = 0x01 << bit; 00106 VFDEM2.writeData(i, bits); 00107 00108 pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits); 00109 // wait(0.5); 00110 cmd = pc.getc(); // wait for key 00111 } 00112 } 00113 pc.printf("Show all segs done\r\n"); 00114 #endif 00115 } 00116 00117 00118 if (keydata[0] == 0x04) { //K3 00119 00120 #if(0) 00121 //test to show all digits (base is 10) 00122 pc.printf("Show all digits\r\n"); 00123 wait(1); 00124 VFDEM2.cls(); 00125 00126 long long int val = 1; 00127 for (int i=0; i<VFDEM2_NR_DIGITS; i++) { 00128 00129 for (long long int cnt=0; cnt<10; cnt++) { 00130 VFDEM2.locate(0); 00131 VFDEM2.printf("%010lld", (val * cnt)); 00132 00133 // wait(0.5); 00134 cmd = pc.getc(); // wait for key 00135 } 00136 val = val * 10; 00137 } 00138 pc.printf("Show all digits done\r\n"); 00139 #endif 00140 00141 #if(1) 00142 //test to show all digits (base is 0x10) 00143 pc.printf("Show all digits\r\n"); 00144 wait(1); 00145 00146 VFDEM2.cls(); 00147 VFDEM2.printf("%d", 0); 00148 cmd = pc.getc(); // wait for key 00149 00150 VFDEM2.cls(); 00151 VFDEM2.printf("%3.4f", 12.3456); 00152 cmd = pc.getc(); // wait for key 00153 00154 VFDEM2.cls(); 00155 VFDEM2.printf("%d", 123456); 00156 cmd = pc.getc(); // wait for key 00157 00158 VFDEM2.cls(); 00159 VFDEM2.printf("%010llx", 0x0123456ABCl); //Note this value needs 64bits 00160 cmd = pc.getc(); // wait for key 00161 00162 long long int val = 1; 00163 for (int i=0; i<VFDEM2_NR_DIGITS; i++) { 00164 00165 for (long long int cnt=0; cnt<0x10; cnt++) { 00166 VFDEM2.locate(0); 00167 VFDEM2.printf("%010llx", (val * cnt)); 00168 // wait(0.5); 00169 cmd = pc.getc(); // wait for key 00170 } 00171 val = val * 0x10; 00172 } 00173 pc.printf("Show all digits done\r\n"); 00174 #endif 00175 00176 } 00177 00178 if (keydata[0] == 0x08) { //K4 00179 00180 #if(1) 00181 //test to show all alpha chars 00182 pc.printf("Show all alpha chars\r\n"); 00183 wait(1); 00184 VFDEM2.cls(); 00185 00186 for (int i=0; i<26; i++) { 00187 VFDEM2.printf("%c", char(i + 'A')); 00188 // VFDEM2.printf("%c", char(i + 'a')); 00189 wait(0.25); 00190 } 00191 pc.printf("Show all alpha chars done\r\n"); 00192 #endif 00193 00194 #if(0) 00195 //test to show all chars 00196 pc.printf("Show all chars\r\n"); 00197 wait(1); 00198 VFDEM2.cls(); 00199 00200 for (int i=FONT_16S_START; i<FONT_16S_END; i++) { 00201 VFDEM2.printf("%c", char(i)); 00202 // wait(0.25); 00203 cmd = pc.getc(); // wait for key 00204 } 00205 pc.printf("Show all chars done\r\n"); 00206 #endif 00207 00208 #if(1) 00209 //wheel 00210 for(int cnt=0;cnt<10;cnt++) { 00211 for(int idx=0;idx<8;idx++) { 00212 VFDEM2.setUDC(0, WHEEL_ANI[idx]); 00213 VFDEM2.locate(0); 00214 VFDEM2.printf("%c%c%c%c%c%c%c%c%c%c",(char)0,(char)0, (char)0,(char)0, (char)0,(char)0, (char)0,(char)0, (char)0,(char)0); 00215 00216 wait(0.1); 00217 } 00218 } 00219 #endif 00220 00221 00222 #if(1) 00223 float delay=0.1; 00224 // Piechart Icons on 00225 VFDEM2.setIcon(PT6311_VFDEM2::CIR); wait(delay); 00226 00227 for(int cnt=0; cnt<10; cnt++) { 00228 VFDEM2.setIcon(PT6311_VFDEM2::PIE_R); 00229 VFDEM2.clrIcon(PT6311_VFDEM2::PIE_B); wait(delay); 00230 00231 VFDEM2.setIcon(PT6311_VFDEM2::PIE_G); 00232 VFDEM2.clrIcon(PT6311_VFDEM2::PIE_R); wait(delay); 00233 00234 VFDEM2.setIcon(PT6311_VFDEM2::PIE_B); 00235 VFDEM2.clrIcon(PT6311_VFDEM2::PIE_G); wait(delay); 00236 } 00237 00238 VFDEM2.clrIcon(PT6311_VFDEM2::PIE_B); wait(delay); 00239 00240 VFDEM2.clrIcon(PT6311_VFDEM2::CIR); wait(delay); 00241 00242 wait(delay); 00243 #endif 00244 00245 VFDEM2.cls(); 00246 // 0123456789 00247 VFDEM2.printf("Hello mbed"); 00248 } 00249 00250 if (keydata[0] == 0x10) { //K5 00251 00252 #if(1) 00253 //test to show all icons 00254 pc.printf("Show all icons\r\n"); 00255 wait(1); 00256 VFDEM2.cls(true); // Also clear all Icons 00257 wait(1); 00258 00259 float delay=0.1; 00260 VFDEM2.setIcon(PT6311_VFDEM2::STP); wait(delay); 00261 VFDEM2.setIcon(PT6311_VFDEM2::PSE); wait(delay); 00262 VFDEM2.setIcon(PT6311_VFDEM2::PLY); wait(delay); 00263 VFDEM2.setIcon(PT6311_VFDEM2::RR); wait(delay); 00264 VFDEM2.setIcon(PT6311_VFDEM2::LL); wait(delay); 00265 VFDEM2.setIcon(PT6311_VFDEM2::PCM); wait(delay); 00266 VFDEM2.setIcon(PT6311_VFDEM2::DTS); wait(delay); 00267 VFDEM2.setIcon(PT6311_VFDEM2::MIC); wait(delay); 00268 VFDEM2.setIcon(PT6311_VFDEM2::DLB); wait(delay); 00269 VFDEM2.setIcon(PT6311_VFDEM2::REC); wait(delay); 00270 VFDEM2.setIcon(PT6311_VFDEM2::PRG); wait(delay); 00271 VFDEM2.setIcon(PT6311_VFDEM2::RND); wait(delay); 00272 VFDEM2.setIcon(PT6311_VFDEM2::DP8); wait(delay); 00273 VFDEM2.setIcon(PT6311_VFDEM2::COL8); wait(delay); 00274 VFDEM2.setIcon(PT6311_VFDEM2::ANG); wait(delay); 00275 VFDEM2.setIcon(PT6311_VFDEM2::ZM); wait(delay); 00276 VFDEM2.setIcon(PT6311_VFDEM2::PBC); wait(delay); 00277 VFDEM2.setIcon(PT6311_VFDEM2::COL6); wait(delay); 00278 VFDEM2.setIcon(PT6311_VFDEM2::MP3); wait(delay); 00279 VFDEM2.setIcon(PT6311_VFDEM2::CDDA); wait(delay); 00280 VFDEM2.setIcon(PT6311_VFDEM2::SS); wait(delay); 00281 VFDEM2.setIcon(PT6311_VFDEM2::VCD); wait(delay); 00282 VFDEM2.setIcon(PT6311_VFDEM2::DVD); wait(delay); 00283 VFDEM2.setIcon(PT6311_VFDEM2::ARW); wait(delay); 00284 VFDEM2.setIcon(PT6311_VFDEM2::ONE); wait(delay); 00285 VFDEM2.setIcon(PT6311_VFDEM2::ALL); wait(delay); 00286 VFDEM2.setIcon(PT6311_VFDEM2::AA); wait(delay); 00287 VFDEM2.setIcon(PT6311_VFDEM2::BB); wait(delay); 00288 VFDEM2.setIcon(PT6311_VFDEM2::TTL); wait(delay); 00289 VFDEM2.setIcon(PT6311_VFDEM2::CHP); wait(delay); 00290 wait(delay); 00291 VFDEM2.clrIcon(PT6311_VFDEM2::STP); wait(delay); 00292 VFDEM2.clrIcon(PT6311_VFDEM2::PSE); wait(delay); 00293 VFDEM2.clrIcon(PT6311_VFDEM2::PLY); wait(delay); 00294 VFDEM2.clrIcon(PT6311_VFDEM2::RR); wait(delay); 00295 VFDEM2.clrIcon(PT6311_VFDEM2::LL); wait(delay); 00296 VFDEM2.clrIcon(PT6311_VFDEM2::PCM); wait(delay); 00297 VFDEM2.clrIcon(PT6311_VFDEM2::DTS); wait(delay); 00298 VFDEM2.clrIcon(PT6311_VFDEM2::MIC); wait(delay); 00299 VFDEM2.clrIcon(PT6311_VFDEM2::DLB); wait(delay); 00300 VFDEM2.clrIcon(PT6311_VFDEM2::REC); wait(delay); 00301 VFDEM2.clrIcon(PT6311_VFDEM2::PRG); wait(delay); 00302 VFDEM2.clrIcon(PT6311_VFDEM2::RND); wait(delay); 00303 VFDEM2.clrIcon(PT6311_VFDEM2::DP8); wait(delay); 00304 VFDEM2.clrIcon(PT6311_VFDEM2::COL8); wait(delay); 00305 VFDEM2.clrIcon(PT6311_VFDEM2::ANG); wait(delay); 00306 VFDEM2.clrIcon(PT6311_VFDEM2::ZM); wait(delay); 00307 VFDEM2.clrIcon(PT6311_VFDEM2::PBC); wait(delay); 00308 VFDEM2.clrIcon(PT6311_VFDEM2::COL6); wait(delay); 00309 VFDEM2.clrIcon(PT6311_VFDEM2::MP3); wait(delay); 00310 VFDEM2.clrIcon(PT6311_VFDEM2::CDDA); wait(delay); 00311 VFDEM2.clrIcon(PT6311_VFDEM2::SS); wait(delay); 00312 VFDEM2.clrIcon(PT6311_VFDEM2::VCD); wait(delay); 00313 VFDEM2.clrIcon(PT6311_VFDEM2::DVD); wait(delay); 00314 VFDEM2.clrIcon(PT6311_VFDEM2::ARW); wait(delay); 00315 VFDEM2.clrIcon(PT6311_VFDEM2::ONE); wait(delay); 00316 VFDEM2.clrIcon(PT6311_VFDEM2::ALL); wait(delay); 00317 VFDEM2.clrIcon(PT6311_VFDEM2::AA); wait(delay); 00318 VFDEM2.clrIcon(PT6311_VFDEM2::BB); wait(delay); 00319 VFDEM2.clrIcon(PT6311_VFDEM2::TTL); wait(delay); 00320 VFDEM2.clrIcon(PT6311_VFDEM2::CHP); wait(delay); 00321 00322 wait(1); 00323 VFDEM2.cls(); // clear all, preserve Icons 00324 pc.printf("Show all icons done\r\n"); 00325 #endif 00326 } 00327 00328 if (keydata[0] == 0x20) { //K6 00329 //write LEDs off 00330 VFDEM2.setLED(0x01); 00331 } 00332 00333 if (keydata[0] == 0x40) { //K7 00334 //write LEDs on 00335 VFDEM2.setLED(0x00); 00336 } 00337 00338 } //if Key 00339 00340 00341 // Check and read switch data (not supported on VFDEM2) 00342 switchdata = VFDEM2.getSwitches(); 00343 00344 if (switchdata != 0) { 00345 pc.printf("Switchdata = 0x%02x\r\n", switchdata); 00346 00347 if (switchdata == PT6311_SW1) { //S1 00348 VFDEM2.cls(); 00349 VFDEM2.writeData(hello_str); 00350 } 00351 00352 if (switchdata == PT6311_SW2) { //S2 00353 VFDEM2.cls(); 00354 VFDEM2.writeData(bye_str); 00355 } 00356 00357 if (switchdata == PT6311_SW3) { //S3 00358 VFDEM2.cls(); 00359 VFDEM2.writeData(mbed_str); 00360 } 00361 00362 VFDEM2.setLED(switchdata); //write LEDs in same pattern 00363 } //if Switch 00364 00365 00366 myled = !myled; 00367 wait(0.3); 00368 } //while 00369 } 00370 #endif 00371 00372 00373 #if(PT6311_TEST == 1) 00374 // Direct PT6311 Test 00375 #include "mbed.h" 00376 #include "PT6311.h" 00377 00378 Serial pc(USBTX, USBRX); 00379 DigitalOut myled(LED1); 00380 00381 // DisplayData_t size is 24 bytes (8 digits @ max 20 segments) ... 48 bytes (16 digits @ max 12 segments) 00382 // DisplayData_t size default is 48 bytes (16 Grids @ 12 Segments) 00383 PT6311::DisplayData_t all_str = {0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, \ 00384 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, \ 00385 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, \ 00386 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00}; 00387 00388 PT6311::DisplayData_t cls_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00389 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00390 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00}; 00391 00392 // KeyData_t size is 6 bytes 00393 PT6311::KeyData_t keydata; 00394 00395 // Switchdata is 1 byte 00396 char switchdata; 00397 00398 PT6311 PT6311(p5,p6,p7, p8); 00399 //PT6311 PT6311(p5,p6,p7, p8, PT6311::Grid16_Seg12); 00400 00401 char cmd, bits; 00402 int main() { 00403 00404 pc.printf("Hello World\r\n"); // 00405 00406 PT6311.cls(); 00407 PT6311.writeData(all_str); 00408 wait(4); 00409 PT6311.setBrightness(PT6311_BRT3); 00410 wait(1); 00411 PT6311.setBrightness(PT6311_BRT0); 00412 wait(1); 00413 PT6311.setBrightness(PT6311_BRT7); 00414 00415 while (1) { 00416 00417 // Check and read keydata 00418 if (PT6311.getKeys(&keydata)) { 00419 pc.printf("Keydata 0..5 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4], keydata[5]); 00420 00421 if (keydata[0] == 0x01) { //play 00422 PT6311.cls(); 00423 PT6311.writeData(all_str); 00424 } 00425 00426 if (keydata[0] == 0x02) { //stop 00427 PT6311.cls(); 00428 PT6311.writeData(cls_str); 00429 } 00430 00431 if (keydata[0] == 0x04) { //open/close 00432 PT6311.cls(); 00433 PT6311.writeData(all_str); 00434 00435 #if(1) 00436 //test to show all segs 00437 pc.printf("Show all segs\r\n"); 00438 wait(1); 00439 PT6311.cls(); 00440 00441 for (int i=0; i<PT6311_DISPLAY_MEM; i++) { 00442 for (int bit=0; bit<8; bit++) { 00443 PT6311.cls(); 00444 00445 bits = 0x01 << bit; 00446 PT6311.writeData(i, bits); 00447 00448 pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits); 00449 // wait(0.5); 00450 cmd = pc.getc(); // wait for key 00451 } 00452 } 00453 pc.printf("Show all segs done\r\n"); 00454 #endif 00455 00456 } 00457 00458 } //if Key 00459 00460 00461 // Check and read switch data 00462 switchdata = PT6311.getSwitches(); 00463 00464 if (switchdata != 0) { 00465 pc.printf("Switchdata = 0x%02x\r\n", switchdata); 00466 00467 if (switchdata == PT6311_SW1) { //S1 00468 PT6311.cls(); 00469 PT6311.writeData(all_str); 00470 } 00471 00472 if (switchdata == PT6311_SW2) { //S2 00473 PT6311.cls(); 00474 PT6311.writeData(cls_str); 00475 } 00476 00477 if (switchdata == PT6311_SW3) { //S3 00478 PT6311.cls(); 00479 PT6311.writeData(all_str); 00480 } 00481 00482 PT6311.setLED(switchdata); //write LEDs in same pattern 00483 } //if Switch 00484 00485 00486 myled = !myled; 00487 wait(0.3); 00488 } //while 00489 } 00490 #endif
Generated on Sun Jul 17 2022 03:27:00 by
1.7.2
PT6311 VFD driver (192 segm max), Keyboard scan (48 keys max)