very simple sample code for PCA9956A (24 channel current control LED driver)
Fork of PCA9955_simple by
main.cpp@1:2a3b314f4996, 2013-10-07 (annotated)
- Committer:
- nxp_ip
- Date:
- Mon Oct 07 04:03:57 2013 +0000
- Revision:
- 1:2a3b314f4996
- Parent:
- 0:3afedead559b
modified to control PCA9956A (24 channel constant current LED controller)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nxp_ip | 0:3afedead559b | 1 | /* |
nxp_ip | 0:3afedead559b | 2 | * very simple sample code for PCA9955 LPD driver |
nxp_ip | 0:3afedead559b | 3 | * |
nxp_ip | 0:3afedead559b | 4 | * 10-Oct-2012 |
nxp_ip | 0:3afedead559b | 5 | * NXP Semiconductors - Interface Products |
nxp_ip | 0:3afedead559b | 6 | */ |
nxp_ip | 0:3afedead559b | 7 | |
nxp_ip | 0:3afedead559b | 8 | #include "mbed.h" |
nxp_ip | 0:3afedead559b | 9 | |
nxp_ip | 1:2a3b314f4996 | 10 | #define PCA9956A_ADDRESS 0x02 |
nxp_ip | 1:2a3b314f4996 | 11 | #define IREF_INIT 0x10 |
nxp_ip | 0:3afedead559b | 12 | |
nxp_ip | 0:3afedead559b | 13 | I2C i2c( p28, p27 ); |
nxp_ip | 0:3afedead559b | 14 | |
nxp_ip | 0:3afedead559b | 15 | char init_array[] = { |
nxp_ip | 0:3afedead559b | 16 | 0x80, // Command |
nxp_ip | 0:3afedead559b | 17 | 0x00, 0x05, // MODE1, MODE2 |
nxp_ip | 1:2a3b314f4996 | 18 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // LEDOUT[3:0] |
nxp_ip | 0:3afedead559b | 19 | 0x80, 0x00, // GRPPWM, GRPFREQ |
nxp_ip | 0:3afedead559b | 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // PWM[7:0] |
nxp_ip | 0:3afedead559b | 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // PWM[15:8] |
nxp_ip | 1:2a3b314f4996 | 22 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // PWM[23:16] |
nxp_ip | 1:2a3b314f4996 | 23 | IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[7:0] |
nxp_ip | 1:2a3b314f4996 | 24 | IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[15:8] |
nxp_ip | 1:2a3b314f4996 | 25 | IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[23:16] |
nxp_ip | 0:3afedead559b | 26 | 0x08 // OFFSET: 1uS offsets |
nxp_ip | 0:3afedead559b | 27 | }; |
nxp_ip | 0:3afedead559b | 28 | |
nxp_ip | 0:3afedead559b | 29 | |
nxp_ip | 0:3afedead559b | 30 | int main() |
nxp_ip | 0:3afedead559b | 31 | { |
nxp_ip | 0:3afedead559b | 32 | char data[ 2 ]; |
nxp_ip | 0:3afedead559b | 33 | int i = 0; |
nxp_ip | 0:3afedead559b | 34 | |
nxp_ip | 1:2a3b314f4996 | 35 | i2c.write( PCA9956A_ADDRESS, init_array, sizeof( init_array ) ); |
nxp_ip | 0:3afedead559b | 36 | |
nxp_ip | 0:3afedead559b | 37 | while ( 1 ) { |
nxp_ip | 1:2a3b314f4996 | 38 | if ( !(i % (256 * 24)) ) { |
nxp_ip | 1:2a3b314f4996 | 39 | data[ 0 ] = 0x3F; |
nxp_ip | 0:3afedead559b | 40 | data[ 1 ] = 0x00; |
nxp_ip | 1:2a3b314f4996 | 41 | i2c.write( PCA9956A_ADDRESS, data, 2 ); |
nxp_ip | 0:3afedead559b | 42 | |
nxp_ip | 0:3afedead559b | 43 | } else { |
nxp_ip | 1:2a3b314f4996 | 44 | data[ 0 ] = 0x0A + ((i >> 8) % 24); |
nxp_ip | 0:3afedead559b | 45 | data[ 1 ] = i & 0xFF; |
nxp_ip | 1:2a3b314f4996 | 46 | i2c.write( PCA9956A_ADDRESS, data, 2 ); |
nxp_ip | 0:3afedead559b | 47 | } |
nxp_ip | 0:3afedead559b | 48 | wait_ms( 1 ); |
nxp_ip | 0:3afedead559b | 49 | i++; |
nxp_ip | 0:3afedead559b | 50 | } |
nxp_ip | 0:3afedead559b | 51 | } |
nxp_ip | 0:3afedead559b | 52 |