簡單易用的 RGB LED driver IC, 資料表中說明它對於每個顏色表現只有5bits,透過串列通訊依序放置 15bits data ,起頭bit=1每個顏色佔據 5bits 總共剛好16個資料
控制程式碼範例,基本上只要依序送出資料即可控制
/*
***********************************************************************************************
* LPD6803 5bits RGB LED Driver
* All Rights Reserved
* File name : LPD6803.c
* Programmer : Wen-Shong Lay, Taiwan Tai-chung
* Web presence :
* E-Mail : wslay0924@gmail.com
* Language : CCS complier version
* Hardware : PIC12F1822
* Date : 07 Spr 2013 Version 1.0
*
* This module provides an interface to LPD6803 RGB LED driver
* PIN2 GMODE=1 採用線性32階; GMODE=0 非線性輸出256階, 內置上拉
* PIN3 OMODE=1 內恆流/恆壓驅動; OMODE=0 外掛驅動, 內置上拉
* PIN13 COMDE 選擇內部輝度時鐘源GCLK, COMDE=1 GCLK=內部振盪器輸出; COMDE=0 GCLK=DCLK, 內置上拉
* PIN1 DIN = SDA
* PIN4 DCLK = SCK
* PIN5,7,11 輸出端 VCC + LED + -^^^^^- OUTx RL=(VCC-VLED-Vout(約0.4~0.8V))/ILED
* PIN6,8,10 回授腳
* OMODE=1 (空接為上拉)
* 內恆壓 FBx ---- GND
* 內恆流 FBx -^^^^- GND I_LED = 0.7V/Rx
***********************************************************************************************
*/
#define SDA PIN_A5
#define SCK PIN_A4
/*
*********************************************************************************************************
* TRANSMISSION RGB SEQUENCE
*
* Description : Output RGB
* Arguments : dr, dg, db 0-31
*
* Returns : none
* Notes :
* OMODE=1;
* GMODE=0; CMODE=0 256 level (non-linear meet 32 level)
* GMODE=0; CMODE=0 32 level
* bit15 bit14 bit13 bit12 bit11 bit10 bit9 bit8 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
* 1 R4 R3 R2 R1 R0 G4 G3 G2 G1 G0 B4 B3 B2 B1 B0
*********************************************************************************************************
*/
void LPD_RGB(char dr, char dg, char db)
{
char i=0;
if (dr>31) dr = 31;
if (dg>31) dg = 31;
if (db>31) db = 31;
output_drive(SDA);
output_drive(SCK);
output_bit(SDA, 0);
output_bit(SCK, 0);
for (i=0; i<32; i++) //start process need 32 bits 0
{
output_bit(SCK,1);
output_bit(SCK,0);
}
//第一個bit 必須輸出1
output_bit(SDA, 1);
output_bit(SCK, 1);
output_bit(SCK, 0);
//輸出R
for (i=0; i<5; i++)
{
output_bit(SDA, bit_test(dr, 4-i));
output_bit(SCK, 1);
output_bit(SCK, 0);
}
//輸出G
for (i=0; i<5; i++)
{
output_bit(SDA, bit_test(dg, 4-i));
output_bit(SCK, 1);
output_bit(SCK, 0);
}
//輸出B
for (i=0; i<5; i++)
{
output_bit(SDA, bit_test(db, 4-i));
output_bit(SCK, 1);
output_bit(SCK, 0);
}
output_bit(SDA, 0);
output_bit(SCK, 1);
output_bit(SCK, 0);
}
沒有留言:
張貼留言