RRNegi
Junior Member level 2
I am using NCP5623 LED driver for the RGB LED.. The code isn't working in hardware.
- - - Updated - - -
Only 3 bytes are being transmitted instead of 6 bytes.
- - - Updated - - -
it is mikroC PRO PIC project and Crystal frequency is 8 MHz.
- - - Updated - - -
.why only 3 bytes are transmitting.
Code:
#include <P18F4550.h>
#include <delays.h>
#include <i2c.h>
#pragma config PLLDIV = 5
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2
#pragma config FOSC = HS
#pragma config FCMEN = ON
#pragma config IESO = OFF
#pragma config PWRT = ON
#pragma config BOR = ON
#pragma config BORV = 2
#pragma config VREGEN = OFF
#pragma config WDT = OFF
#pragma config WDTPS = 2048
#pragma config CCP2MX = OFF
#pragma config PBADEN = OFF
#pragma config LPT1OSC = OFF
#pragma config MCLRE = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
#pragma config ICPRT = OFF
#pragma config XINST = OFF
#pragma config CP0 = OFF
#pragma config CP1 = OFF
#pragma config CP2 = OFF
#pragma config CP3 = OFF
#pragma config CPB = OFF
#pragma config CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
#pragma config WRT2 = OFF
#pragma config WRT3 = OFF
#pragma config WRTC = OFF
#pragma config WRTB = OFF
#pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
#pragma config EBTR2 = OFF
#pragma config EBTR3 = OFF
#pragma config EBTRB = OFF
#define NCP5623_ADDRESS 0x70
#define CHIP_SHUTDOWN 0b00000000
#define SET_MAX_LED_CURRENT 0b00100000
#define PWM_RED_LED 0b01000000
#define PWM_GREEN_LED 0b01100000
#define PWM_BLUE_LED 0b10000000
#define TARGET_UPWARD_IEND 0b10100000
#define TARGET_DOWNWARD_IEND 0b11000000
#define GRADUAL_DIMMING_STEP_TIME 0b11100000
#define LED_CURRENT_16 0b00010000
#define LED_CURRENT_8 0b00001000
#define LED_CURRENT_4 0b00000100
#define LED_CURRENT_2 0b00000010
#define LED_CURRENT_1 0b00000001
#define BPWM16 0b00010000
#define BPWM8 0b00001000
#define BPWM4 0b00000100
#define BPWM2 0b00000010
#define BPWM1 0b00000001
#define GDIM16 0b00010000
#define GDIM8 0b00001000
#define GDIM4 0b00000100
#define GDIM2 0b00000010
#define GDIM1 0b00000001
#define GDIM128ms 0b00010000
#define GDIM64ms 0b00001000
#define GDIM32ms 0b00000100
#define GDIM16ms 0b00000010
#define GDIM8ms 0b00000001
unsigned char i = 0;
void Delay_ms(unsigned int mSec);
void NCP5623_Shutdown();
void NCP5623_Set_Led_Current(char value);
void NCP5623_Set_Red_Led_Brightness(char value);
void NCP5623_Set_Green_Led_Brightness(char value);
void NCP5623_Set_Blue_Led_Brightness(char value);
void NCP5623_Set_Gradual_Dimming_Upward(char value);
void NCP5623_Set_Gradual_Dimming_Downward(char value);
void NCP5623_Set_Gradual_Dimming_Step_Time(char value);
void NCP5623_Set_Rgb_Brightness( char r_value, char g_value, char b_value);
void Delay_ms(unsigned int mSec)
{
while(mSec != 0) {
Delay1KTCYx(2);
mSec--;
}
}
void NCP5623_Shutdown()
{
StartI2C();
WriteI2C(NCP5623_ADDRESS);
WriteI2C(CHIP_SHUTDOWN);
StopI2C();
}
void NCP5623_Set_Led_Current(char value)
{
StartI2C();
WriteI2C(NCP5623_ADDRESS);
if((value == LED_CURRENT_16) || (value == LED_CURRENT_8) || (value == LED_CURRENT_4)
|| (value == LED_CURRENT_2) || (value == LED_CURRENT_1))
{
WriteI2C(SET_MAX_LED_CURRENT | value);
}
StopI2C();
}
void NCP5623_Set_Red_Led_Brightness(char value)
{
StartI2C();
WriteI2C (NCP5623_ADDRESS);
if((value == BPWM16) || (value == BPWM8) || (value == BPWM4)
|| (value == BPWM2) || (value == BPWM1))
{
WriteI2C(PWM_RED_LED | value);
}
StopI2C();
}
void NCP5623_Set_Green_Led_Brightness(char value)
{
StartI2C();
WriteI2C (NCP5623_ADDRESS);
if((value == BPWM16) || (value == BPWM8) || (value == BPWM4)
|| (value == BPWM2) || (value == BPWM1))
{
WriteI2C(PWM_GREEN_LED | value);
}
StopI2C();
}
void NCP5623_Set_Blue_Led_Brightness(char value)
{
StartI2C();
WriteI2C(NCP5623_ADDRESS);
if((value == BPWM16) || (value == BPWM8) || (value == BPWM4)
|| (value == BPWM2) || (value == BPWM1))
{
WriteI2C(PWM_BLUE_LED | value);
}
StopI2C();
}
void NCP5623_Set_Gradual_Dimming_Upward(char value)
{
StartI2C();
WriteI2C(NCP5623_ADDRESS);
if((value == GDIM16) || (value == GDIM8) || (value == GDIM4)
|| (value == GDIM2) || (value == GDIM1))
{
WriteI2C(TARGET_UPWARD_IEND | value);
}
StopI2C();
}
void NCP5623_Set_Gradual_Dimming_Downward(char value)
{
StartI2C();
WriteI2C(NCP5623_ADDRESS);
if((value == GDIM16) || (value == GDIM8) || (value == GDIM4)
|| (value == GDIM2) || (value == GDIM1))
{
WriteI2C(TARGET_DOWNWARD_IEND | value);
}
StopI2C();
}
void NCP5623_Set_Gradual_Dimming_Step_Time(char value)
{
StartI2C();
WriteI2C(NCP5623_ADDRESS);
if((value == GDIM128ms) || (value == GDIM64ms) || (value == GDIM32ms)
|| (value == GDIM16ms) || (value == GDIM8ms))
{
WriteI2C(GRADUAL_DIMMING_STEP_TIME | value);
}
StopI2C();
}
void NCP5623_Set_Rgb_Brightness(char r_value, char g_value, char b_value) {
NCP5623_Set_Red_Led_Brightness(r_value);
NCP5623_Set_Green_Led_Brightness(g_value);
NCP5623_Set_Blue_Led_Brightness(b_value);
}
void main (void)
{
ADCON1 = 0x0F;
OpenI2C(MASTER, SLEW_OFF);// Initialize I2C module
Delay_ms(200);
NCP5623_Set_Led_Current(LED_CURRENT_16);
NCP5623_Set_Red_Led_Brightness(BPWM16);
NCP5623_Set_Green_Led_Brightness(BPWM16);
NCP5623_Set_Blue_Led_Brightness(BPWM16);
NCP5623_Set_Gradual_Dimming_Upward(GDIM16);
NCP5623_Set_Gradual_Dimming_Step_Time(GDIM32ms);
while(1)
{
for(i = 0x01; i < 0x20; i<<1)
{
NCP5623_Set_Rgb_Brightness(i, i, i);
Delay100TCYx(100);
}
Delay100TCYx(100);
Delay100TCYx(100);
for(i = 0x10; i >= 0x01; i>>1)
{
NCP5623_Set_Rgb_Brightness(i, i, i);
Delay100TCYx(100);
}
Delay100TCYx(100);
Delay100TCYx(100);
i = 0x01;
NCP5623_Set_Rgb_Brightness((i << 4), (i << 2), i);
Delay100TCYx(100);
i = 0x10;
NCP5623_Set_Rgb_Brightness(i, (i >> 2), (i >> 4));
Delay100TCYx(100);
}
}
- - - Updated - - -
Only 3 bytes are being transmitted instead of 6 bytes.
- - - Updated - - -
it is mikroC PRO PIC project and Crystal frequency is 8 MHz.
- - - Updated - - -
.why only 3 bytes are transmitting.