Yep sure!
	Code:
	
ASM
CONFIG CPUDIV=NOCLKDIV ; CPU runing at full speed
CONFIG USBDIV=OFF ; Low speed USB clock diviser disabled, not used here
CONFIG FOSC=HS ; Use of High Speed crystal oscillator
CONFIG PLLEN=ON ; Enable PLL multiplier, 12Mhz oscilator x 4
CONFIG PCLKEN=ON ; Primary clock source is enabled
CONFIG FCMEN=OFF ; Failsafe clock off
CONFIG IESO=OFF ; Oscillator switchover mode disabled
CONFIG WDTEN=ON ; Watchdog timer on
CONFIG WDTPS=512 ; Watchdog divider is 512
CONFIG MCLRE=OFF ; Disable MCLR pin, enable RC3
CONFIG STVREN=ON ; Stack full/underflow will cause reset
CONFIG LVP=OFF ; Low voltage programming disabled
CONFIG BBSIZ=OFF ; 512kW block boot size
CONFIG XINST=OFF ; Extended instruction mode disabled
ENDASM
Include	"cdc_desc.bas"	' Include the CDC descriptors
INCLUDE "USB_ASM_Service.pbp"  ' USB Init and Service interrupt routines
'Define pin function
TRISA = %00000000 'PortA all digital output
TRISB = %00000000 'PortB all digital output
TRISC = %00000000 'PortC all digital output
ANSEL = %00000000 'Disable analog input on other pins
ANSELH = %00000000 'Disable analog input on other pins
'Define weak pullups
WPUA = %00000000 'No weak pullup on portA
WPUB = %00000000 'No weak pullup on portB
    
Define  OSC     48
buffer VAR BYTE[16]
cnt VAR BYTE Byte
i VAR BYTE
'Pin function declaration
GreenLED VAR PORTC.6
RedLED VAR PORTC.3
BlueLED VAR PORTC.4
pwmvalue VAR BYTE
'Program start
pwmvalue = 130
HPWM 1,pwmvalue,32767
LOW REDLED
LOW BLUELED
LOW GREENLED
Pause 10
USBInit	' Get USB going
' Wait for USB input
idleloop:
USBService ' Must service USB regularly
cnt = 16 ' Specify input buffer size
USBIn 3, buffer, cnt, idleloop
i = 0
SELECT CASE buffer
        CASE "R"
            HIGH REDLED
            LOW GREENLED
            LOW BLUELED
        CASE "G"
            LOW REDLED
            HIGH GREENLED
            LOW BLUELED
        CASE "B"
            LOW REDLED
            LOW GREENLED
            HIGH BLUELED
        CASE "C"        
            LOW REDLED
            HIGH GREENLED
            HIGH BLUELED
        CASE "M"        
            HIGH REDLED
            LOW GREENLED
            HIGH BLUELED
        CASE "Y"
            HIGH REDLED
            HIGH GREENLED
            LOW BLUELED
        CASE "W"
            HIGH REDLED
            HIGH GREENLED
            HIGH BLUELED
        CASE "K"
            LOW REDLED
            LOW GREENLED
            LOW BLUELED
        CASE ELSE
            i = 1
END SELECT
' Message received
IF i = 0 THEN
	buffer[0] = buffer
	buffer[1] = "-"
	buffer[2] = "O"
	buffer[3] = "k"
	buffer[4] = 13
	buffer[5] = 10
	buffer[6] = 0
ELSE
        buffer[0] = "E"
	buffer[1] = "r"
	buffer[2] = "r"
	buffer[3] = "."
	buffer[4] = 13
	buffer[5] = 10
	buffer[6] = 0
ENDIF	
	
outloop:
	USBService		' Must service USB regularly
	USBOut 3, buffer, 7, outloop
	Goto idleloop		' Wait for next buffer
 It is a quick and dirty modification of the CDC demo. A RGB LED takes the color code sent on the USB port as a letter. The code works, but commenting USBInit, and both USBService kill it.
				
			
Bookmarks