Here, this is even more simplified. Have momentary-ON button on Port B.0 pulled high, 4 LEDs with resistors to VSS on Port D.0, 1, 2 and 3.
On PIC side:
- button on Port B.0 sends "Button" text.
On PC side using Mr E's executable as-is:
- Port B buttons toggles LED on Port D.3.
Code:
'***************************************************************************
'* Name : USBLabX1_RH.pbp *
'* Author : Steve Monfette/Darrel Taylor/Demon *
'* Date : Jan 11 2012 *
'* Version : 3.0 *
'* Notes : This is a re-creation of mister-e's USBdemo for DT_HID *
'* : Meant to work with mister-e's GUI *
'* : Modified for Lab X1 *
'* Hardware : PIC 18F4550, 20mhz crystal *
'* : Lab X1 Experimental Board, 9.5V wall adapter *
'* : MeLabs U2 Programmer v4.32 *
'* Software : PIC Basic Pro v2.60C *
'* : MicroCode Studio Plus v2.2.1.1 *
'* : MPASM WIN Assembler v4.02 (mplab tools/MPASM Suite) *
'* PIC mods : plastic USB connector hot-glued onto top of PIC *
'* : D- wired to C4 (pin 23) directly to top of pins *
'* : D+ wired to C5 (pin 24) directly to top of pins *
'* : two 0.1uF ceramic caps in parallel across VUSB and VSS *
'***************************************************************************
'--- if you use these, you must comment the ones in the .inc file ---
@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H
@ __CONFIG _CONFIG3H, _CCP2MX_OFF_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
DEFINE OSC 48
CLEAR
;--- Setup Interrupts ------------------------------------------------------
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_Handler
endm
INT_CREATE ; Creates the interrupt processor
endasm
;--- Setup USB -------------------------------------------------------------
INCLUDE "DT_HID260.pbp"
DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "Mr E/DT/RH"
DEFINE USB_PRODUCTNAME "USBLabX1"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 8 ; IN report is PIC to PC (8,16,32,64)
DEFINE USB_OUTSIZE 8 ; OUT report is PC to PIC
DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10
; --- Each USB status LED is optional, comment them if not used ------------
; --- They can be assigned to any pin, and no further action is required ---
DEFINE USB_LEDPOLARITY 1 ; LED ON State [0 or 1] (default = 1)
DEFINE USB_PLUGGEDLED PORTD,0 ; LED indicates if USB is connected
DEFINE USB_TXLED PORTD,1 ; " " data being sent to PC
DEFINE USB_RXLED PORTD,2 ; " " data being received from PC
;--- Setup Port directions -------------------------------------------------
TRISA = %00000000 ' Set port A pins to output
TRISB = %00000001 ' Set port B pins to 7 output, 1 input
TRISC = %00000000 ' Set all port C pins to output
TRISD = %00000000 ' Set all port D pins to output
TRISE = %00000000 ' Set all port E pins to output
;--- Variables -------------------------------------------------------------
DummyByte VAR BYTE ' Was used for analog logic by original demo
WS_BYTE VAR BYTE
WS_LOOP VAR WORD
;--- Initialize ------------------------------------------------------------
ADCON1 = %00001111 ; Digital
INTCON2 = %00000000 ; I need this for keypad on Lab X1, pull-up resistors
PORTB = %00000000 ; I need this for keypad on Lab X1
; Port B.0 is set high from output of Port B.4
PORTD.3 = 0 ' Clear LED
;--- The Main Loop ---------------------------------------------------------
Main:
FOR WS_LOOP = 0 to 250 ' Very basic debounce for keypress
@ ON_USBRX_GOSUB _HandleRX
PAUSE 1
NEXT WS_LOOP
IF PortB.0 = 0 then
ARRAYWRITE USBTXBuffer, ["Button "]
IF Plugged THEN GOSUB DoUSBOut ; only send when USB is connected
ENDIF
GOTO Main
end
;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle ---------------
HandleRX:
ARRAYREAD USBRXBuffer,[WS_BYTE, DummyByte, DummyByte, DummyByte, DummyByte]
TOGGLE PORTD.3 ' Turn LED ON/OFF
return
Robert
Bookmarks