小白求教CH555使用rgb三色LED控制器 驱动rgb矩阵问题

使用rgb三色LED控制器 驱动rgb矩阵,该如何写一个函数接口确定其中一个rgb灯的位置,并给它赋红绿蓝三色的占空比?

rgb初始化:

//P4-PWM_R

//P2-PWM_G

//P1-PWM_B

//P0-COM3~COM10

//P3-COM11~COM17

//P7_0-COM1

//P7_1-COM2


/*******************************************************************************

* Function Name  : InitRGBLED

* Description    : RGBLED ??????

* Input          : None

* Return         : None

*******************************************************************************/

void InitRGBLED(void)

LED_COMMON_Start = 0x0E;  

P7 |= ( bP7_1_DIR | bP7_0_DIR );


/* LED驱动相关初始化 */

P4 = P2 = P1 = 0xFF;  /* R/G/B PWM pins invert output, low action for sink current */

P0 = P3 = 0xFF;  /* COMMON pin invert output, low action for drive external PMOS */

// P7 = 0x00;

P4_MOD_OC = P2_MOD_OC = P1_MOD_OC = 0;  /* R/G/B PWM pins push-pull output */

P0_MOD_OC = P3_MOD_OC = 0; /* COMMON pins push-pull output */

LED_CTRL = bLED_EN;

LED_CYCLE = bLED_INTEN_CYC0; /* PWM_128@color,PWM_128@intenisy,1x bLED_COLOR_CYC|  MASK_LED_INT_CYC */

LED_FRAME = bLED_INH_TMR2 | bLED_INH_TMR0;  /* 101->8 intenisy PWM cycles, same PWM data repeat 1 time */

LED_DMA = BufferAddr = (UINT16)( &RGBdataBuffer[ 0 ] );  /* buffer start address  */

// RGB_Load_Mode = 0;            /* indicate data@xRAM (1=data@flash ROM) */

LED_INT_ADJ = 0x00;  /* adjust: increase intenisy */

LED_PWM_OE = 0xFF;

LED_COMMON = 0xFF;  /* preset COMMON selection, next is 0, start @interrupt */

LED_CTRL = bLED_IE_INHIB | bLED_BLUE_EN | bLED_GREEN_EN | bLED_RED_EN | bLED_COM_AHEAD | bLED_PWM_INHIB | bLED_EN;

LED_STATUS |= bLED_IF_SET;  /* force bLED_IF to enter interrupt service */ 

IE_PWM_I2C = 1;


    LED_RED_ADJ = 0;

    LED_GRE_ADJ = 0;

    LED_BLU_ADJ = 0;


/* 将RGB LED中断优先级设置为高优先级 */

IP_EX |= bIP_PWM_I2C;

}




void LED_INT( void ) interrupt INT_NO_PWM_I2C using 1

{

UINT8 idata com_save;

UINT8 idata offset;


/* 切换COM并加载LED数据 */

LED_COMMON++;

if( ( LED_COMMON & 0x1F ) == 0x00 )  

{

/* switch COMMON, clear interrupt flag */      

LED_COMMON = LED_COMMON_Start;


/* reset buffer start address */

LED_DMA = BufferAddr;

}

// if( IsCode ) 

// {

// /* load data from code ROM, and prepare COMMON pin low for key scan, ASM for speed */

// LED_LOAD_CODE( );

// }

// else 

// {

// /* load data from XRAM, and prepare COMMON pin low for key scan, ASM for speed */

// LED_LOAD_XRAM( );

//    }


/* 暂存LED_COMMON */

com_save = LED_COMMON;

}

主函数:

void main(void)

{

UINT8 i,RGB_stauts;

signed char data incre=0;

CfgFsys();

mDelaymS(20);


InitRGBLED();

LED_RED_ADJ = 0;

LED_GRE_ADJ = 0;

LED_BLU_ADJ = 0;

IE_PWM_I2C = 1;

E_DIS=0;

EA = 1;

// /*变量初始化*/ 

for(i=0; i<128; i++){

RGBdataBuffer1[i][0]=0;

RGBdataBuffer1[i][1]=0;//R

RGBdataBuffer1[i][2]=0;//G

RGBdataBuffer1[i][3]=0;//B

}    

mDelaymS(1000);

BufferAddr = (UINT16)(&RGBdataBuffer1[0]);


//R

for(i=0; i<128; i++){

RGBdataBuffer[i][0]=127;

RGBdataBuffer[i][1]=127;//R

RGBdataBuffer[i][2]=0;//G

RGBdataBuffer[i][3]=0;//B

}  

mDelaymS(1000);

BufferAddr = (UINT16)(&RGBdataBuffer[0]); 

mDelaymS(1000);  

BufferAddr = (UINT16)(&RGBdataBuffer1[0]);  

mDelaymS(1000);  

//G

for(i=0; i<128; i++){

RGBdataBuffer[i][0]=127;

RGBdataBuffer[i][1]=0;//R

RGBdataBuffer[i][2]=127;//G

RGBdataBuffer[i][3]=0;//B

}

BufferAddr = (UINT16)(&RGBdataBuffer[0]); 

mDelaymS(1000); 

BufferAddr = (UINT16)(&RGBdataBuffer1[0]);  

mDelaymS(1000); 

//B

for(i=0; i<128; i++){

RGBdataBuffer[i][0]=127;

RGBdataBuffer[i][1]=0;//R

RGBdataBuffer[i][2]=0;//G

RGBdataBuffer[i][3]=127;//B

}

BufferAddr = (UINT16)(&RGBdataBuffer[0]); 

mDelaymS(1000); 

BufferAddr = (UINT16)(&RGBdataBuffer1[0]);  

mDelaymS(1000);

while(1){


if(incre >= 127)  RGB_stauts = 1;

if(incre <= -127) RGB_stauts = 0;

LED_RED_ADJ = RGB_stauts?(incre--):(incre++);

LED_GRE_ADJ = RGB_stauts?(incre--):(incre++);

LED_BLU_ADJ = RGB_stauts?(incre--):(incre++);

mDelaymS(1000);

}

}



您可以理解为,RGBdataBuffer,一共有128行,每行表示一个RGB灯,一行四个字节分别代表亮度,R,G,B。


只有登录才能回复,可以选择微信账号登录