Hi all, I made a RGB LED lamp with super bright RGB LEDs from sparkfun and control the color from my TV remote. I use 16F628s X2 because I couldnt get pulsein to work with MIBAM (inturupt timming issue) Here is the code if it will help anyone. Its not real clean but it works well

Aaron

IR CODE
Code:
 '****************************************************************
'*  Name    : IR_RGB_ControlV2                                      
'*  Author  : Aaron E.Wilson                                    
'*  Notice  : Copyright (c) 2009 
'*          : All Rights Reserved                               
'*  Date    : 2/21/2009                                         
'*  Version : 1.0                                               
'*  Notes   : Sets RGB select ports and UP/DN ports from IR remote                                                  
'*          :                                                   
'****************************************************************



define osc 4
CMCON     = 7          ' PortA = digital I/O
VRCON     = 0          ' A/D Voltage reference disabled
TRISA     = %00000010  ' Set PortA I/O
TRISB     = %00000000  ' Set PortB I/O 
PORTA     = 0          ' Clear PortA
PORTB     = 0          ' Clear PortB


IRpulse_length var word(13)
xx var Byte
Command	Var	Byte
Device Var Byte        'IR Chip---------RGB Chip
IR_IN var PORTA.1       'Pin 18         N/A
RED_SEL var PORTB.1     'Pin 7          Pin 18
BLUE_SEL var PORTB.2    'Pin 8          Pin 3
GREEN_SEL var PORTB.3   'Pin 9          Pin 17
UP var PORTB.5          'Pin 11         Pin 1
DN var PORTB.4          'Pin 10         Pin 2

pause 500

Main:
    gosub ReadIr 
    if command = 1 then RED_Adj
    if command = 2 then BLUE_Adj
    if command = 3 then GREEN_Adj

goto Main

Red_Adj:
    blue_sel = 0
    Green_sel = 0
    red_sel = 1
    gosub ReadIr
    if command = 17 then
    dn = 0
    up = 1
    pause 100
    up = 0
    endif
    if command = 18 then
    up = 0
    dn = 1
    pause 100
    dn = 0
    endif
    if command = 2 then BLUE_Adj
    if command = 3 then GREEN_Adj
    goto red_adj

BLUE_Adj:
    red_sel = 0
    green_sel = 0
    blue_sel = 1
    gosub ReadIr
    if command = 17 then
    dn = 0
    up = 1
    pause 100
    up = 0
    endif
    if command = 18 then
    up = 0
    dn = 1
    pause 100
    dn = 0
    endif
    if command = 1 then red_Adj
    if command = 3 then GREEN_Adj
    goto blue_adj

GREEN_Adj:
    red_sel = 0
    Blue_sel = 0
    green_sel = 1
    gosub ReadIr
    if command = 17 then
    dn = 0
    up = 1
    pause 100
    up = 0
    endif
    if command = 18 then
    up = 0
    dn = 1
    pause 100
    dn = 0
    endif
    if command = 2 then BLUE_Adj
    if command = 1 then red_Adj
    goto green_adj  
    
ReadIR: 
    PuLSIN IR_IN,0,IRpulse_length(0)
    if IRpulse_length(0) < 200 then
    goto ReadIR
    Endif

    for xx=1 to 12
    pulsin ir_in,0,IRpulse_length(xx)
    next  xx

    if IRpulse_length(1) < 100 then
    Command.bit0 = 0 
    Else	
    Command.bit0 = 1
    endif
    
    if IRpulse_length(2) < 100 then
    Command.bit1 = 0 
    Else	
    Command.bit1 = 1
    endif
    
    if IRpulse_length(3) < 100 then
    Command.bit2 = 0 
    Else	
    Command.bit2 = 1
    endif
    
    if IRpulse_length(4) < 100 then
    Command.bit3 = 0 
    Else	
    Command.bit3 = 1
    endif
    
    if IRpulse_length(5) < 100 then
    Command.bit4 = 0 
    Else	
    Command.bit4 = 1
    endif
    
    if IRpulse_length(6) < 100 then
    Command.bit5 = 0 
    Else	
    Command.bit5 = 1
    endif
    
    if IRpulse_length(7) < 100 then
    Command.bit6 = 0 
    Else	
    Command.bit6 = 1
    endif
    
    Command.bit7 = 0 
    Command = Command + 1
    If Command = 10 then
    Command = 0
    Endif

    if IRpulse_length(8) < 100 then
    Device.bit0 = 0 
    Else	
    Device.bit0 = 1
    endif
    
    if IRpulse_length(9) < 100 then
    Device.bit1 = 0 
    Else	
    Device.bit1 = 1
    endif
    
    if IRpulse_length(10) < 100 then
    Device.bit2 = 0 
    Else	
    Device.bit2 = 1
    endif
    
    if IRpulse_length(11) < 100 then
    Device.bit3 = 0 
    Else	
    Device.bit3 = 1
    endif
