Application Notes

AN10315
LED dimmer demoboard
Rev. 01 — 7 January 2005
Application note
Document information
Info
Content
Keywords
I2C, LED, RGB, LED controller, LED dimmer, LED blinker, color mixing,
RGB mixing, RGB LED, White LED, Back lighting, GPIO, I/O expander,
Keypad control, LED dimmer evaluation board, I2C evaluation board,
PCA9531, PCA9533, PCA9555, PCA9564, P89LV51RD2
Abstract
8-bit tri-color LED demonstration board description, features and operation
modes are discussed. Source code in C language, containing
communication routines between an 80C51-core microcontroller +
PCA9564 and the I2C slave devices is provided: keypad control, LED
control / color mixing.
AN10315
Philips Semiconductors
LED dimmer demoboard
Revision history
Rev
Date
Description
01
20050107
Application note (9397 750 14062); initial version.
Contact information
For additional information, please visit: http://www.semiconductors.philips.com
For sales office addresses, please send an email to: [email protected]
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
2 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
1. Introduction
The LED Dimmer Demoboard demonstrates the capability of the I2C-bus to control a
keypad and perform Red/Green/Blue LED lighting color mixing operations.
The demoboard is a stand alone solution using the Philips P89LV51RD2 microcontroller
interfacing with a Philips PCA9564 I2C-bus controller to generate the different I2C
commands. The microcontroller comes programmed with a default firmware that is
explained in this Application Note. If additional programming is required, the user must
remove the microcontroller from its socket and use an external programmer.
The demoboard is composed by 2 sub-boards that are directly connected to each other
without the need for external cables:
• The Keypad Control Card contains the microcontroller, the keypad with the keypad
controller and the power supply/regulator module (external 9 V power supply or 9 V
battery).
• The LED Control Card contains all the LEDs and the devices controlling them.
Each card can be used separately and can be connected to other companion cards.
I2C slave devices used on the demoboard are the following:
• Philips PCA9555PW, 16-bit GPIO functioning as a 16-key keypad controller.
• Philips PCA9531PW and PCA9533DP/01, 8-bit and 4-bit LED dimmer for LED control
and color mixing (Red, Green and White LEDs, RGB LEDs).
2. Ordering information
The complete demoboard kit consists of:
• The keypad control card
• The LED display card
Kit can be obtained through your local Philips Semiconductors Sales organization or via
e-mail to [email protected]
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
3 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
3. Technical information—hardware
3.1 Block diagram
Keypad Control Card
16-key KEYPAD
PCA
9555
RESET
LED Control Card
/INT
/RESET
SDA
Data /
Control
P89LV51
RD2
SCL
`
PCA
9564
3.3 V
Regulator
PCA
9533
PCA
9531
PCA
9531
PCA
9531
PCA
9531
9 V battery
or
9 V power supply
Misc/Status LEDs
- 4 Red LEDs
- 1 Green LED
- 1 Blue LED
- 1 RG LED
4 White LEDs
8 RGB LEDs
Fig 1. Block diagram
3.2 I2C-bus device addresses
Table 1:
I2C-bus device addresses
Device type
Description
I2C address (hexadecimal)
P89LV51RD2/PCA9564PW
microcontroller /
I2C-bus controller
User definable when slave
PCA9531PW (Red - RGB LEDs)
8-bit I2C LED dimmer
0xCA
PCA9531PW (Green - RGB LEDs)
8-bit I2C LED dimmer
0xCC
8-bit
I2C
LED dimmer
0xCE
8-bit
I2C
LED dimmer
0xC6
PCA9533DP/01 (White LEDs)
4-bit
I2C
LED dimmer
0xC4
PCA9555
16-bit I2C GPIO
PCA9531PW (Blue - RGB LEDs)
PCA9531PW (Misc/Status LEDs)
9397 750 14062
Application note
0x46
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
4 of 45
Application note
Rev. 01 — 7 January 2005
GND
C6
22 pF
C5
22 pF
3
4
S17
1
2
GND
2
1
P2.0-A8
P2.1-A9
P2.2-A10
P2.3-A11
P2.4-A12
P2.5-A13
P2.6-A14
P2.7-A15
P0.0-AD0
P0.1-AD1
P0.2-AD2
P0.3-AD3
P0.4-AD4
P0.5-AD5
P0.6-AD6
P0.7-AD7
−1
K
9V
GND
+
−
−
+
+
RN1
4.7 kΩ
G1
AB9V
LD1
R7
1 kΩ
GND
R6
1.5 kΩ
1 kΩ
IN OUT
ADJ
IC1
R4
C8
100 nF
11
13
14 INTPCA9555
15
16
17
18
19
WR\
RD\
A0
A1
C7
100 µF
VCC3
PIN18
GND
VSS
PIN10 PCA9564PW
PIN11 WR\
PIN12 RD\
PIN13 CE\
SCL
SDA
PIN19
C1
100 nF
GND
VDD
PIN14 A0
PIN15 A1
RESET\ PIN17 RESET\
PIN16 INT\
INT\
U$2
D0
D1
D2
D3
D4
D5
D6
D7
24
25
26
27
28
29
30
31
PIN1
PIN2
PIN3
PIN4
PIN5
PIN6
PIN7
PIN8
D0
D1
D2
D3
D4
D5
D6
D7
234 56 789
1
PIN20
43
42
41
40
39
38
37
36
SK14
U$4
RXD-P3.0
TXD-P3.1
INT0\-P3.2
21
INT1\-P3.3
XTAL1
Q1
T0-P3.4
11.0592
T1-P3.5
WR\-P36
MHz 20
XTAL2
VSS RD\-P3.7
P89LV51RA2 22
PSEN\
C2
100 nF
GND
44
VCC
T2-P1.0
T2EX-P1.1
ECI-P1.2
CEX0-P1.3
CEX1-P1.4
CEX2-P1.5
CEX3-P1.6
CEX4-P1.7
U$1
35 EA\-VPP
33
ALE-PROG\
10 RST
32
R5
1 kΩ
C4
1 µF
RST
2
3
4
5
6
7
8
9
GND
9397 750 14062
GND2
R1
10 kΩ
GND
JP5 1
2
3
4
JP3 1
2
3
4
JP7 1
2
JP2 1
2
JP6 1
2
JP1 1
2
JP4 1
2
3
4
INTPCA9555
SDA0
SCL0
R2
10 kΩ
GND
RST
INTPCA9555
SCL0
SDA0
VCC3
GND
12 PCA9555PW
U$3 24
VDD IO00 4
23 SDA
IO01 5
6
22
IO02 7
SCL
IO03 8
IO04 9
IO05 10
1 INT\
IO06 11
IO07
IO10 13
IO11 14
IO12 15
21 A0
IO13 16
2 A1
IO14 17
3 A2
IO15 18
IO16 19
20
GND IO17
R3
10 kΩ
C3
100 nF
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
S16
S15
S14
S13
S12
S11
S10
S9
S8
S7
S6
S5
S4
S3
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
S1
S2
1
2
3
4
GND
Philips Semiconductors
AN10315
LED dimmer demoboard
3.3 Schematic
3.3.1 Keypad control card
Fig 2. Keypad control card schematic
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
5 of 45
Application note
9397 750 14062
Rev. 01 — 7 January 2005
VSS
PIN4
GND
PCA24S08DP
SDA
PIN5
WP
PIN7
150
C5
100 n
GND
PCA9531PW
GND
LED0 PIN4
LED1 PIN5
120
120
R13
R15
120
120 R12
R10
120 R9
C4
100 n
U$3
0
SDA
0 R17
PIN14 SCL
PIN13 RESET LED2 PIN6 0 R18
0
R19
LED3 PIN7
0 R20
LED4 PIN9
0 R21
LED5 PIN10
0
PIN3 A2
PIN11 R22
LED6
PIN2 A1
0
R23
PIN1 A0
LED7 PIN12
R24
PIN15
GND
VSS PIN8
GND
/INT
RESET
SCL PIN6
/PROT PIN3
PIN8 V
CC
JP6 1
2
4
74LVC1G04GW
U$4
PCA9531PW
VDD
JP2 1
2
U$6
2
GND
PIN16
JP3 1
2
3
4
VCC
SCL0
SDA0
PIN8
JP5 1
2
3
4
PIN12 LED7
VSS PIN8
PCA9531PW
A2 PIN3
A1 PIN2
A0 PIN1
VSS
JP7 1
2
R35
PIN10 LED5
PIN11 LED6
R8
GND
LED0 PIN4
LED1 PIN5
PIN13 RESET LED2 PIN6 120
R11
LED3 PIN7
LED4 PIN9
120
LED5 PIN10
PIN3 A2
PIN11 R14
LED6
PIN2 A1
120
PIN1 A0
LED7 PIN12
R16
U$2
PIN15
SDA
PIN14 SCL
PCA9531PW
GND
VDD
RESET
VCC
R36
0
150
150 R33
120 R34
R31
GND
LED0 PIN4
LED1 PIN5
PIN16
R32
150
150 R30
PIN18 V
DD
LED0
PIN5 LED1
PIN6
LED2 RESET PIN13
PIN7
LED3
PIN9 LED4
U$5
C2
100 n
GND
PIN15
SDA
SCL PIN14
PIN8
PIN4
PIN4
GND
U$1
SDA
C3
100 n
150 R2
PIN14 SCL
PIN13 RESET LED2 PIN6 150 R1
150
R3
LED3 PIN7
150 R4
LED4 PIN9
150 R5
LED5 PIN10
150
PIN3 A2
PIN11 R6
LED6
PIN2 A1
150
R7
PIN1 A0
LED7 PIN12
PIN15
VSS
150 R29
LED3
LED2
LED1
GND
PCA9533DP
PIN5
PIN3
PIN2
LED0
SDA PIN7
SCL PIN6
GND
C1
100 n
VDD
150
R28
R26
120
R25
120
PIN1
U$7
PIN8 V
DD
R27
120
120
LD8 LD7 LD6 LD5 LD4 LD3 LD2 LD1
PIN16
JP4 1
2
3
4
JP1 1
2
LD9
Philips Semiconductors
AN10315
LED dimmer demoboard
3.3.2 LED control card
LD20
LD19
LD18
LD17
LD16
LD15
LD14
LD13
LD12
LD11
Fig 3. LED control card schematic
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
6 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
3.4 Demoboard (top view)
8 RGB LEDs:
LD13 to LD18
PCA9533
4 White LEDs:
LD1 to LD4
PCA9531
Green
PCA9531
Blue
PCA9531
Red
PCA9531
Misc/Status
Misc/Status LEDs:
LD5 to LD8
Misc/Status LEDs:
LD9, LD11, LD12
PCA9555
Connectors between
the boards
- Power supply
- I2C-bus
- Reset signal
-/Int signal (not used)
P89LV51RD2
RESET pushbutton
Keypad
PCA9564
External 9 V battery
or
External 9 V power supply
Connectors for external
master or slave card
Fig 4. Schematic keypad control card
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
7 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
3.5 RGB color mixing
Red, Green and Blue are the 3 primary colors allowing creating all the other colors by
mixing them together.
The desired color is created by applying the right amount of Red, plus the right amount of
Green plus the right amount of Blue light from the RGB LED.
A 152 Hz frequency voltage is applied to the Red, Green and Blue LED drivers so that the
human eye does not see the ON/OFF cycle (typically frequencies higher than100 Hz are
required).
Varying the duty cycle controls the average current flowing through the LED, thus
controlling the brightness for each color. The human eye sees an average brightness
value since it cannot see the ON/OFF cycle.
The sum of the 3 primary colors at various brightness values will then define the resulting
color: <IRed> + <IGreen> + <IBlue> gives the desired visible color.
Voltage on Red LED driver
<I
Red>
<I
Green
+
Voltage on Green LED driver
>
+
Voltage on Blue LED driver
<I
Blue>
=
Resulting color
Fig 5. Color mixing theory
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
8 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
4. Technical information—how to use the demobord
4.1 Introduction
Firmware in the P89LV51RD2 microcontroller emulates a cell phone application,
programs fun patterns, and controls the brightness of a virtual display. A battery discharge
emulation with a visual charge status can also be performed. The firmware is intended to
show a specific application (i.e., cell phone), but this demoboard can be used for any
application that requires a keypad control and LED lighting/color mixing.
Most of the code, written in C language, has been re-used from the PCA9564 Evaluation
Board (drivers, main interfacing files between the P89LV51RD2 and the PCA9564). Only
the mainloop.c, i2c_routines.c and i2cexprt.h files have been modified to implement the
code specific to the demoboard. For more information about the files different from the
3 mentioned above, refer to the Application Notes AN10149: PCA9564 evaluation board,
and to the PCA9564 Evaluation Board main page at:
http://www.standardproducts.philips.com/support/boards/pca9564/.
The default firmware in the P89LV51RD2 allows the user to:
•
•
•
•
•
Control the 16-key keypad (numbers from 0 to 9 are displayed in binary code)
Control the RGB LEDs and program 3 different colors / display speed
Control the brightness of the white LEDs
Emulate a ‘battery discharge’ application
Enable an ‘Auto Demo Mode’ showing some ‘fun light’ application / RGB mixing
The P89LV51RD2 can be programmed with any user defined firmware. Since the
demoboard does not have any built-in programming feature, the user must then program
the microcontroller with an external programmer.
Default firmware (source files and ‘.hex’ file) can be downloaded from the following link:
http://www.standardproducts.philips.com/support/boards/leddemo/.
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
9 of 45
xxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x xxxxxxxxxxxxxx xxxxxxxxxx xxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx
xxxxx xxxxxx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxx x x
Philips Semiconductors
9397 750 14062
Application note
Power up
or
Reset
PROGRAMMING
MODE
Key F1
pushed?
YES
NO
Key F2
pushed?
NO
LD12
blinking
Key 1
pushed?
YES
EMULATION
MODE
YES
NO
Key 2
pushed?
NO
NO
Key 3
pushed?
YES
YES
Key 4
pushed?
YES
LD5 on
LD6 on
LD7 on
LD8 on
Programming
Fun Pattern 1
Routine
Programming
Fun Pattern 2
Routine
Programming
Fun Pattern 3
Routine
White LED
Control
Routine
LD11
blinking
NO
Rev. 01 — 7 January 2005
NO
NO
Key END
pushed?
YES
NO
Key END
pushed?
YES
LD5 off
NO
Key END
pushed?
YES
LD6 off
NO
Key END
pushed?
YES
LD12 off
4.2 Firmware routines
Dialing Routine
Key END
pushed?
YES
LD7 off
LD8 off
NO
Key 1
pushed?
Battery
Emulation
Routine
Key END
pushed?
YES
Fig 6.
Firmware routines flowchart
NO
Key END
pushed?
YES
LD11 off
YES
Auto Demo
Routine
Only a RESET exits the
Auto Demo Routine
AN10315
NO
Key 4
pushed?
LED dimmer demoboard
10 of 45
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
YES
NO
AN10315
Philips Semiconductors
LED dimmer demoboard
4.3 Dialing routine
4.3.1 How the keypad control works
Keypad control is done using a PCA9555 with its INT signal connected to a GPIO of the
P89LV51RD2 microcontroller. The 16 keys of the keypad are simply connected to the
16 GPIOs of the PCA9555 and to the ground, without any other external components
since internal 100 kΩ pull-ups are provided by the PCA9555.
Each time one (or more) key is pressed, the PCA9555 generates an Interrupt that is
detected by the P89LV51RD2. A read of the input port registers of the PCA9555 is then
initiated in order to determine which key(s) has (have) been pushed. Two modes are
possible:
1. One time only pushed detection: only one read is performed.
2. Continuous push detection: the P89LV51RD2 keeps polling the input port registers as
long as the register content is different from 0xFF (meaning that at least one key is
pushed).
Code is described in the function called ‘GPIO_Interrupt_Handler()’ described in Section
5.3 “I2C_Routines.c”.
When an Interrupt is detected, the P89LV51RD2 initiates 2 input port register readings. A
delay between the 2 readings allows:
• potential switch bounces to be filtered.
• Detection of a one time or continuous push detection.
The delay is long enough so that if 2 readings are identical, it assumes that a continuous
push is applied to the pushbutton. If the second reading is different, it assumes that the
user released the pushbutton. The delay is also short enough so that a push in another
key is not masked.
A variable called ‘GPIO_Polling_On’ enable/disables the polling option thus making the
scan suitable for a ‘one shot’ detection.
Continuous push detection is enabled when set to ‘1’.
4.3.2 Keypad mapping with the PCA9555 I/Os
Table 2:
PCA9555 Input port Register 0
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
8
7
6
5
4
3
2
1
Table 3:
PCA9555 Input port Register 1
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
F2
F1
END
SND
#
*
0
9
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
11 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
4.3.3 Application: cell phone type keyboard—Dialing routine
The firmware in the P89LV51RD2 targets a cell phone type application where the keypad
is used to dial phone numbers and access to a programming mode in order to access the
RGB and White LEDs.
When dialing a phone number (keys 0 to 9 are used), the pushed key value is displayed
using its binary code with LD5 (MSB) to LD8 (LSB).
Table 4:
KEY
Binary code for numbers from 0 to 9
LD5
LD6
LD7
LD8
0
♦
1
2
♦
3
♦
4
♦
5
♦
6
♦
♦
7
♦
♦
8
♦
9
♦
♦
♦
♦
♦
Note that a maximum of 10 keys can be pushed when dialing a phone number. If more
than 10 keys are entered, LD5 to LD8 will start flashing at 1 Hz / 50 % duty cycle to let the
user know that the maximum number has been reached.
After dialing the number, the user has to push the SND key to send the number or the
END key to end the call. LD5 to LD8 become off when those 2 keys are pushed.
When SND is pushed, all eight RGB LEDs will blink at 1 Hz / 50 % duty cycle with either a
red color (visual emulating a ‘busy’ line) or a green color (visual emulating a ‘non busy’
line).
Pushing END ends the call and the RGB LEDs (Red or Green) are off.
Remark: To dial a number, the user needs to be sure that the programming mode is not
enabled (LD12 is not blinking) or the emulation mode is not enabled (LD11 is not blinking).
If the demoboard is either in the programming mode or in the emulation mode, the END
key must be pushed one or two times (depending which branch of the firmware is active)
until LD11 and LD12 are off. A reset can also be performed to reach the dialing routine.
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
12 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
4.4 Programming mode
The programming mode shows capabilities of the PCA9533 and the PCA9531 LED
dimmers to control LEDs for:
• RGB (Red / Green / Blue) color mixing
• White LED brightness control
Power supply used for both I2C devices and LEDs is equal to 3.3 V. Applications requiring
LEDs connected to 5 V or even higher power supply are also possible. Power supply
values higher than 5 V require the use of external FET drivers. More information can be
found in the Application Notes AN264 - I2C devices for LED display control.
• Programming mode is entered by pushing key F1. LD12 (Blue LED) starts then
blinking to indicate that the programming mode is active.
• Keys 1, 2 and 3 select the 3 programmable ‘fun patterns’. See Section 4.4.1
“Programming fun patterns routine—RGB color mixing” for more detail.
• Key 4 selects the white LED’s control. See Section 4.4.3 “White LED control routine”
for more detail.
LD5 to LD8 let the user know which programming is active.
Table 5:
Active programming
Programming
Key to be pushed
LD5
LD6
LD7
LD8
Fun Pattern 1
1
ON
OFF
OFF
OFF
Fun Pattern 2
2
OFF
ON
OFF
OFF
Fun Pattern 3
3
OFF
OFF
ON
OFF
White LED control
4
OFF
OFF
OFF
ON
• Pushing Key END once leaves the current programming that was performed (fun
pattern 1, 2 or 3, white LED control). The corresponding LED (LD5 to LD8) is then off.
• Pushing Key END one more time leaves the programming mode. LD12 stops blinking.
4.4.1 Programming fun patterns routine—RGB color mixing
Three ‘fun patterns’ can be programmed when using the default firmware. For each ‘fun
pattern’, the user can select:
• The resulting color: selection of amount or Red, Green and Blue.
• The rotating speed:
LD13 →LD14 →LD15 →LD16 →LD17 →LD18 →LD19 →LD20 →LD13
For each pattern, primary colors (Red, Green, Blue) can be added (+) or removed (-) and
the rotating speed can be increased (+) or decreased (-) by pushing the corresponding
key in the keypad.
•
•
•
•
•
Key 2: Red (-)
Key 3: Red (+)
Key 5: Green (-)
Key 6: Green (+)
Key 8: Blue (-)
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
13 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
• Key 9: Blue (+)
• Key 0: Speed (-)
• Key #: Speed (+)
Remark: Those keys have been programmed to detect a continuous push applied to
them. When pushed continuously, (+) or (-) action is performed continuously until max
(0xFF) or min (0x00) in the PWM registers.
Remark: Keys in this routine have been programmed to detect a continuous push applied
to them. When pushed continuously, (+) or (-) action is performed continuously until max
(0xFF) or min (0x00) in the PWM registers.
4.4.2 PCA953x mapping with the LEDs
Table 6:
PCA933 (White LEDs) - LS0
Bit 7
Bit 6
Bit 5
LD4
Table 7:
Bit 4
Bit 3
LD3
Bit 2
Bit 1
Bit 0
LD2
LD1
PCA931 (Misc/Status LEDs) - LS0
Bit 7
Bit 6
Bit 5
LD8
Table 8:
Bit 4
Bit 3
LD7
Bit 2
Bit 1
Bit 0
LD6
LD5
PCA931 (Misc/Status LEDs) - LS1
Bit 7
Bit 6
Bit 5
LD12
Table 9:
Bit 4
LD11
Bit 3
Bit 2
LD9 Green
Bit 1
Bit 0
LD9 Red
PCA931 (Red/Green/Blue LEDs) - LS0
Bit 7
Bit 6
Bit 5
LD16
Table 10:
Bit 4
Bit 3
LD15
Bit 2
Bit 1
LD14
Bit 0
LD13
PCA931 (Red/Green/Blue LEDs) - LS1
Bit 7
Bit 6
Bit 5
LD20
Bit 4
LD19
Bit 3
Bit 2
LD18
Bit 1
Bit 0
LD17
4.4.3 White LED control routine
Brightness control for the 4 white LEDs is performed with the following keys:
• Key 2: Brightness (-)
• Key 3: Brightness (+)
Remark: Keys in this routine have been programmed to detect a continuous push applied
to them. When pushed continuously, (+) or (-) action is performed continuously until
max (0xFF) or min (0x00) in the PWM registers.
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
14 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
4.5 Emulation mode: battery discharge application
Emulation mode can be described as a mode that would require external ‘stimulus’ to
show an application in a real environment. The example in the firmware shows a simple
application where a battery discharge (for example in a cell phone application) is emulated
by pushing a key. A LED controlled by a PCA9531 is used to provide visual status of the
battery level:
• Emulation mode is entered by pushing key F2. LD11 starts blinking.
• Pushing key 1 starts battery discharge emulation.
– LD5 to LD8 are on, indicating a fully charged battery (100 %).
– LD9 blinks slowly (1 Hz) and high duty cycle, with a Green color.
• Pushing continuously Key 3 emulates a battery discharge (from 100 % with LD5 to
LD8 on, down to 0 % with LD5 to LD8 off). The different steps are explained in
Table 11. Principle is to change the LED color (Green, Orange, Red) and the
LED duty cycle (shorter duty cycle) to catch the user’s attention when using their cell
phone.
Table 11:
Battery discharge steps
Step
Battery charge
LD5
LD6
LD7
LD8
LD9
1
100 %
ON
ON
ON
ON
Green - 1 Hz - 93 % duty cycle
2
75 %
OFF
ON
ON
ON
Green - 1 Hz - 93 % duty cycle
3
50 %
OFF
OFF
ON
ON
Orange - 1 Hz - 50 % duty cycle
4
25 %
OFF
OFF
OFF
ON
Red - 1 Hz - 6 % duty cycle
5
0%
OFF
OFF
OFF
OFF
Red - 1 Hz - 0.4 % duty cycle
• A reset of the emulation is performed by pushing key 6. Battery is then fully charged.
• Pushing key END exits the battery discharge emulation mode. LD5 to LD9 are off.
• Pushing again key END exits the Emulation mode. LD11 stops blinking.
Remark: Keys in this routine have been programmed to detect a continuous push applied
to them. When pushed continuously, (+) or (-) action is performed continuously.
4.6 Auto Demo routine
The Auto Demo routine shows some light effects real time RGB mixing without having to
push any buttons.
• Emulation mode is entered by pushing key F2. LD11 starts blinking
• Pushing key 4 starts the auto demo mode
Remark: Once the Auto Demo Mode starts (after pushing key 4), the user must use the
RESET button to exit the mode.
4.7 RESET
The RESET button located in the Keypad Control Card allows the user to reinitialize the
P89LV51RD2 and the I2C devices and go to a known state. It causes the firmware to start
again at the beginning point and initiates the dialing routine.
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
15 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
4.8 How to code I2C commands using the P89LV51RD2/PCA9564
I2C messages are described using a ‘structure’ type definition where the I2C address, the
number of bytes to be sent/received and a pointer to a buffer with the data are used:
typedef struct
{
BYTE address;
BYTE nrBytes;
BYTE *buf;
} I2C_MESSAGE;
// slave address to sent/receive message
// number of bytes in message buffer
// pointer to application message buffer
The user must then use a variable with an ‘I2C_MESSAGE’ type and a variable acting as
a buffer that will be filled with the message to send (Write operation) or filled with the
message received (Read operation).
Example 1: Program the PCA9531_Red with BR0 at (max frequency, 50 % duty cycle)
and BR1 at (max frequency, 10 % duty cycle), with LD13 to LD16 blinking at
BR0 and LD17 to LD20 blinking at BR1.
idata I2C_MESSAGE Message1;
idata BYTE Buffer1[16];
Message1.nrBytes = 7;
Message1.buf
= Buffer1;
Message1.address = 0xCA;
Buffer1[0]
= 0x11;
Buffer1[1]
= 0x00;
Buffer1[2]
= 0x80;
Buffer1[3]
= 0x00;
Buffer1[4]
= 0x19;
Buffer1[5]
= 0x00;
Buffer1[6]
= 0x00;
I2C_Write(&Message1);
//
//
//
//
//
//
//
//
//
I2C address PCA9531 Red (RGB LEDs)
auto increment + register 1
max frequency
50 % duty cycle
max frequency
10 % duty cycle
Red RGB LED's = off
Red RGB LED's = off
Function sending the I2C sequence
Example 2: Read the PCA9555 Input port Registers. To perform this operation a Write to
the device must been initiated first in order to provide the command code (or
pointer information) to decide which register(s) needs to be read. Then a
read is performed.
idata I2C_MESSAGE Message2;
data I2C_MESSAGE Message3;
idata BYTE Buffer2[16];
idata BYTE Buffer3[16];
Message2.nrBytes =
Message3.nrBytes =
Message2.buf
=
Message3.buf
=
Message2.address =
Message3.address =
Buffer2[0] = 0x00;
1;
2
Buffer2;
Buffer3;
0x46;
0x47;
// The 1st message is 1 byte long
// The 2nd message is 2 bytes long;
// I2C address PCA9555 Write
// I2C address PCA9555 Read
// Set the command byte / pointer
1st part of the message)
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
16 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
I2C_WriteRepRead(&Message2,&Message3); // Function sending the I2C sequence
After the read is performed Buffer3[0] and Buffer3[1] contain the input port register values.
5. Source code
5.1 i2cexpert.h
//*************************************************************************
//
P H I L I P S P R O P R I E T A R Y
//
//
COPYRIGHT (c) 2003 BY PHILIPS SEMICONDUCTORS
//
-- ALL RIGHTS RESERVED -//
// File Name: i2cexpert.h
// Created:
June 2, 2003
// Modified: June 4, 2003
// Revision: 1.00
//*************************************************************************
#include <REG51RX.H>
typedef unsigned char
typedef unsigned short
typedef unsigned long
BYTE;
WORD;
LONG;
typedef struct
{
BYTE address;
BYTE nrBytes;
BYTE *buf;
} I2C_MESSAGE;
// each message is configured as follows:
// slave address to sent/receive message
// number of bytes in message buffer
// pointer to application message buffer
typedef struct
{
BYTE nrMessages;
I2C_MESSAGE **p_message;
} I2C_TRANSFER;
//
//
//
//
structure of a complete transfer
made up of a number of messages and pointers to the messages
number of message in one transfer
pointer to pointer to message
/***************************************************************************/
/*
E X P O R T E D D A T A D E C L A R A T I O N S
*/
/***************************************************************************/
#define FALSE
#define TRUE
0
1
#define
#define
#define
#define
I2C_WR
I2C_RD
Increment
Decrement
0
1
0
1
#define
#define
#define
#define
#define
#define
#define
PCA9531_WR
PCA9531_RD
PCA9555_WR
PCA9555_RD
PCA9531_R_WR
PCA9531_R_RD
PCA9531_G_WR
0xC8
0xC9
0x46
0x47
0xCA
0xCB
0xCC
//
//
//
//
//
//
//
i2c
i2c
i2c
i2c
i2c
i2c
i2c
address
address
address
address
address
address
address
LED
LED
i/o
i/o
LED
LED
LED
Dimmer
Dimmer
expander
expander
Dimmer Red
Dimmer Red
Dimmer Green
9397 750 14062
Application note
-
Write operation
Read operation
Write operation
Read operation
Write operation
Read operation
Write operation
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
17 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
#define
#define
#define
#define
#define
#define
#define
#define
#define
PCA9531_G_RD
PCA9531_B_WR
PCA9531_B_RD
PCA9531_M_WR
PCA9531_M_RD
PCA9533_W_WR
PCA9533_W_RD
PCA24S08_WR
PCA24S08_RD
0xCD
0xCE
0xCF
0xC6
0xC7
0xC4
0xC5
0xA0
0xA1
//
//
//
//
//
//
//
i2c
i2c
i2c
i2c
i2c
i2c
i2c
address
address
address
address
address
address
address
LED
LED
LED
LED
LED
LED
LED
Dimmer
Dimmer
Dimmer
Dimmer
Dimmer
Dimmer
Dimmer
Green
Blue
Blue
Misc
Misc
White
White
//
//
//
//
//
//
//
//
//
//
//
//
transfer ended No Errors
transfer busy
err: general error
err: No data in block
err: No ack on data
err: No ack on address
err: Device not present
err: Arbitration lost
err: Time out occurred
err: Slave mode error
err: Initialization (not done)
err: Initialization (not done)
-
Read operation
Write operation
Read operation
Write operation
Read operation
Write operation
Read operation
/**** Status Errors ****/
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
I2C_OK
I2C_BUSY
I2C_ERROR
I2C_NO_DATA
I2C_NACK_ON_DATA
I2C_NACK_ON_ADDRESS
I2C_DEVICE_NOT_PRESENT
I2C_ARBITRATION_LOST
I2C_TIME_OUT
I2C_SLAVE_ERROR
I2C_INIT_ERROR
I2C_RETRIES
0
1
2
3
4
5
6
7
8
9
10
11
/***************************************************************************/
/*
I N T E R F A C E F U N C T I O N P R O T O T Y P E S
*/
/***************************************************************************/
extern
extern
extern
extern
void
void
void
void
I2C_InitializeMaster(BYTE speed);
I2C_InitializeSlave(BYTE slv, BYTE *buf, BYTE size, BYTE speed);
I2C_InstallInterrupt(BYTE vector);
I2C_Interrupt(void);
extern
extern
extern
extern
extern
extern
void
void
void
void
void
void
I2C_Write(I2C_MESSAGE *msg);
I2C_WriteRepWrite(I2C_MESSAGE *msg1, I2C_MESSAGE *msg2);
I2C_WriteRepRead(I2C_MESSAGE *msg1, I2C_MESSAGE *msg2);
I2C_Read(I2C_MESSAGE *msg);
I2C_ReadRepRead(I2C_MESSAGE *msg1, I2C_MESSAGE *msg2);
I2C_ReadRepWrite(I2C_MESSAGE *msg1, I2C_MESSAGE *msg2);
extern
extern
extern
extern
extern
extern
void
void
void
void
void
void
Init_White(void);
Init_RGB(void);
Init_Misc(void);
Init_GPIO(void);
GPIO_Interrupt_Handler(void);
InsertDelay(unsigned char delayTime);
extern void Backlight_Programming(void);
extern void Fun_Pattern_Programming(void);
extern void Battery_Status(void);
extern void Dial_Number(void);
extern void Intro_Patterns(void);
extern void Fun_Pattern_Display (short int Red_Value, short int Green_Value, short int Blue_Value, short int
Speed_Value);
extern void Auto_Demo(void);
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
18 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
static
static
static
static
sbit
sbit
sbit
sbit
LED0
LED1
LED2
LED3
=
=
=
=
P2^2;
P2^3;
P2^4;
P2^5;
// LD[9:12] mapped with LV51's P2[2:5]
static sbit PCA9555_Int = P3^2;
sbit PCA9564_Reset
= P3^4;
// Interrupt PCA9555 mapped with LV51's P3[2]
// Reset PCA9564 mapped with LV51's P3[4]
5.2 mainloop.c
//*************************************************************************
//
P H I L I P S P R O P R I E T A R Y
//
//
COPYRIGHT (c) 2003 BY PHILIPS SEMICONDUCTORS
//
-- ALL RIGHTS RESERVED -//
// File Name: mainloop.c
// Created:
June 2, 2003
// Modified: November 07, 2003
// Revision: 1.00
//*************************************************************************
#include
#include
#include
#include
<REG51RX.H>
"i2cexprt.h"
"PCA9564sys.h"
"I2C_Routines.h"
idata
idata
idata
idata
BYTE
BYTE
BYTE
BYTE
Buffer1[32];
Buffer2[32];
Buffer3[16];
Buffer4[16];
idata
idata
idata
idata
I2C_MESSAGE
I2C_MESSAGE
I2C_MESSAGE
I2C_MESSAGE
Message1;
Message2;
Message3;
Message4;
static short int ProgramCounter = 0;
//****************************************************************************
// Initialization Functions at power up, Reset or program change
//****************************************************************************
static void Init_PCA9564(void)
{
PCA9564_Reset = 1;
PCA9564_Reset = 0;
InsertDelay(2);
// PCA9564 reset time = 2 ms
PCA9564_Reset = 1;
AUXR = 2;
I2C_InitializeMaster(0x00);
// External memory space
// 330 kHz
}
void Init_White(void)
{
Message1.buf
= Buffer1;
Message1.nrBytes = 6;
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
19 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
Message1.address = PCA9533_W_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x10;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x10;
// default duty cycle for pwm1
Buffer1[5] = 0xAA;
// LD1-LD4 on at BR0 (White LEDs)
I2C_Write(&Message1);
}
void Init_RGB(void)
{
Message1.buf
= Buffer1;
Message1.nrBytes = 7;
Message1.address = PCA9531_R_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x6B;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x6B;
// default duty cycle for pwm1
Buffer1[5] = 0x00;
// Red RGB LED's = off
Buffer1[6] = 0x00;
// Red RGB LED's = off
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x00;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x00;
// default duty cycle for pwm1
Buffer1[5] = 0x00;
// Green RGB LED's = off
Buffer1[6] = 0x00;
// Green RGB LED's = off
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x25;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x25;
// default duty cycle for pwm1
Buffer1[5] = 0x00;
// Blue RGB LED's = off
Buffer1[6] = 0x00;
// Blue RGB LED's = off
I2C_Write(&Message1);
}
void Init_Misc(void)
{
Message1.buf
= Buffer1;
Message1.nrBytes = 7;
Message1.address = PCA9531_M_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x97;
// default prescaler pwm0
Buffer1[2] = 0x80;
// default duty cycle for pwm0
Buffer1[3] = 0x97;
// default prescaler pwm1 = 1 Hz
Buffer1[4] = 0x08;
// default duty cycle for pwm1 = 50%
Buffer1[5] = 0x00;
// Misc LED's = off
Buffer1[6] = 0x00;
// Misc LED's = off
I2C_Write(&Message1);
}
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
20 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
void Init_GPIO(void)
{
Message2.address =
Message2.buf
=
Message2.nrBytes =
Buffer2[0]
=
Message3.address
Message3.buf
Message3.nrBytes
Buffer3[0]
Buffer3[1]
=
=
=
=
=
PCA9555_WR;
Buffer2;
1;
0;
// subaddress = 0
PCA9555_RD;
Buffer3;
2;
// read 2 bytes
0xFF;
0xFF;
}
//****************************************************************************
// Delay time in milliseconds
// Insert a wait into the program flow
// Use Timer 1
// Do not use an interrupt
// Oscillator running at 11.0592 MHz
// 6 clock cycles per clock tick
// Therefore, we need 1843 cycles for 1msec
//****************************************************************************
void InsertDelay(unsigned char delayTime)
{
unsigned char i;
TMOD = (TMOD & 0x0F) | 0x01;
// 16-bit timer
TR1 = 0;
for (i=0;i<delayTime;i++)
{
TF1 = 0;
TH1 = 0xF8;
// set timer1 to 1843
TL1 = 0xCD;
// since it's an up-timer, use (65536-1843) = 63693 = F8CD
TR1 = 1;
// Start timer
while(TF1==0);
// wait until Timer1 overflows
}
}
//****************************************************************************
// Determine which program the user wants to run
//****************************************************************************
static void Function_Select(void)
{
if (Buffer3[1] == 0xBF)
// Push on F1 detected - enter LED programming mode
{
Message1.address = PCA9531_M_WR; // PCA9531 Misc to indicate LED programming mode
Message1.nrBytes = 2;
Buffer1[0]
= 0x16;
// subaddress = 0x06
Buffer1[1]
= 0xC0;
// LD12 blinking at BR1 --> Indicate LED programming mode active
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
while (Buffer3[1] != 0xDF)
// Loop as long as END button not pushed (programming mode active)
{
Buffer3[1] = 0xFF;
// Clear Key F1 pushed
GPIO_Interrupt_Handler();
// Check if a new key has been pushed (sub mode - function to be programmed)
if (Buffer3[0] == 0xFE | Buffer3[0] == 0xFD | Buffer3[0] == 0xFB)
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
21 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
// Key pushed = 1, 2, or 3 --> Fun pattern programming
{
Fun_Pattern_Programming();
}
if (Buffer3[0] == 0xF7)
{
Backlight_Programming();
}
}
Buffer3[1] = 0xFF;
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 2;
Buffer1[0]
= 0x16;
Buffer1[1]
= 0x00;
I2C_Write(&Message1);
// Key pushed = 4 --> Backlight programming
// Clear Key END pushed - leave programming mode
// PCA9531 Misc
// subaddress = 0x16
// Misc Green LED = off --> Indicate LED programming mode left
// Program PCA9531 (2 bytes)
}
if (Buffer3[1] == 0x7F)
// Push on F2 detected - enter simulation mode
{
Message1.address = PCA9531_M_WR; // PCA9531 Misc to indicate simulation mode
Message1.nrBytes = 2;
Buffer1[0]
= 0x16;
// subaddress = 0x06
Buffer1[1]
= 0x30;
// LD11 blinking at BR1 --> Indicate simulation mode active
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
while (Buffer3[1] != 0xDF)
// Loop as long as END button not pushed (programming mode active)
{
Buffer3[1] = 0xFF;
// Clear Key F2 pushed
GPIO_Interrupt_Handler();
// Check if a new key has been pushed (sub mode - function to be programmed)
if (Buffer3[0] == 0xFE)
// Key pushed = 1 --> Battery discharge emulation
{
Battery_Status();
}
if (Buffer3[0] == 0xF7)
// Key 4 pushed
{
Auto_Demo();
}
}
Buffer3[1] = 0xFF;
// Clear Key END pushed - leave simulation mode
Message1.address = PCA9531_M_WR; // PCA9531 Misc to indicate LED programming mode
Message1.nrBytes = 2;
Buffer1[0]
= 0x16;
// subaddress = 0x06
Buffer1[1]
= 0x00;
// LD11 blinking at BR1 --> Indicate LED programming mode active
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
}
if (Buffer3[0] != 0xFF | Buffer3[1] == 0xFE | Buffer3[1] == 0xFD | Buffer3[1] == 0xFB | Buffer3[1] == 0xF7)
{
Dial_Number();
Buffer3[1] = 0xFF;
// Clear Key END pushed
}
Buffer3[1] = 0xFF;
// Clear Key END pushed
}
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
22 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
//****************************************************************************
// Main program
//****************************************************************************
void main(void)
{
Init_PCA9564();
Init_White();
Init_RGB();
Init_Misc();
Init_GPIO();
Intro_Patterns();
//
//
//
//
//
//
Initialization PCA9564
Initialization White LED's
Initialization RGB LED's
Initialization Misc LED's
Initialization GPIO
Patterns displayed at power up
while (1)
{
GPIO_Interrupt_Handler();
Function_Select();
// Enter a specific mode (programming, dial a number ...)
}
}
5.3 I2C_Routines.c
//*************************************************************************
//
P H I L I P S P R O P R I E T A R Y
//
//
COPYRIGHT (c) 2003 BY PHILIPS SEMICONDUCTORS
//
-- ALL RIGHTS RESERVED -//
// File Name: I2C_Routines.c
// Created: June 2, 2003
// Modified: November 07, 2003
// Revision: 1.00
//*************************************************************************
#include <REG51RX.H>
#include "i2cexprt.h"
#include "PCA9564sys.h"
unsigned char Data_Received;
extern unsigned char CRX;
extern
extern
extern
extern
idata
idata
idata
idata
BYTE
BYTE
BYTE
BYTE
Buffer1[32];
Buffer2[32];
Buffer3[16];
Buffer4[16];
extern
extern
extern
extern
idata
idata
idata
idata
I2C_MESSAGE
I2C_MESSAGE
I2C_MESSAGE
I2C_MESSAGE
Message1;
Message2;
Message3;
Message4;
idata BYTE Snapshot_1_1st_Byte
idata BYTE Snapshot_1_2nd_Byte
idata BYTE Snapshot_2_1st_Byte
idata BYTE Snapshot_2_2nd_Byte
int Trigger_GPIO_Polling;
int GPIO_Polling_On = 0;
//
=
=
=
=
0x0F;
0x0F;
0x00;
0x00;
Enable (1) or disable (0) the PCA9555 polling option - default = off
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
23 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
void InsertBigDelay(void)
{
InsertDelay(255);
InsertDelay(255);
InsertDelay(255);
InsertDelay(255);
InsertDelay(255);
}
//****************************************************************************
// Program the 3 PCA9531 (R/G/B) with the same parameter(s)
//****************************************************************************
void Write_RGB_Controller(void)
{
Message1.address = PCA9531_R_WR;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
I2C_Write(&Message1);
}
//****************************************************************************
// GPIO Interrupt Handling function
// One shot mode (through /INT) or
// permanent action detection (then Input PCA9554 Reg# polling)
//****************************************************************************
void GPIO_Interrupt_Handler(void)
{
Message2.address = PCA9555_WR;
Message2.buf
= Buffer2;
Message2.nrBytes = 1;
Buffer2[0]
= 0;
Message3.address = PCA9555_RD;
Message3.buf
= Buffer3;
Message3.nrBytes = 2;
//subaddress = 0
// read 2 bytes
if (PCA9555_Int==0)
// Action
{
I2C_WriteRepRead(&Message2,&Message3);
if (Buffer3[0] ==0xFF & Buffer3[1] ==0xFF);
else
{
Snapshot_1_1st_Byte = Buffer3[0];
Snapshot_1_2nd_Byte = Buffer3[1];
}
on pushbutton detected
// 1st read the PCA9555
// load the 1st read data (Byte 1) in a temp memory
// load the 1st read data (Byte 2) in a temp memory
InsertDelay(255);
InsertDelay(255);
InsertDelay(255);
I2C_WriteRepRead(&Message2,&Message3);
Snapshot_2_1st_Byte
= Buffer3[0];
Snapshot_2_2nd_Byte
= Buffer3[1];
// 2nd read the PCA9555
// load the 2nd read data (Byte 1) in a temp memory
// load the 2nd read data (Byte 2) in a temp memory
// Compare the 2 read data in the temp memories
if (Snapshot_1_1st_Byte == Snapshot_2_1st_Byte & Snapshot_1_2nd_Byte == Snapshot_2_2nd_Byte & GPIO_Polling_On == 1)
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
24 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
{
Trigger_GPIO_Polling = 1;
}
else
{
Trigger_GPIO_Polling = 0;
Buffer3[0] = Snapshot_1_1st_Byte;
Buffer3[1] = Snapshot_1_2nd_Byte;
}
}
if (Trigger_GPIO_Polling == 1)
{
I2C_WriteRepRead(&Message2,&Message3);
}
// permanent push detected when 1st and 2nd readings equal
// single shot action when 1st and 2nd readings different
// Buffer loaded again with the initial push value
// Buffer loaded again with the initial push value
// Start Polling PCA9554 when permanent push detected
}
//****************************************************************************
// Pattern displayed at power up or after a reset
//****************************************************************************
void Intro_Patterns(void)
{
Message1.nrBytes = 7;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x3B;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x01;
// default duty cycle for pwm1
Buffer1[5] = 0x00;
// Green RGB LED's = off
Buffer1[6] = 0x00;
// Green RGB LED's = off
Message1.address = PCA9531_R_WR;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
I2C_Write(&Message1);
Message1.nrBytes = 3;
Buffer1[0] = 0x15;
Buffer1[1] = 0x02;
// LD13 @ BR0
Buffer1[2] = 0x00;
Write_RGB_Controller();
InsertDelay(250);
Buffer1[1] = 0x0A;
// LD14 @ BR0
Buffer1[2] = 0x00;
Write_RGB_Controller();
InsertDelay(250);
Buffer1[1] = 0x20;
// LD15 @ BR0
Buffer1[2] = 0x00;
Write_RGB_Controller();
InsertDelay(250);
Buffer1[1] = 0xA0;
// LD16 @ BR0
Buffer1[2] = 0x00;
Write_RGB_Controller();
InsertDelay(250);
Buffer1[1] = 0x00;
Buffer1[2] = 0x02;
// LD17 @ BR0
Write_RGB_Controller();
InsertDelay(250);
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
25 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
Buffer1[1] = 0x00;
Buffer1[2] = 0x0A;
Write_RGB_Controller();
InsertDelay(250);
Buffer1[1] = 0x00;
Buffer1[2] = 0x20;
Write_RGB_Controller();
InsertDelay(250);
Buffer1[1] = 0x00;
Buffer1[2] = 0xA0;
Write_RGB_Controller();
InsertDelay(250);
Buffer1[1] = 0x02;
Buffer1[2] = 0x00;
Write_RGB_Controller();
InsertDelay(250);
Buffer1[1] = 0x00;
Buffer1[2] = 0x00;
Write_RGB_Controller();
// LD18 @ BR0
// LD19 @ BR0
// LD20 @ BR0
// LD13 @ BR0
// off
// off
}
//****************************************************************************
// Function controlling number dial
// Number = 10 digits : xxx-xxx-xxxx
// Once dialed, SND button is pushed
//****************************************************************************
idata BYTE Key_Pushed;
short int Call
= 0;
void Dial_Number(void)
{
int Nb_Key_Pressed = 0;
int One_To_Eight
= 0;
int Nine_Zero
= 0;
Call++;
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 6;
Message1.buf
= Buffer1;
Buffer1[0]
= 0x11;
Buffer1[1]
= 0x97;
Buffer1[2]
= 0x80;
Buffer1[3]
= 0x97;
Buffer1[4]
= 0x08;
Buffer1[5]
= 0x00;
I2C_Write(&Message1);
// When Call = even number, line is busy - When Call = odd number, line is not busy
// PCA9531 Misc
// Reset the PCA9531 to its default programmed values
//
//
//
//
//
//
//
subaddress = 0x01
BR0 = 1 Hz
BR0 duty cycle = 50%
BR1 = 1 Hz
duty cycle BR1 = 50%
All 4 LEDs off
Program PCA9531 (6 bytes)
Message1.nrBytes = 2;
while (Buffer3[1] != 0xDF)
// Loop as long as END button not pushed (call not ended)
{
if (Buffer3[0] != 0xFF & Nb_Key_Pressed < 11 & Buffer3[1] != 0xEF) // Key pushed = 1, 2, 3, 4, 5, 6, 7, 8 and != SND
{
Key_Pushed = Buffer3[0];
Nb_Key_Pressed++;
One_To_Eight = 1;
Nine_Zero = 0;
}
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
26 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
if (Buffer3[1] != 0xFF & Nb_Key_Pressed < 11 & Buffer3[1] != 0xEF) // Key pushed = 9, 0 and != SND
{
Key_Pushed = Buffer3[1];
Nb_Key_Pressed++;
One_To_Eight = 0;
Nine_Zero = 1;
}
if (Nb_Key_Pressed < 11 & Buffer3[1] != 0xEF & (Buffer3[0] != 0xFF | Buffer3[1] != 0xFF))
{
Buffer3[0] = 0xFF;
// Clear key pushed
Buffer3[1] = 0xFF;
// Clear key pushed
Buffer1[0] = 0x15;
// subaddress PCA9531_M= 0x05
switch (Key_Pushed)
{
case 0xFE: if (One_To_Eight == 1)
// 1 pushed
{
Buffer1[1] = 0x40;
// LD8 = on
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
}
if (Nine_Zero == 1)
// 9 pushed
{
Buffer1[1] = 0x41;
// LD5 and LD8 = on
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
}
break;
case 0xFD: if (One_To_Eight == 1)
// 2 pushed
{
Buffer1[1] = 0x10;
// LD7 = on
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
}
if (Nine_Zero ==1)
// 0 pushed
{
Buffer1[1] = 0x00;
// LD5 to LD8 = off
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
}
break;
case 0xFB:
// 3 pushed
Buffer1[1] = 0x50;
// LD7 and LD8 = on
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
break;
case 0xF7:
// 4 pushed
Buffer1[1] = 0x04;
// LD6 = on
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
break;
case 0xEF:
// 5 pushed
Buffer1[1] = 0x44;
// LD6 and LD8 = on
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
break;
case 0xDF:
// 6 pushed
Buffer1[1] = 0x14;
// LD6 and LD7 = on
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
break;
case 0xBF:
// 7 pushed
Buffer1[1] = 0x54;
// LD6, LD7 and LD8 = on
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
break;
case 0x7F:
// 8 pushed
Buffer1[1] = 0x01;
// LD5 = on
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
27 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
I2C_Write(&Message1);
break;
// Program PCA9531 (2 bytes)
}
}
if (Nb_Key_Pressed == 11 & Buffer3[1] != 0xEF) // more than 10 keys pushed and SND not pushed yet
{
Buffer3[0] = 0xFF;
// Clear key pushed
Buffer3[1] = 0xFF;
// Clear key pushed
Buffer1[1] = 0xAA;
// LD5 to LD8 = BR0 to indicate that the 10 numbers have been dialed
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
Nb_Key_Pressed++;
}
if (Buffer3[1] == 0xEF)
// SND pushed: Send a call
{
Buffer1[1]
= 0x00;
// LD5 to LD8 = off (dial number = done)
I2C_Write(&Message1);
// Program PCA9531 (2 bytes)
Message1.nrBytes = 7;
Buffer1[0]
= 0x11;
// subaddress = 0x01
Buffer1[1]
= 0x97;
// BR0 = 1 Hz
Buffer1[2]
= 0x80;
// duty cycle BR0 = 50%
Buffer1[3]
= 0x00;
// max freq BR1
Buffer1[4]
= 0xFF;
// max duty cycle BR1
Buffer1[5]
= 0xAA;
// All 4 RGB LEDs blinking red
Buffer1[6]
= 0xAA;
// All 4 RGB LEDs blinking red
if (Call & 0x01)
// Busy signal
{
Message1.address = PCA9531_R_WR;
// PCA9531 Red
I2C_Write(&Message1);
// Program PCA9531 (7 bytes)
}
else
// Non Busy signal
{
Message1.address = PCA9531_G_WR;
// PCA9531 Green
I2C_Write(&Message1);
// Program PCA9531 (7 bytes)
}
}
Buffer3[0] = 0xFF;
Buffer3[1] = 0xFF;
GPIO_Interrupt_Handler();
// Check if a key has been pushed
}
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 2;
Buffer1[1]
= 0x00;
I2C_Write(&Message1);
Message1.nrBytes = 3;
Buffer1[2]
= 0x00;
Message1.address = PCA9531_R_WR;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
I2C_Write(&Message1);
// PCA9531 Misc
// LD5 to LD8 = off (dial number = done)
// Program PCA9531 (2 bytes)
//
//
//
//
//
All RGB
PCA9531
Program
PCA9531
Program
LEDs = off
Red to switch off Red LEDs
PCA9531 (3 bytes)
Red to switch off Green LEDs
PCA9531 (3 bytes)
}
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
28 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
//****************************************************************************
// Function controlling the Duty Cycle for a specific device
// inputs = Key "-", Key "+", I2C address
// output = new Duty Cycle value
//****************************************************************************
short int Duty_Cycle_Control(short int Operation, short int I2C_Address, short int Duty_Cycle_Value)
{
Message1.address = I2C_Address;
Message1.nrBytes = 2;
if (Operation == Decrement & Duty_Cycle_Value > 0x00) // Key pushed = 2 - decrease brightness
{
Buffer1[0] = 0x02;
// subaddress = 0x02
Duty_Cycle_Value--;
// decrement pwm 0
Buffer1[1] = Duty_Cycle_Value;
I2C_Write(&Message1);
// send new data to PCA9531 (2 bytes)
}
if (Operation == Increment & Duty_Cycle_Value < 0xFF) // Key pushed = 3 pushed - increase brightness
{
Buffer1[0] = 0x02;
// subaddress = 0x02
Duty_Cycle_Value++;
// increment pwm 0
Buffer1[1] = Duty_Cycle_Value;
I2C_Write(&Message1);
// send new data to PCA9531 (2 bytes)
}
Buffer3[0] = 0xFF;
// Clear Key Plus pushed
Buffer3[1] = 0xFF;
// Clear Key Plus pushed (Key 9 only)
return Duty_Cycle_Value;
}
//****************************************************************************
// Function controlling the Backlight programming
// Entered by pushing 1
// Key 2 = decrease brightness
// Key 3 = Increase brightness
// Leave the mode by pushing END
//****************************************************************************
idata BYTE Duty_Cycle_White;
void Backlight_Programming (void)
{
Buffer3[0]
= 0xFF;
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 2;
Buffer1[0]
= 0x15;
Buffer1[1]
= 0x40;
I2C_Write(&Message1);
GPIO_Polling_On = 1;
Message2.address = PCA9533_W_WR;
Message2.buf
= Buffer2;
Message2.nrBytes = 1;
Buffer2[0]
= 0x02;
Message3.address = PCA9533_W_RD;
Message3.buf
= Buffer3;
Message3.nrBytes = 1;
I2C_WriteRepRead(&Message2,&Message3);
Duty_Cycle_White = Buffer3[0];
while (Buffer3[1] != 0xDF)
// Clear Key 1 pushed
// PCA9531 Misc to indicate backlight programming mode
// subaddress = 0x15
// LD8 on --> backlight programming mode active
// Enable PCA9555 polling option (see GPIO_Interrupt_Handler function)
// Read the current brightness value from the PCA9533
// subaddress = 12
// read 1 byte
// read PWM0 of the PCA9531
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
29 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
{
GPIO_Interrupt_Handler();
InsertDelay(100);
if (Buffer3[0] == 0xFD) Duty_Cycle_White = Duty_Cycle_Control(Decrement, PCA9533_W_WR, Duty_Cycle_White);
// "-" Red (Key 2)
if (Buffer3[0] == 0xFB) Duty_Cycle_White = Duty_Cycle_Control(Increment, PCA9533_W_WR, Duty_Cycle_White);
// "+" Red (Key 3)
}
Buffer3[1]
= 0xFF;
GPIO_Polling_On = 0;
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 2;
Buffer1[0]
= 0x15;
Buffer1[1]
= 0x00;
I2C_Write(&Message1);
// Clear Key END pushed
// Disable PCA9555 GPIO option
// PCA9531 Misc to indicate LED programming mode
// subaddress = 0x15
// LD8 off --> backlight programming mode left
}
//****************************************************************************
// Function displaying a selected Fun Pattern
// Inputs = Amount of Red, Green and Blue, Rotating Speed
//****************************************************************************
int Fun_Loop_Counter = 1;
int Speed_Prog_On
= 0;
void Fun_Pattern_Display( short int Red_Value,
{
Message1.buf
= Buffer1;
Message1.nrBytes = 2;
Buffer1[0]
= 0x12;
Message1.address = PCA9531_R_WR;
Buffer1[1]
= Red_Value;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
Buffer1[1]
= Green_Value;
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
Buffer1[1]
= Blue_Value;
I2C_Write(&Message1);
Message1.nrBytes = 3;
Buffer1[0]
= 0x15;
short int Green_Value, short int Blue_Value, short int Speed_Value)
//
//
//
//
//
//
//
//
//
//
subaddress = 12
PCA9531 Red
Programming Red
Program PCA9531 Red (2 bytes)
PCA9531 Green
Programming Green
Program PCA9531 Green (2 bytes)
PCA9531 Blue
Programming Blue
Program PCA9531 Blue (2 bytes)
// subaddress = 15
// Loop as long as a pushbutton not pressed
while (((Buffer3[0]==0xFF & Buffer3[1]==0xFF) | Buffer3[1] == 0xFD | Buffer3[1] == 0xF7) & Speed_Prog_On ==0)
{
if (Fun_Loop_Counter < 8)
{
Fun_Loop_Counter++;
}
else
{
Fun_Loop_Counter = 1;
}
switch (Fun_Loop_Counter)
{
case 1: Buffer1[1] = 0x02;
// Programming LD13 blinking at BR0
Buffer1[2] = 0x00;
// LED's off
break;
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
30 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
case 2: Buffer1[1]
Buffer1[2]
break;
case 3: Buffer1[1]
Buffer1[2]
break;
case 4: Buffer1[1]
Buffer1[2]
break;
case 5: Buffer1[1]
Buffer1[2]
break;
case 6: Buffer1[1]
Buffer1[2]
break;
case 7: Buffer1[1]
Buffer1[2]
break;
case 8: Buffer1[1]
Buffer1[2]
break;
= 0x08;
= 0x00;
// Programming LD14 blinking at BR0
// LED's off
= 0x20;
= 0x00;
// Programming LD15 blinking at BR0
// LED's off
= 0x80;
= 0x00;
// Programming LD16 blinking at BR0
// LED's off
= 0x00;
= 0x02;
// LED's off
// Programming LD17 blinking at BR0
= 0x00;
= 0x08;
// Programming LD18 blinking at BR0
// LED's off
= 0x00;
= 0x20;
// LED's off
// Programming LD19 blinking at BR0
= 0x00;
= 0x80;
// LED's off
// Programming LD20 blinking at BR0
}
Message1.address = PCA9531_R_WR;
// PCA9531 Green
I2C_Write(&Message1);
// Program PCA9531 Red (3 bytes)
Message1.address = PCA9531_G_WR;
// PCA9531 Green
I2C_Write(&Message1);
// Program PCA9531 Green (3 bytes)
Message1.address = PCA9531_B_WR;
// PCA9531 Blue
I2C_Write(&Message1);
// Program PCA9531 Blue (3 bytes)
InsertDelay(Speed_Value);
// Programmable delay
InsertDelay(Speed_Value);
InsertDelay(Speed_Value);
GPIO_Interrupt_Handler();
if (Buffer3[1] == 0xFD | Buffer3[1] == 0xF7) Speed_Prog_On = 1;
}
if ((Buffer3[0]!=0xFF | Buffer3[1]!=0xFF) & Buffer3[1] != 0xFD &
{
Message1.nrBytes = 3;
Buffer1[0]
= 0x15;
// subaddress = 15
Buffer1[1]
= 0xAA;
// Programming All
Buffer1[2]
= 0xAA;
// Programming All
Message1.address = PCA9531_R_WR;
// PCA9531 Green
I2C_Write(&Message1);
// Program PCA9531
Message1.address = PCA9531_G_WR;
// PCA9531 Green
I2C_Write(&Message1);
// Program PCA9531
Message1.address = PCA9531_B_WR;
// PCA9531 Blue
I2C_Write(&Message1);
// Program PCA9531
}
Buffer3[1] != 0xF7) // All the LEDs blinking at BR0
LED's blinking at BR0
LED's blinking at BR0
Red (3 bytes)
Green (3 bytes)
Blue (3 bytes)
}
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
31 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
//****************************************************************************
// Function controlling the Fun Pattern programming
// 3 programmable patterns: color and speed
// Entered by pushing 4
// Key 1 = select pattern 1
// Key 4 = select pattern 2
// Key 7 = select pattern 3
// Key 2 = decrease red of selected pattern
// Key 3 = increase red of selected pattern
// Key 5 = decrease green of selected pattern
// Key 6 = increase green of selected pattern
// Key 8 = decrease blue of selected pattern
// Key 9 = increase blue of selected pattern
// Key 0 = decrease speed of selected pattern
// Key # = increase speed of selected pattern
//****************************************************************************
idata BYTE Duty_Cycle_R_One
idata BYTE Duty_Cycle_G_One
idata BYTE Duty_Cycle_B_One
= 0x6B;
= 0x01;
= 0x25;
idata BYTE Duty_Cycle_R_Two
idata BYTE Duty_Cycle_G_Two
idata BYTE Duty_Cycle_B_Two
= 0x01;
= 0x6B;
= 0x25;
idata BYTE Duty_Cycle_R_Three = 0x26;
idata BYTE Duty_Cycle_G_Three = 0x6B;
idata BYTE Duty_Cycle_B_Three = 0x01;
int Speed_One
= 255;
int Speed_Two
= 25;
int Speed_Three = 100;
void Fun_Pattern_Programming (void)
{
Init_RGB();
GPIO_Interrupt_Handler();
// Check if an action on pushbutton happened
if (Buffer3[0] == 0xFE)
// Pattern 1 selected - Key 1 pushed
{
Buffer3[0]
= 0xFF;
// Clear Key 1 pushed
Message1.address = PCA9531_M_WR;
// PCA9531 Misc to indicate backlight programming mode
Message1.nrBytes = 2;
Buffer1[0]
= 0x15;
// subaddress = 0x15
Buffer1[1]
= 0x01;
// LD5 on --> Pattern 1 programming active
I2C_Write(&Message1);
while (Buffer3[1]!=0xDF)
// Loop as long as END button not pushed (Fun pattern 1 programming active)
{
Buffer3[1] = 0xFF;
GPIO_Interrupt_Handler();
// Check if an action on pushbutton happened
GPIO_Polling_On = 1;
// Enable PCA9555 polling option (see GPIO_Interrupt_Handler function)
Fun_Pattern_Display(Duty_Cycle_R_One, Duty_Cycle_G_One, Duty_Cycle_B_One, Speed_One);
if (Buffer3[0] == 0xFD) Duty_Cycle_R_One = Duty_Cycle_Control(Decrement, PCA9531_R_WR, Duty_Cycle_R_One);
// "-" Red (Key 2)
if (Buffer3[0] == 0xFB) Duty_Cycle_R_One = Duty_Cycle_Control(Increment, PCA9531_R_WR, Duty_Cycle_R_One);
// "+" Red (Key 3)
if (Buffer3[0] == 0xEF) Duty_Cycle_G_One = Duty_Cycle_Control(Decrement, PCA9531_G_WR, Duty_Cycle_G_One);
// "-" Green (Key 5)
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
32 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
if (Buffer3[0] == 0xDF) Duty_Cycle_G_One = Duty_Cycle_Control(Increment, PCA9531_G_WR, Duty_Cycle_G_One);
// "+" Green (Key 6)
if (Buffer3[0] == 0x7F) Duty_Cycle_B_One = Duty_Cycle_Control(Decrement, PCA9531_B_WR, Duty_Cycle_B_One);
// "-" Blue (Key 8)
if (Buffer3[1] == 0xFE) Duty_Cycle_B_One = Duty_Cycle_Control(Increment, PCA9531_B_WR, Duty_Cycle_B_One);
// "+" Blue (Key 9)
if (Buffer3[1] == 0xFD & Speed_One > 0)
{
Speed_One--;
}
if (Buffer3[1] == 0xF7 & Speed_One < 255)
{
Speed_One++;
}
Speed_Prog_On = 0;
GPIO_Polling_On = 0;
// Disable PCA9555 GPIO Polling option
}
Buffer3[0]
= 0xFF;
Buffer3[1]
= 0xFF;
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 2;
Buffer1[0]
= 0x15;
Buffer1[1]
= 0x00;
I2C_Write(&Message1);
// PCA9531 Misc to indicate backlight programming mode
// subaddress = 0x15
// LD5 off --> Pattern 1 programming left
}
if (Buffer3[0] == 0xFD)
// Pattern 2 selected - Key 2 pushed
{
Buffer3[0]
= 0xFF;
// Clear Key 2 pushed
Message1.address = PCA9531_M_WR;
// PCA9531 Misc to indicate backlight programming mode
Message1.nrBytes = 2;
Buffer1[0]
= 0x15;
// subaddress = 0x15
Buffer1[1]
= 0x04;
// LD6 on --> Pattern 2 programming active
I2C_Write(&Message1);
while (Buffer3[1]!=0xDF)
// Loop as long as END button not pushed (Fun pattern 2 programming active)
{
Buffer3[1] = 0xFF;
GPIO_Interrupt_Handler();
// Check if an action on pushbutton happened
GPIO_Polling_On = 1;
// Enable PCA9555 polling option (see GPIO_Interrupt_Handler function)
Fun_Pattern_Display(Duty_Cycle_R_Two, Duty_Cycle_G_Two, Duty_Cycle_B_Two, Speed_Two);
if (Buffer3[0] == 0xFD) Duty_Cycle_R_Two = Duty_Cycle_Control(Decrement, PCA9531_R_WR, Duty_Cycle_R_Two);
// "-" Red (Key 2)
if (Buffer3[0] == 0xFB) Duty_Cycle_R_Two = Duty_Cycle_Control(Increment, PCA9531_R_WR, Duty_Cycle_R_Two);
// "+" Red (Key 3)
if (Buffer3[0] == 0xEF) Duty_Cycle_G_Two = Duty_Cycle_Control(Decrement, PCA9531_G_WR, Duty_Cycle_G_Two);
// "-" Green (Key 5)
if (Buffer3[0] == 0xDF) Duty_Cycle_G_Two = Duty_Cycle_Control(Increment, PCA9531_G_WR, Duty_Cycle_G_Two);
// "+" Green (Key 6)
if (Buffer3[0] == 0x7F) Duty_Cycle_B_Two = Duty_Cycle_Control(Decrement, PCA9531_B_WR, Duty_Cycle_B_Two);
// "-" Blue (Key 8)
if (Buffer3[1] == 0xFE) Duty_Cycle_B_Two = Duty_Cycle_Control(Increment, PCA9531_B_WR, Duty_Cycle_B_Two);
// "+" Blue (Key 9)
if (Buffer3[1] == 0xFD & Speed_Two > 0)
{
Speed_Two--;
}
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
33 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
if (Buffer3[1] == 0xF7 & Speed_Two < 255)
{
Speed_Two++;
}
Speed_Prog_On = 0;
GPIO_Polling_On = 0;
// Disable PCA9555 GPIO Polling option
}
Buffer3[1]
= 0xFF;
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 2;
Buffer1[0]
= 0x15;
Buffer1[1]
= 0x00;
I2C_Write(&Message1);
// PCA9531 Misc to indicate backlight programming mode
// subaddress = 0x15
// LD6 off --> Pattern 2 programming left
}
if (Buffer3[0] == 0xFB)
{
Buffer3[0]
= 0xFF;
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 2;
Buffer1[0]
= 0x15;
Buffer1[1]
= 0x10;
I2C_Write(&Message1);
// Pattern 3 selected - Key 3 pushed
// Clear Key 3 pushed
// PCA9531 Misc to indicate backlight programming mode
// subaddress = 0x15
// LD7 on --> Pattern 3 programming active
while (Buffer3[1]!=0xDF)
// Loop as long as END button not pushed (Fun pattern 1 programming active)
{
Buffer3[1] = 0xFF;
GPIO_Interrupt_Handler();
// Check if an action on pushbutton happened
GPIO_Polling_On = 1;
// Enable PCA9555 polling option (see GPIO_Interrupt_Handler function)
Fun_Pattern_Display(Duty_Cycle_R_Three, Duty_Cycle_G_Three, Duty_Cycle_B_Three, Speed_Three);
if (Buffer3[0] == 0xFD) Duty_Cycle_R_Three = Duty_Cycle_Control(Decrement, PCA9531_R_WR, Duty_Cycle_R_Three);
// "-" Red (Key 2)
if (Buffer3[0] == 0xFB) Duty_Cycle_R_Three = Duty_Cycle_Control(Increment, PCA9531_R_WR, Duty_Cycle_R_Three);
// "+" Red (Key 3)
if (Buffer3[0] == 0xEF) Duty_Cycle_G_Three = Duty_Cycle_Control(Decrement, PCA9531_G_WR, Duty_Cycle_G_Three);
// "-" Green (Key 5)
if (Buffer3[0] == 0xDF) Duty_Cycle_G_Three = Duty_Cycle_Control(Increment, PCA9531_G_WR, Duty_Cycle_G_Three);
// "+" Green (Key 6)
if (Buffer3[0] == 0x7F) Duty_Cycle_B_Three = Duty_Cycle_Control(Decrement, PCA9531_B_WR, Duty_Cycle_B_Three);
// "-" Blue (Key 8)
if (Buffer3[1] == 0xFE) Duty_Cycle_B_Three = Duty_Cycle_Control(Increment, PCA9531_B_WR, Duty_Cycle_B_Three);
// "+" Blue (Key 9)
if (Buffer3[1] == 0xFD & Speed_Three > 0)
{
Speed_Three--;
}
if (Buffer3[1] == 0xF7 & Speed_Three < 255)
{
Speed_Three++;
}
Speed_Prog_On = 0;
GPIO_Polling_On = 0;
// Disable PCA9555 GPIO Polling option
}
// end programming pattern 3 (END pushed and detected)
Buffer3[1]
= 0xFF;
Message1.address = PCA9531_M_WR;
// PCA9531 Misc to indicate backlight programming mode
Message1.nrBytes = 2;
Buffer1[0]
= 0x15;
// subaddress = 0x15
Buffer1[1]
= 0x00;
// LD7 off --> Pattern 1 programming left
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
34 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
I2C_Write(&Message1);
}
Message1.address = PCA9531_R_WR;
Message1.nrBytes = 3;
Buffer1[0]
= 0x15;
Buffer1[1]
= 0x00;
Buffer1[2]
= 0x00;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
I2C_Write(&Message1);
Buffer3[1]
= 0xFF;
// end if
// PCA9531 Red
// subaddress = 15
// all Red LED's off
// all Red LED's off
// PCA9531 all Green LED's off
// PCA9531 all Blue LED's off
// Clear Key END pushed
}
//****************************************************************************
// Function emulating a Battery Discharge
// Pushing Key 3 discharges the battery (level can be seen with LD5 to LD8
// Pushing 6 resets the emulation (battery fully charged again
//****************************************************************************
void Battery_Status (void)
{
int Battery_Level = 0xFF;
Buffer3[0]
= 0xFF;
// Clear Key 1 pushed
Message1.address = PCA9531_M_WR;
// PCA9531 Misc
Message1.nrBytes = 7;
Buffer1[0]
= 0x11;
// subaddress = 0x01
Buffer1[1]
= 0x97;
// Blinking rate
Buffer1[2]
= 0xF0;
// High Duty Cycle when Battery charge > 50%
Buffer1[3]
= 0x97;
// default prescaler pwm1 = 1 Hz
Buffer1[4]
= 0x08;
// default duty cycle for pwm1 = 50%
Buffer1[5]
= 0x55;
// LD5 to LD8 on --> Indicate battery fully charged
Buffer1[6]
= 0x32;
// RG LED Green blinking at BR0
I2C_Write(&Message1);
while (Buffer3[1]!=0xDF)
// Loop as long as END button not pushed (Fun pattern 2 programming active)
{
InsertDelay(150);
Buffer3[1] = 0xFF;
GPIO_Interrupt_Handler();
// Check if an action on pushbutton happened
GPIO_Polling_On = 1;
// Enable PCA9555 polling option (see GPIO_Interrupt_Handler function)
if (Buffer3[0] == 0xFB)
// Key 3 pushed - Battery is discharging when Key 3 pushed (continuous)
{
if (Battery_Level != 0x00) Battery_Level--;
if (Battery_Level == 0xC0)
{
Message1.address = PCA9531_M_WR; // PCA9531 Misc
Message1.nrBytes = 2;
Buffer1[0]
= 0x15;
// subaddress = 0x05
Buffer1[1]
= 0x54;
// LD5 now off
I2C_Write(&Message1);
}
if (Battery_Level == 0x80)
{
Message1.address = PCA9531_M_WR; // PCA9531 Misc
Message1.nrBytes = 6;
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
35 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
Buffer1[0]
= 0x12;
Buffer1[1]
= 0x80;
Buffer1[2]
= 0x97;
Buffer1[3]
= 0x08;
Buffer1[4]
= 0x50;
Buffer1[5]
= 0x3A;
I2C_Write(&Message1);
}
if (Battery_Level == 0x40)
{
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 6;
Buffer1[0]
= 0x12;
Buffer1[1]
= 0x10;
Buffer1[2]
= 0x97;
Buffer1[3]
= 0x08;
Buffer1[4]
= 0x40;
Buffer1[5]
= 0x38;
I2C_Write(&Message1);
}
if (Battery_Level == 0x00)
{
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 6;
Buffer1[0]
= 0x12;
Buffer1[1]
= 0x01;
Buffer1[2]
= 0x97;
Buffer1[3]
= 0x08;
Buffer1[4]
= 0x00;
Buffer1[5]
= 0x38;
I2C_Write(&Message1);
}
}
if (Buffer3[0] == 0xDF)
{
//
//
//
//
//
//
subaddress = 0x02
RG (Orange) LED shorter duty cycle
default prescaler pwm1 = 1 Hz
default duty cycle for pwm1 = 50%
LD5 and LD6 now off
RG LED Green and Red blinking at BR0 (Orange)
// PCA9531 Misc
//
//
//
//
//
//
subaddress = 0x02
RG (Red only) LED even shorter duty cycle
default prescaler pwm1 = 1 Hz
default duty cycle for pwm1 = 50%
LD5, LD6 and LD7 now off
RG LED Green and Red blinking at BR0
// PCA9531 Misc
//
//
//
//
//
//
subaddress = 0x02
Duty Cycle = 0x01 --> Red LED actually almost off
default prescaler pwm1 = 1 Hz
default duty cycle for pwm1 = 50%
LD5, LD6, LD7 and LD8 now off
RG LED Green and Red blinking at BR0
// Reset the simulation and recharge completly the battery (Key 6 pushed)
Battery_Level
= 0xFF;
Message1.address = PCA9531_M_WR;
// PCA9531 Misc
Message1.nrBytes = 6;
Buffer1[0]
= 0x12;
// subaddress = 0x02
Buffer1[1]
= Battery_Level - 0x10; // High Duty Cycle when Battery charge > 50%
Buffer1[2]
= 0x97;
// default prescaler pwm1 = 1 Hz
Buffer1[3]
= 0x08;
// default duty cycle for pwm1 = 50%
Buffer1[4]
= 0x55;
// LD5 to LD8 on --> Indicate battery fully charged
Buffer1[5]
= 0x32;
// RG LED Green blinking at BR0
I2C_Write(&Message1);
}
Buffer3[0] = 0xFF;
}
GPIO_Polling_On = 0;
Buffer3[1]
= 0xFF;
Message1.address = PCA9531_M_WR;
Message1.nrBytes = 3;
Buffer1[0]
= 0x15;
Buffer1[1]
= 0x00;
Buffer1[2]
= 0x30;
I2C_Write(&Message1);
// Clear Key 3 pushed
// Disable PCA9555 polling option (see GPIO_Interrupt_Handler function)
// PCA9531 Misc
// LD5 to LD8 off
}
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
36 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
//****************************************************************************
// Auto demo mode
// Reset only allows leaving this mode
//****************************************************************************
void Auto_Demo(void)
{
int i;
int j;
int k;
Message1.buf
= Buffer1;
Message1.nrBytes = 7;
Message1.address = PCA9531_R_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x6B;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x01;
// default duty cycle for pwm1
Buffer1[5] = 0x00;
// Green RGB LED's = off
Buffer1[6] = 0x00;
// Green RGB LED's = off
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x01;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x6B;
// default duty cycle for pwm1
Buffer1[5] = 0x00;
// Green RGB LED's = off
Buffer1[6] = 0x00;
// Green RGB LED's = off
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x25;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x25;
// default duty cycle for pwm1
Buffer1[5] = 0x00;
// Green RGB LED's = off
Buffer1[6] = 0x00;
// Green RGB LED's = off
I2C_Write(&Message1);
Message1.nrBytes = 3;
Buffer1[0] = 0x15;
// Animation 1
for (i = 0; i < 3; i++)
{
Buffer1[1] = 0xEE; //
Buffer1[2] = 0xEE; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xBB; //
Buffer1[2] = 0xBB; //
Write_RGB_Controller();
InsertBigDelay();
}
LD13 and 15 @ BR0 - LD14 and 16 @ BR1
LD17 and 19 @ BR0 - LD18 and 20 @ BR1
LD13 and 15 @ BR1 - LD14 and 16 @ BR0
LD17 and 19 @ BR1 - LD18 and 20 @ BR0
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
37 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
// Animation 2
Buffer1[1] = 0xAA; //
Buffer1[2] = 0xAA; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xAB; //
Buffer1[2] = 0xAA; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xAE; //
Buffer1[2] = 0xAA; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xBA; //
Buffer1[2] = 0xAA; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xEA; //
Buffer1[2] = 0xAA; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xAA; //
Buffer1[2] = 0xAB; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xAA; //
Buffer1[2] = 0xAE; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xAA; //
Buffer1[2] = 0xBA; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xAA; //
Buffer1[2] = 0xEA; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xAA; //
Buffer1[2] = 0xAA; //
Write_RGB_Controller();
InsertBigDelay();
// Animation 3
for (i = 0; i < 3; i++)
{
Buffer1[1] = 0xAB; //
Buffer1[2] = 0xAB; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xAE; //
Buffer1[2] = 0xAE; //
Write_RGB_Controller();
InsertBigDelay();
Buffer1[1] = 0xBA; //
Buffer1[2] = 0xBA; //
Write_RGB_Controller();
InsertBigDelay();
LD13-16 @ BR0
LD17-20 @ BR0
LD13 @ BR1 - LD14-16 @ BR0
LD17-20 @ BR0
LD14 @ BR1 - LD13,14,16 @ BR0
LD17-20 @ BR0
LD15 @ BR1 - LD13,14,16 @ BR0
LD17-20 @ BR0
LD16 @ BR1 - LD13-15 @ BR0
LD17-20 @ BR0
LD13-16 @ BR0
LD17 @ BR1 - LD18-20 @ BR0
LD13-16 @ BR0
LD18 @ BR1 - LD17,19,20 @ BR0
LD13-16 @ BR0
LD19 @ BR1 - LD17,18,20 @ BR0
LD13-16 @ BR0
LD18 @ BR1 - LD17,19,20 @ BR0
LD13-16 @ BR0
LD17-20 @ BR0
LD13@BR1, LD14-15-16@BR0
LD17@BR1, LD18-19-20@BR0
LD14@BR1, LD13-15-16@BR0
LD18@BR1, LD17-19-20@BR0
LD15@BR1, LD13-14-16@BR0
LD19@BR1, LD17-18-20@BR0
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
38 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
Buffer1[1] = 0xEA; // LD16@BR1, LD13-14-15@BR0
Buffer1[2] = 0xEA; // LD20@BR1, LD17-18-19@BR0
Write_RGB_Controller();
InsertBigDelay();
}
// Animation 4
Buffer1[1]
= 0x00; // LD13-16
Buffer1[2]
= 0x00; // LD17-20
Write_RGB_Controller();
for (i = 0; i < 3; i++)
{
Message1.address = PCA9531_R_WR;
Buffer1[1] = 0x41; // LD13,LD16
Buffer1[2] = 0x10; // LD19
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
Buffer1[1] = 0x04; // LD14
Buffer1[2] = 0x41; // LD17,20
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
Buffer1[1] = 0x10; // LD15
Buffer1[2] = 0x04; // LD18
I2C_Write(&Message1);
InsertBigDelay();
Message1.address = PCA9531_G_WR;
Buffer1[1] = 0x41; // LD13,LD16
Buffer1[2] = 0x10; // LD19
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
Buffer1[1] = 0x04; // LD14
Buffer1[2] = 0x41; // LD17,20
I2C_Write(&Message1);
Message1.address = PCA9531_R_WR;
Buffer1[1] = 0x10; // LD15
Buffer1[2] = 0x04; // LD18
I2C_Write(&Message1);
InsertBigDelay();
Message1.address = PCA9531_B_WR;
Buffer1[1] = 0x41; // LD13,LD16
Buffer1[2] = 0x10; // LD19
I2C_Write(&Message1);
Message1.address = PCA9531_R_WR;
Buffer1[1] = 0x04; // LD14
Buffer1[2] = 0x41; // LD17,20
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
Buffer1[1] = 0x10; // LD15
Buffer1[2] = 0x04; // LD18
I2C_Write(&Message1);
InsertBigDelay();
}
= off
= off
= red
= red
= green
= green
= blue
= blue
= green
= green
= blue
= blue
= red
= red
= blue
= blue
= red
= red
= green
= green
Message1.nrBytes = 7;
Message1.address = PCA9531_R_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
39 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
Buffer1[2] = 0x00;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x00;
// default duty cycle for pwm1
Buffer1[5] = 0xAA;
// Green RGB LED's = BR0
Buffer1[6] = 0xAA;
// Green RGB LED's = BR0
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x00;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x00;
// default duty cycle for pwm1
Buffer1[5] = 0xAA;
// Green RGB LED's = BR0
Buffer1[6] = 0xAA;
// Green RGB LED's = BR0
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
Buffer1[0] = 0x11;
// autoincrement + register 1
Buffer1[1] = 0x00;
// default prescaler pwm0
Buffer1[2] = 0x00;
// default duty cycle for pwm0
Buffer1[3] = 0x00;
// default prescaler pwm1
Buffer1[4] = 0x00;
// default duty cycle for pwm1
Buffer1[5] = 0xAA;
// Green RGB LED's = BR0
Buffer1[6] = 0xAA;
// Green RGB LED's = BR0
I2C_Write(&Message1);
Message1.nrBytes = 2;
Buffer1[0] = 0x12;
// Red only from min to max brightness
Message1.address = PCA9531_R_WR;
for (i = 0x00; i < 0xFF; i++)
{
Buffer1[1] = i;
I2C_Write(&Message1);
InsertDelay(40);
};
Buffer1[1] = 0x00;
// No red
I2C_Write(&Message1);
// Green only from min to max brightness
Message1.address = PCA9531_G_WR;
for (j = 0x00; j < 0xFF; j++)
{
Buffer1[1] = j;
I2C_Write(&Message1);
InsertDelay(40);
};
Buffer1[1] = 0x00;
// No green
I2C_Write(&Message1);
// Blue only from min to max brightness
Message1.address = PCA9531_B_WR;
for (k = 0x00; k < 0xFF; k++)
{
Buffer1[1] = k;
I2C_Write(&Message1);
InsertDelay(40);
};
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
40 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
Buffer1[1] = 0x00;
I2C_Write(&Message1);
// No blue
// Some color mixing 1
Message1.address = PCA9531_R_WR;
Buffer1[1] = 0x36;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
Buffer1[1] = 0x2B;
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
for (k = 0x00; k < 0xFF; k++)
{
Buffer1[1] = k;
InsertDelay(40);
I2C_Write(&Message1);
};
// Some color mixing 2
Buffer1[1] = 0x0A;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
Buffer1[1] = 0x0A;
I2C_Write(&Message1);
Message1.address = PCA9531_R_WR;
for (i = 0x00; i <0xFF; i++)
{
Buffer1[1] = i;
I2C_Write(&Message1);
InsertDelay(40);
};
// Some color mixing 3
Buffer1[1] = 0x10;
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
Buffer1[1] = 0x0A;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
for (j = 0x00; j < 0xFF; j++)
{
Buffer1[1] = j;
I2C_Write(&Message1);
InsertDelay(40);
};
// Some color mixing 4
Buffer1[1] = 0x00;
Message1.address = PCA9531_R_WR;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
I2C_Write(&Message1);
Message1.address = PCA9531_R_WR;
for (i = 0x00; i < 0xFF; i++)
{
Buffer1[1] = i;
// Program some red
// Program some green
// Increase amount of blue
// Program some blue
// Program some green
// Increase amount of red
// Program some red
// Program some blue
// Increase amount of green
// No color
// Increase amount of red
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
41 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
I2C_Write(&Message1);
InsertDelay(40);
};
Message1.address = PCA9531_G_WR;
for (j = 0x00; j < 0xFF; j++)
{
Buffer1[1] = j;
I2C_Write(&Message1);
InsertDelay(40);
};
Buffer1[1] = 0x00;
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
for (k = 0x00; k < 0xFF; k++)
{
Buffer1[1] = k;
I2C_Write(&Message1);
InsertDelay(40);
};
Message1.address = PCA9531_R_WR;
Buffer1[1] = 0x00;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
for (j = 0x00; j < 0xFF; j++)
{
Buffer1[1] = j;
I2C_Write(&Message1);
InsertDelay(40);
};
Buffer1[1] = 0x00;
I2C_Write(&Message1);
Message1.address = PCA9531_R_WR;
for (i = 0x00; i < 0xFF; i++)
{
Buffer1[1] = i;
I2C_Write(&Message1);
InsertDelay(40);
};
Buffer1[1] = 0x00;
I2C_Write(&Message1);
Message1.address = PCA9531_G_WR;
Buffer1[1] = 0xFF;
I2C_Write(&Message1);
Message1.address = PCA9531_B_WR;
for (k = 0x00; k < 0xFF; k++)
{
Buffer1[1] = k;
I2C_Write(&Message1);
InsertDelay(40);
};
Buffer1[1] = 0x00;
I2C_Write(&Message1);
Message1.address = PCA9531_R_WR;
for (i = 0x00; i < 0xFF; i++)
{
Buffer1[1] = i;
I2C_Write(&Message1);
InsertDelay(40);
// Increase amount of green
// Remove Green
// Increase amount of blue
// Remove Red
// Increase amount of green
// Remove Green
// Increase amount of red
// Remove Red
// Max Green
// Increase amount of blue
// Remove Blue
// Increase amount of red
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
42 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
};
Message1.address = PCA9531_G_WR;
for (j = 0x00; j < 0xFF; j++)
{
Buffer1[1] = j;
I2C_Write(&Message1);
InsertDelay(40);
};
// Increase amount of green
}
// END OF THE I2C ROUTINES //
9397 750 14062
Application note
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
43 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
6. Disclaimers
Life support — These products are not designed for use in life support
appliances, devices, or systems where malfunction of these products can
reasonably be expected to result in personal injury. Philips Semiconductors
customers using or selling these products for use in such applications do so
at their own risk and agree to fully indemnify Philips Semiconductors for any
damages resulting from such application.
Right to make changes — Philips Semiconductors reserves the right to
make changes in the products - including circuits, standard cells, and/or
software - described or contained herein in order to improve design and/or
performance. When the product is in full production (status ‘Production’),
relevant changes will be communicated via a Customer Product/Process
Change Notification (CPCN). Philips Semiconductors assumes no
responsibility or liability for the use of any of these products, conveys no
licence or title under any patent, copyright, or mask work right to these
products, and makes no representations or warranties that these products are
free from patent, copyright, or mask work right infringement, unless otherwise
specified.
Application information — Applications that are described herein for any
of these products are for illustrative purposes only. Philips Semiconductors
make no representation or warranty that such applications will be suitable for
the specified use without further testing or modification.
7. Licenses
Purchase of Philips I2C components
9397 750 14062
Application note
Purchase of Philips I2C components conveys a
license under the Philips’ I2C patent to use the
components in the I2C system provided the
system conforms to the I2C specification
defined by Philips. This specification can be
ordered using the code 9398 393 40011.
© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
Rev. 01 — 7 January 2005
44 of 45
AN10315
Philips Semiconductors
LED dimmer demoboard
8. Contents
1
2
3
3.1
3.2
3.3
3.3.1
3.3.2
3.4
3.5
4
4.1
4.2
4.3
4.3.1
4.3.2
4.3.3
4.4
4.4.1
4.4.2
4.4.3
4.5
4.6
4.7
4.8
5
5.1
5.2
5.3
6
7
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Ordering information . . . . . . . . . . . . . . . . . . . . . 3
Technical information—hardware . . . . . . . . . . 4
Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 4
I2C-bus device addresses. . . . . . . . . . . . . . . . . 4
Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Keypad control card . . . . . . . . . . . . . . . . . . . . . 5
LED control card . . . . . . . . . . . . . . . . . . . . . . . . 6
Demoboard (top view) . . . . . . . . . . . . . . . . . . . 7
RGB color mixing . . . . . . . . . . . . . . . . . . . . . . . 8
Technical information—how to use the
demobord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Firmware routines . . . . . . . . . . . . . . . . . . . . . . 10
Dialing routine. . . . . . . . . . . . . . . . . . . . . . . . . 11
How the keypad control works . . . . . . . . . . . . 11
Keypad mapping with the PCA9555 I/Os . . . . 11
Application: cell phone type keyboard—
Dialing routine. . . . . . . . . . . . . . . . . . . . . . . . . 12
Programming mode . . . . . . . . . . . . . . . . . . . . 13
Programming fun patterns routine—
RGB color mixing . . . . . . . . . . . . . . . . . . . . . . 13
PCA953x mapping with the LEDs . . . . . . . . . 14
White LED control routine. . . . . . . . . . . . . . . . 14
Emulation mode: battery discharge application 15
Auto Demo routine . . . . . . . . . . . . . . . . . . . . . 15
RESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
How to code I2C commands using the
P89LV51RD2/PCA9564 . . . . . . . . . . . . . . . . . 16
Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
i2cexpert.h . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
mainloop.c . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
I2C_Routines.c . . . . . . . . . . . . . . . . . . . . . . . . 23
Disclaimers. . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
© Koninklijke Philips Electronics N.V. 2005
All rights are reserved. Reproduction in whole or in part is prohibited without the prior
written consent of the copyright owner. The information presented in this document does
not form part of any quotation or contract, is believed to be accurate and reliable and may
be changed without notice. No liability will be accepted by the publisher for any
consequence of its use. Publication thereof does not convey nor imply any license under
patent- or other industrial or intellectual property rights.
Date of release: 7 January 2005
Document number: 9397 750 14062
Published in The Netherlands