小白求教CH555使用rgb三色LED控制器 驅(qū)動rgb矩陣問題

使用rgb三色LED控制器 驅(qū)動rgb矩陣,該如何寫一個函數(shù)接口確定其中一個rgb燈的位置,并給它賦紅綠藍(lán)三色的占空比?

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驅(qū)動相關(guān)初始化 */

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中斷優(yōu)先級設(shè)置為高優(yōu)先級 */

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數(shù)據(jù) */

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;

}

主函數(shù):

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燈,一行四個字節(jié)分別代表亮度,R,G,B。


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频