return
    
DebugInfo:
SEROUT2 PORTA.0,16780,[13]
pause 100
SEROUT2 PORTA.0,16780,[10]
pause 100
SEROUT2 PORTA.0,16780,["Device ", dec Device, " Command ", dec command]
pause 100
return

end



MIBAM CODE
Code:
 '****************************************************************
'*  Name    : Adj_Color                                         
'*  Author  : Aaron E.Wilson                                    
'*  Notice  : Copyright (c) 2009
'*          : All Rights Reserved                               
'*  Date    : 2/22/2009                                         
'*  Version : Final                                               
'*  Notes   :                                                   
'*          :                                                   
'****************************************************************
;_________________________Interrupt Context save locations]_________________

wsave       var byte    $20     SYSTEM      ' location for W if in bank0
wsave1      VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
wsave2      VAR BYTE    $120    SYSTEM      ' location for W if in bank2
ssave       VAR BYTE    BANK0   SYSTEM      ' location for STATUS register
psave       VAR BYTE    BANK0   SYSTEM      ' location for PCLATH register

;----[ MIBAM Setup ]--------------------------------------------------------

BAM_COUNT CON 3                     ; How many BAM Pins are used?
INCLUDE "MIBAM.pbp"                 ; Mirror Image BAM module

RED    VAR BYTE
GREEN  VAR BYTE
BLUE   VAR BYTE

ASM
BAM_LIST  macro                     ; Define PIN's to use for BAM
     BAM_PIN (PORTB,0, GREEN)       ; Pin 6
     BAM_PIN (PORTB,1, BLUE)        ; Pin 7
     BAM_PIN (PORTB,2, RED)         ; Pin 8
  endm
  BAM_INIT  BAM_LIST                ; Initialize the Pins
ENDASM
;----[ Chip Setup ]--------------------------------------------------------
define osc 4
CMCON     = 7          ' PortA = digital I/O
VRCON     = 0          ' A/D Voltage reference disabled
TRISA     = %00011111  ' Set PortA I/O
TRISB     = %11111000  ' Set PortB I/O 
PORTA     = 0          ' Clear PortA
PORTB     = 0          ' Clear PortB

;----[ Adjustment Setup ]-------------------------------------------------

RED_VAL var byte
GREEN_VAL var byte
BLUE_VAL var byte
UP_SEL var bit
DN_SEL var bit

RED_PORT var PORTA.1        'Pin 18 
GREEN_PORT var PORTA.0      'Pin 17 
BLUE_PORT var PORTA.4       'Pin 3 
UP_PORT var PORTA.2         'Pin 1
DN_PORT var PORTA.3         'Pin 2

;----[ Inital Settings ]--------------------------------------------------

RED_VAL = 0
GREEN_VAL = 0
BLUE_VAL = 0

;----[ Program ]----------------------------------------------------------

Main:
    gosub led
    gosub Adjust
    

goto main


Adjust:
    if PORTA = 0 then main
    
    Red_Up:
    if red_val > 250 then red_dn
    if red_port = 1 and up_port = 1 then
    red_val = red_val +1
    pause 100
    endif
    
    Red_Dn:
    if red_val = 0 then green_up
    if red_port = 1 and dn_port = 1 then
    red_val = red_val -1
    pause 100
    endif
    
    Green_Up:
    if green_val > 250 then green_dn
    if green_port = 1 and up_port = 1 then
    green_val = green_val +1
    pause 100
    endif
    
    Green_Dn:
    if green_val = 0 then blue_up
    if green_port = 1 and dn_port = 1 then
    green_val = green_val -1
    pause 100
    endif

    Blue_Up:
    if Blue_val > 250 then BLue_dn
    if Blue_port = 1 and up_port = 1 then
    Blue_val = Blue_val +1
    pause 100
    endif
    
    Blue_Dn:
    if Blue_val = 0 then main
    if BLue_port = 1 and dn_port = 1 then
    Blue_val = Blue_val -1
    pause 100
    endif
    goto main

LED:
    red = red_val
    pause 20
    blue = blue_val
    pause 20
    green = green_val
    pause 20
return
end