Wim Huiskamp
/
mbed_PT6961
Test program for Princeton PT6961 LED controller library.
See here for more information.
Diff: main.cpp
- Revision:
- 1:59c864633347
- Parent:
- 0:c77f1ad8d993
- Child:
- 2:3bc72b8f5481
diff -r c77f1ad8d993 -r 59c864633347 main.cpp --- a/main.cpp Sun Aug 23 14:40:33 2015 +0000 +++ b/main.cpp Sun Aug 23 14:42:54 2015 +0000 @@ -22,9 +22,7 @@ #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) @@ -40,8 +38,6 @@ PT6961 pt6961(p5,p6,p7, p8); int main() { -// char c; -// int data; pc.printf("Hello World\r\n"); // @@ -59,7 +55,6 @@ // 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 @@ -88,194 +83,3 @@ 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 \ No newline at end of file