• PicŪ Basic


  • Octobrite / TLC5947 rgb led driver example

    I have been admiring this chip TLC5947 from Texas Insturments. This awesome chip makes it super easy to drive 24 led channels of leds. For more details see the Datasheet.

    Anyways I picked up the Octobrite board from Macetech to make a quick demo of this chip easy. I plan on using this in a number of upcoming projects and thought I'd whip up some code. A quick google search didn't produce any example for picbasic so I thought I would share!




    Code:
    '****************************************************************
    '*  Name    : OCTOBRITE_A.BAS                                   *
    '*  Author  : OHARARP                                           *
    '*  Date    : 5/3/2009                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : Code Designed to work with OCTOBRITE/TLC5947      *
    '****************************************************************
        Device = 18F1220
        Xtal = 10
        Declare PLL_Req = On    
        Optimiser_Level = 3
        Clear    
        All_Digital = TRUE
    '*******************************************************************************   
    'Device Fuse configuration
    Config_Start
        OSC     = HSPLL     ; Internal Oscillator with I/O on RA6 and RA7
        FSCM    = OFF        ; Failsafe Clock Monitor Disabled
        IESO    = OFF        ; Int/Ext Oscillator Switch Over Disabled
        PWRT    = OFF        ; Power Up Timer Disabled
        BOR     = OFF        ; Brownout Reset Disabled
        WDT     = OFF        ; Watchdog Timer Disabled
        MCLRE    = On        ; MCLR Disabled
        LVP     = OFF       ; Low Voltage ICSP Disabled
    Config_End  
    '*******************************************************************************   
    Dim CMD As Word
    Dim RED As Word
    Dim BLU As Word
    Dim GRN As Word
    
    Dim SO As PORTA.0 'DATA PIN
    Dim CL As PORTA.1 'CLOCK PIN
    Dim BL As PORTA.2 'BLANK PIN
    Dim XL As PORTA.3 'LATCH PIN
    
    Dim IDX_RGB As Word
    Dim IDX_SHIFT As Word
    Dim DOF As Float 'Degrees of Offset
    Dim BF  As Float         'Brightness Factor
    Dim IDX_SCAN As Float    'Scan Index
    '*******************************************************************************   
    INIT:
    GoSub OCTO_RESET
    
    MAIN:
    
    RED = 0 
    GRN = 0
    BLU = 0
    
    'CYCLE THROUGH A SET OF PATTERN - SAME FOR ALL LEDS
    For IDX_RGB = 0 To 4095 Step 500
        RED = RED + IDX_RGB
        GRN = 1024
        BLU = 4095 - IDX_RGB 
        GoSub SHIFT_OCTO
        DelayMS 250
    Next
    
    
    GoTo MAIN
    '*******************************************************************************   
    OCTO_RESET:
        High BL
        DelayMS 250
        Low BL
    Return
    '*******************************************************************************   
    SHIFT_OCTO:
        Low XL  'Low Latch
        For IDX_SHIFT = 0 To 7
            SHOut SO,CL,msbfirst,[BLU\12, GRN\12, RED\12]
        Next
        High XL 
    Return
    '*******************************************************************************
    This article was originally published in forum thread: Octobrite / TLC5947 rgb led driver example started by ohararp View original post