Wim Huiskamp
/
mbed_PT6961
Test program for Princeton PT6961 LED controller library.
See here for more information.
main.cpp
- Committer:
- wim
- Date:
- 2015-08-23
- Revision:
- 0:c77f1ad8d993
- Child:
- 1:59c864633347
File content as of revision 0:c77f1ad8d993:
/* mbed PT6961 Test program, for Princeton PT6961 LED controller * Copyright (c) 2015, v01: WH, Initial version * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "mbed.h" #include "PT6961.h" #if(1) Serial pc(USBTX, USBRX); DigitalOut myled(LED1); // DisplayData_t size is 12 bytes (6 digits max 12 segments) OR 14 bytes (7 digits at max 11 segments) PT6961::DisplayData_t mbed_str = {0xDA,0x00, 0x7C,0x00, 0x3C,0x01, 0xF6,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00}; PT6961::DisplayData_t all_str = {0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F}; PT6961::DisplayData_t bye_str = {0x7C,0x00, 0xEC,0x00, 0x3C,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00}; PT6961::DisplayData_t hello_str = {0xDC,0x00, 0x3C,0x01, 0x38,0x00, 0x38,0x00, 0xF8,0x01, 0x00,0x00, 0x00,0x00}; // KeyData_t size is 5 bytes PT6961::KeyData_t keydata; // PT6191 declaration, Default setting 7 Digits, 11 Segments PT6961 pt6961(p5,p6,p7, p8); int main() { // char c; // int data; pc.printf("Hello World\r\n"); // pt6961.cls(); pt6961.writeData(all_str); wait(4); pt6961.setBrightness(PT6961_BRT3); pt6961.writeData(mbed_str); wait(1); pt6961.setBrightness(PT6961_BRT0); wait(1); pt6961.setBrightness(PT6961_BRT3); while (1) { // Check and read keydata if (pt6961.readKeys(&keydata)) { // pc.printf("Key\r\n"); // pc.printf("Keydata 0..4 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4]); if (keydata[0] == 0x10) { //sw2 pt6961.cls(); pt6961.writeData(all_str); } if (keydata[0] == 0x02) { //sw8 pt6961.cls(); pt6961.writeData(hello_str); } if (keydata[0] == 0x20) { //sw6 pt6961.cls(); pt6961.writeData(mbed_str); } if (keydata[1] == 0x02) { //sw4 pt6961.cls(); pt6961.writeData(bye_str); } } //if myled = !myled; wait(0.3); } //while } #else Serial pc(USBTX, USBRX); DigitalOut myled(LED1); SPI spi(p5,p6,p7); DigitalOut cs(p8); int flip(char data) { char value=0; if ((data & 0x01) == 0x01) {value |= 0x80;} ; if ((data & 0x02) == 0x02) {value |= 0x40;} ; if ((data & 0x04) == 0x04) {value |= 0x20;} ; if ((data & 0x08) == 0x08) {value |= 0x10;} ; if ((data & 0x10) == 0x10) {value |= 0x08;} ; if ((data & 0x20) == 0x20) {value |= 0x04;} ; if ((data & 0x40) == 0x40) {value |= 0x02;} ; if ((data & 0x80) == 0x80) {value |= 0x01;} ; return value; } void fill () { cs=0; wait_us(1); spi.write(flip(0xC0)); // address set cmd, 0 spi.write(flip(0xFF)); // data spi.write(flip(0x07)); // data spi.write(flip(0xFF)); // data spi.write(flip(0x07)); // data spi.write(flip(0xFF)); // data spi.write(flip(0x07)); // data spi.write(flip(0xFF)); // data spi.write(flip(0x07)); // data spi.write(flip(0xFF)); // data spi.write(flip(0x07)); // data spi.write(flip(0xFF)); // data spi.write(flip(0x07)); // data spi.write(flip(0xFF)); // data spi.write(flip(0x07)); // data wait_us(1); cs=1; } void clear () { cs=0; wait_us(1); spi.write(flip(0xC0)); // address set cmd, 0 spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data wait_us(1); cs=1; } int main() { char c; int data; pc.printf("Hello World\r\n"); // cs=1; spi.format(8,3); spi.frequency(100000); cs=0; wait_us(1); spi.write(flip(0x03)); // display mode cmd, 7 digits, 11 segments wait_us(1); cs=1; wait_us(50); cs=0; wait_us(1); spi.write(flip(0x40)); // data set cmd, normal mode, auto incr, write data wait_us(1); cs=1; wait_us(50); cs=0; wait_us(1); spi.write(flip(0x8B)); // display control cmd, display On, 10/16 pwm wait_us(1); cs=1; wait_us(50); fill(); pc.printf("Press key\r\n"); // c=pc.getc(); clear(); #if(0) for (int digit=0; digit<7; digit++) { for (int seg=0; seg<12; seg++) { data = 1 << seg; cs=0; wait_us(1); spi.write(flip(0xC0 + (digit << 1))); // address set cmd, 0 spi.write(flip( data & 0xFF)); // data spi.write(flip((data >> 8) & 0x07)); // data wait_us(1); cs=1; //wait(0.5); pc.printf("Dig=%d, Seg=%d, Press key\r\n", digit, seg); // c=pc.getc(); } //seg cs=0; wait_us(1); spi.write(flip(0xC0 + digit)); // address set cmd, 0 spi.write(flip(0x00)); // data spi.write(flip(0x00)); // data wait_us(1); cs=1; } //dig #endif const char mbed[] = {0xDA,0x00, 0x7C,0x00, 0x3C,0x01, 0xF6,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00}; cs=0; wait_us(1); spi.write(flip(0xC0)); // address set cmd, 0 for (int dig=0; dig<7; dig++) { spi.write(flip(mbed[(dig<<1)])); // data spi.write(flip(mbed[(dig<<1) + 1])); // data } wait_us(1); cs=1; while(1) { myled = 1; wait(0.5); myled = 0; wait(0.5); cs=0; wait_us(1); spi.write(flip(0x42)); // data set cmd, normal mode, auto incr, read data data = spi.write(0xFF); // read keys 0 pc.printf("data=0x%02x ", flip(data)); // data = spi.write(0xFF); // read keys 1 pc.printf("data=0x%02x ", flip(data)); // data = spi.write(0xFF); // read keys 2 pc.printf("data=0x%02x ", flip(data)); // data = spi.write(0xFF); // read keys 3 pc.printf("data=0x%02x ", flip(data)); // data = spi.write(0xFF); // read keys 4 pc.printf("data=0x%02x\r\n", flip(data)); // wait_us(1); cs=1; } } #endif