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 PT6318 Test program, for Princeton PT6318 VFD controller 00002 * Copyright (c) 2016, v01: WH, Initial version, KUH8300 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 "PT6318.h" 00024 00025 // Select one of the testboards for Princeton PT6318 VFD controller 00026 00027 #if (KUH8300_TEST == 1) 00028 // KUH8300 PT6318 Test 00029 #include "mbed.h" 00030 #include "PT6318.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 KUH8300 is 24 bytes (8 Grids @ 20 Segments) 00038 PT6318::DisplayData_t all_str = {0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, \ 00039 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F }; 00040 00041 PT6318::DisplayData_t cls_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00042 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00 }; 00043 00044 // KeyData_t size is 6 bytes 00045 PT6318::KeyData_t keydata; 00046 00047 //PT6318_KUH8300 declaration, Setting 8 Grids @ 20 Segments 00048 PT6318_KUH8300 KUH8300(p5,p6,p7, p8); 00049 00050 char cmd, bits; 00051 int main() { 00052 00053 pc.printf("Hello World\r\n"); // 00054 00055 KUH8300.cls(); 00056 KUH8300.writeData(all_str); 00057 wait(4); 00058 KUH8300.setBrightness(PT6318_BRT3); 00059 wait(1); 00060 KUH8300.setBrightness(PT6318_BRT0); 00061 wait(1); 00062 KUH8300.setBrightness(PT6318_BRT7); 00063 00064 while (1) { 00065 00066 // Check and read keydata 00067 if (KUH8300.getKeys(&keydata)) { 00068 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]); 00069 00070 if (keydata[0] == 0x01) { //up 00071 KUH8300.cls(); 00072 KUH8300.writeData(all_str); 00073 } 00074 00075 if (keydata[0] == 0x02) { //pause 00076 KUH8300.cls(); 00077 KUH8300.writeData(cls_str); 00078 #if(1) 00079 //test to show all segs 00080 pc.printf("Show all segs\r\n"); 00081 wait(1); 00082 KUH8300.cls(); 00083 00084 for (int i=0; i<PT6318_DISPLAY_MEM; i++) { 00085 for (int bit=0; bit<8; bit++) { 00086 KUH8300.cls(); 00087 00088 bits = 0x01 << bit; 00089 KUH8300.writeData(bits, i); 00090 00091 pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits); 00092 // wait(0.5); 00093 cmd = pc.getc(); // wait for key 00094 } 00095 } 00096 pc.printf("Show all segs done\r\n"); 00097 #endif 00098 } 00099 00100 if (keydata[0] == 0x04) { //play 00101 00102 #if(0) 00103 //test to show all digits (base is 10) 00104 pc.printf("Show all digits\r\n"); 00105 wait(1); 00106 KUH8300.cls(); 00107 00108 for (int i=0; i<KUH8300_NR_DIGITS; i++) { 00109 00110 for (int cnt=0; cnt<10; cnt++) { 00111 KUH8300.locate(i); 00112 KUH8300.printf("%0d", cnt); 00113 00114 // wait(0.5); 00115 cmd = pc.getc(); // wait for key 00116 } 00117 } 00118 pc.printf("Show all digits done\r\n"); 00119 #endif 00120 00121 #if(1) 00122 //test to show all digits (base is 0x10) 00123 pc.printf("Show all digits\r\n"); 00124 wait(1); 00125 00126 KUH8300.cls(); 00127 KUH8300.printf("%d", 0); 00128 cmd = pc.getc(); // wait for key 00129 00130 KUH8300.cls(); 00131 KUH8300.printf("%3.4f", 12.3456); 00132 cmd = pc.getc(); // wait for key 00133 00134 KUH8300.cls(); 00135 KUH8300.printf("%d", 123456); 00136 cmd = pc.getc(); // wait for key 00137 00138 KUH8300.cls(); 00139 KUH8300.printf("%08x", 0x0123ABCD); //Note this value needs 64bits 00140 cmd = pc.getc(); // wait for key 00141 00142 for (int i=0; i<KUH8300_NR_DIGITS; i++) { 00143 00144 for (int cnt=0; cnt<0x10; cnt++) { 00145 KUH8300.locate(i); 00146 KUH8300.printf("%0x", cnt); 00147 // wait(0.5); 00148 cmd = pc.getc(); // wait for key 00149 } 00150 } 00151 pc.printf("Show all digits done\r\n"); 00152 #endif 00153 00154 } 00155 00156 if (keydata[0] == 0x08) { //open 00157 00158 #if(1) 00159 //test to show all alpha chars 00160 pc.printf("Show all alpha chars\r\n"); 00161 wait(1); 00162 KUH8300.cls(); 00163 00164 for (int i=0; i<26; i++) { 00165 KUH8300.printf("%c", char(i + 'A')); 00166 // KUH8300.printf("%c", char(i + 'a')); 00167 wait(0.25); 00168 } 00169 pc.printf("Show all alpha chars done\r\n"); 00170 #endif 00171 00172 #if(0) 00173 //test to show all chars 00174 pc.printf("Show all chars\r\n"); 00175 wait(1); 00176 KUH8300.cls(); 00177 00178 for (int i=FONT_16S_START; i<FONT_16S_END; i++) { 00179 KUH8300.printf("%c", char(i)); 00180 // wait(0.25); 00181 cmd = pc.getc(); // wait for key 00182 } 00183 pc.printf("Show all chars done\r\n"); 00184 #endif 00185 } 00186 00187 if (keydata[0] == 0x10) { //down 00188 #if(0) 00189 //wheel 00190 for(int cnt=0;cnt<10;cnt++) { 00191 for(int idx=0;idx<8;idx++) { 00192 KUH8300.setUDC(0, WHEEL_ANI[idx]); 00193 KUH8300.locate(0); 00194 KUH8300.printf("%c%c%c%c%c%c%c%c",(char)0,(char)0, (char)0,(char)0, (char)0,(char)0, (char)0,(char)0); 00195 00196 wait(0.1); 00197 } 00198 } 00199 #endif 00200 } 00201 00202 if (keydata[0] == 0x20) { //title 00203 KUH8300.cls(); 00204 // 01234567 00205 KUH8300.printf("Hi mbed"); 00206 } 00207 00208 00209 if (keydata[0] == 0x40) { //menu 00210 00211 #if(1) 00212 //test to show all icons 00213 pc.printf("Show all icons\r\n"); 00214 wait(1); 00215 KUH8300.cls(true); // Also clear all Icons 00216 wait(1); 00217 00218 float delay=0.1; 00219 KUH8300.setIcon(PT6318_KUH8300::CAM); wait(delay); 00220 KUH8300.setIcon(PT6318_KUH8300::DIG); wait(delay); 00221 KUH8300.setIcon(PT6318_KUH8300::MONO); wait(delay); 00222 KUH8300.setIcon(PT6318_KUH8300::PRG); wait(delay); 00223 KUH8300.setIcon(PT6318_KUH8300::DTS); wait(delay); 00224 KUH8300.setIcon(PT6318_KUH8300::MEM); wait(delay); 00225 KUH8300.setIcon(PT6318_KUH8300::KHZ); wait(delay); 00226 KUH8300.setIcon(PT6318_KUH8300::STR); wait(delay); 00227 KUH8300.setIcon(PT6318_KUH8300::MHZ); wait(delay); 00228 00229 KUH8300.setIcon(PT6318_KUH8300::KEY); wait(delay); 00230 KUH8300.setIcon(PT6318_KUH8300::ALL); wait(delay); 00231 KUH8300.setIcon(PT6318_KUH8300::DP6); wait(delay); 00232 KUH8300.setIcon(PT6318_KUH8300::COL6); wait(delay); 00233 00234 KUH8300.setIcon(PT6318_KUH8300::ARW); wait(delay); 00235 KUH8300.setIcon(PT6318_KUH8300::A_); wait(delay); 00236 KUH8300.setIcon(PT6318_KUH8300::B_); wait(delay); 00237 KUH8300.setIcon(PT6318_KUH8300::CD4A); wait(delay); 00238 00239 KUH8300.setIcon(PT6318_KUH8300::CHP); wait(delay); 00240 KUH8300.setIcon(PT6318_KUH8300::N3); wait(delay); 00241 KUH8300.setIcon(PT6318_KUH8300::L3); wait(delay); 00242 KUH8300.setIcon(PT6318_KUH8300::HK3); wait(delay); 00243 00244 KUH8300.setIcon(PT6318_KUH8300::TTL); wait(delay); 00245 KUH8300.setIcon(PT6318_KUH8300::JM1); wait(delay); 00246 KUH8300.setIcon(PT6318_KUH8300::HK2); wait(delay); 00247 00248 KUH8300.setIcon(PT6318_KUH8300::PSE); wait(delay); 00249 KUH8300.setIcon(PT6318_KUH8300::PLY); wait(delay); 00250 KUH8300.setIcon(PT6318_KUH8300::PBC); wait(delay); 00251 KUH8300.setIcon(PT6318_KUH8300::DVD); wait(delay); 00252 KUH8300.setIcon(PT6318_KUH8300::CD); wait(delay); 00253 KUH8300.setIcon(PT6318_KUH8300::V); wait(delay); 00254 KUH8300.setIcon(PT6318_KUH8300::S); wait(delay); 00255 00256 wait(delay); 00257 00258 KUH8300.clrIcon(PT6318_KUH8300::CAM); wait(delay); 00259 KUH8300.clrIcon(PT6318_KUH8300::DIG); wait(delay); 00260 KUH8300.clrIcon(PT6318_KUH8300::MONO); wait(delay); 00261 KUH8300.clrIcon(PT6318_KUH8300::PRG); wait(delay); 00262 KUH8300.clrIcon(PT6318_KUH8300::DTS); wait(delay); 00263 KUH8300.clrIcon(PT6318_KUH8300::MEM); wait(delay); 00264 KUH8300.clrIcon(PT6318_KUH8300::KHZ); wait(delay); 00265 KUH8300.clrIcon(PT6318_KUH8300::STR); wait(delay); 00266 KUH8300.clrIcon(PT6318_KUH8300::MHZ); wait(delay); 00267 00268 KUH8300.clrIcon(PT6318_KUH8300::KEY); wait(delay); 00269 KUH8300.clrIcon(PT6318_KUH8300::ALL); wait(delay); 00270 KUH8300.clrIcon(PT6318_KUH8300::DP6); wait(delay); 00271 KUH8300.clrIcon(PT6318_KUH8300::COL6); wait(delay); 00272 00273 KUH8300.clrIcon(PT6318_KUH8300::ARW); wait(delay); 00274 KUH8300.clrIcon(PT6318_KUH8300::A_); wait(delay); 00275 KUH8300.clrIcon(PT6318_KUH8300::B_); wait(delay); 00276 KUH8300.clrIcon(PT6318_KUH8300::CD4A); wait(delay); 00277 00278 KUH8300.clrIcon(PT6318_KUH8300::CHP); wait(delay); 00279 KUH8300.clrIcon(PT6318_KUH8300::N3); wait(delay); 00280 KUH8300.clrIcon(PT6318_KUH8300::L3); wait(delay); 00281 KUH8300.clrIcon(PT6318_KUH8300::HK3); wait(delay); 00282 00283 KUH8300.clrIcon(PT6318_KUH8300::TTL); wait(delay); 00284 KUH8300.clrIcon(PT6318_KUH8300::JM1); wait(delay); 00285 KUH8300.clrIcon(PT6318_KUH8300::HK2); wait(delay); 00286 00287 KUH8300.clrIcon(PT6318_KUH8300::PSE); wait(delay); 00288 KUH8300.clrIcon(PT6318_KUH8300::PLY); wait(delay); 00289 KUH8300.clrIcon(PT6318_KUH8300::PBC); wait(delay); 00290 KUH8300.clrIcon(PT6318_KUH8300::DVD); wait(delay); 00291 KUH8300.clrIcon(PT6318_KUH8300::CD); wait(delay); 00292 KUH8300.clrIcon(PT6318_KUH8300::V); wait(delay); 00293 KUH8300.clrIcon(PT6318_KUH8300::S); wait(delay); 00294 00295 wait(1); 00296 KUH8300.cls(); // clear all, preserve Icons 00297 pc.printf("Show all icons done\r\n"); 00298 #endif 00299 } 00300 00301 if (keydata[0] == 0x80) { //stop 00302 //write LEDs off 00303 // KUH8300.setLED(0x07); 00304 KUH8300.setLED(PT6318_LED1 | PT6318_LED2 | PT6318_LED3 | PT6318_LED4 | PT6318_LED5); 00305 } 00306 00307 if (keydata[1] == 0x01) { //left 00308 //write LEDs on 00309 KUH8300.setLED(0x00); 00310 } 00311 00312 if (keydata[1] == 0x02) { //pwr 00313 } 00314 00315 if (keydata[1] == 0x04) { //next 00316 } 00317 00318 } //if Key 00319 00320 myled = !myled; 00321 wait(0.3); 00322 } //while 00323 } 00324 #endif 00325 00326 00327 #if(PT6318_TEST == 1) 00328 // Direct PT6318 Test 00329 #include "mbed.h" 00330 #include "PT6318.h" 00331 00332 Serial pc(USBTX, USBRX); 00333 DigitalOut myled(LED1); 00334 00335 // DisplayData_t size is 24 bytes (8 digits @ max 20 segments) ... 48 bytes (16 digits @ max 12 segments) 00336 // DisplayData_t size default is 48 bytes (16 Grids @ 12 Segments) 00337 PT6318::DisplayData_t all_str = {0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, \ 00338 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, \ 00339 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, \ 00340 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F, 0xFF,0xFF,0x0F}; 00341 00342 PT6318::DisplayData_t cls_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00343 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00344 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \ 00345 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00}; 00346 00347 // KeyData_t size is 6 bytes 00348 PT6318::KeyData_t keydata; 00349 00350 // Switchdata is 1 byte 00351 char switchdata; 00352 00353 PT6318 PT6318(p5,p6,p7, p8); 00354 //PT6318 PT6318(p5,p6,p7, p8, PT6318::Grid16_Seg12); 00355 00356 char cmd, bits; 00357 int main() { 00358 00359 pc.printf("Hello World\r\n"); // 00360 00361 PT6318.cls(); 00362 PT6318.writeData(all_str); 00363 wait(4); 00364 PT6318.setBrightness(PT6318_BRT3); 00365 wait(1); 00366 PT6318.setBrightness(PT6318_BRT0); 00367 wait(1); 00368 PT6318.setBrightness(PT6318_BRT7); 00369 00370 while (1) { 00371 00372 // Check and read keydata 00373 if (PT6318.getKeys(&keydata)) { 00374 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[4]); 00375 00376 if (keydata[0] == 0x01) { //up 00377 PT6318.cls(); 00378 PT6318.writeData(all_str); 00379 } 00380 00381 if (keydata[0] == 0x02) { //pause 00382 PT6318.cls(); 00383 PT6318.writeData(cls_str); 00384 } 00385 00386 if (keydata[0] == 0x04) { //play 00387 PT6318.cls(); 00388 PT6318.writeData(all_str); 00389 00390 #if(1) 00391 //test to show all segs 00392 pc.printf("Show all segs\r\n"); 00393 wait(1); 00394 PT6318.cls(); 00395 00396 for (int i=0; i<PT6318_DISPLAY_MEM; i++) { 00397 for (int bit=0; bit<8; bit++) { 00398 PT6318.cls(); 00399 00400 bits = 0x01 << bit; 00401 PT6318.writeData(bits, i); 00402 00403 pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits); 00404 // wait(0.5); 00405 cmd = pc.getc(); // wait for key 00406 } 00407 } 00408 pc.printf("Show all segs done\r\n"); 00409 #endif 00410 00411 } 00412 00413 } //if Key 00414 00415 myled = !myled; 00416 wait(0.3); 00417 } //while 00418 } 00419 #endif
Generated on Tue Jul 26 2022 08:47:11 by
1.7.2
PT6318 VFD driver (192 segm max), Keyboard scan (48 max).