Posts moved from here:
http://www.picbasic.co.uk/forum/showthread.php?t=4529
to make a new thread for Jim.
Hi,
I'm trying to get LABXUSB code to work which is a basic USB transmit/receive demo of USB. I get the same list of errors as above.
I've copied the contents of PBP\USB18 into the folder containing the LABXUSB.BAS file. I then open the LABXUSB.BAS file in microcode studio plus, and push F9 to compile it, and still I get the above error list...
Am I missing something very obvious (usual!)? Is there a tick box somewhere?
Best regards, and a belated happy new year to all!
Cheers
Jimbo
The LABXUSB.BAS is listed below:
Code:
INCLUDE "LABXUSB.INC"
' NOTE: USBBuffer(0) "aliased here as CMDByte" holds BufferOut(1) output
' from EasyHID.
' For inbound data packets, the value in CMDByte indicates what data the
' host application has requested. For outbound data packets "stuff the PIC
' is sending back", the value indicates to the host what data the PIC is
' returning.
' ************************************************************
' * main program loop - remember, you must keep the USB *
' * connection alive with a call to USBService every couple *
' * of milliseconds or so... *
' ************************************************************
Main:
' These are enabled only for routines in USBDriverService
' to cause a response when interrupt flag bits are tested
@ BCF PIE2, USBIE ; Disable USB interrupts
@ BSF UIE, ACTVIE ; Enable USB Bus Activity Detect Interrupt
@ BSF UIE, IDLEIE ; Enable USB Idle Detect Interrupt
usbinit ' initialise USB...
ProgramStart:
' GOSUB USB_Interrupts
gosub DoUSBIn
' Find out which command we've received from the USB host
' and process the request.
IF CMDByte = "R" THEN RelayControl
IF CMDByte = "Z" THEN ShowStatus
goto ProgramStart
' ************************************************************
' * Control & data gathering routines *
' ************************************************************
ShowStatus:
ADCIN 0, Temp ' Read A/D channel 0 into Temp variable
' Load USB buffer with command & data
CMDByte = "A" ' USBBuffer(0) = "A"
USBBuffer(1) = Temp.HighByte
USBBuffer(2) = Temp.LowByte
GOSUB DoUSBOut ' Send data to USB host
GetTemp: ' Read temperature from Dallas 1-wire DS18B20 temp sensor
OWOut DQ, 1, [$CC, $44] ' Skip ROM search & do temp conversion
Wait_Up:
OWIn DQ, 4, [Busy] ' Read busy-bit
if Busy = 0 Then Wait_Up ' Still busy..?, Wait_Up..!
OWOut DQ, 1, [$CC, $BE] ' Skip ROM search & read scratchpad memory
OWIn DQ, 2, [Temp.Lowbyte, Temp.Highbyte]' Read two bytes / end comms
' Load USB buffer with command & data
CMDByte = "T" ' USBBuffer(0) = "T"
USBBuffer(1) = Temp.HighByte
USBBuffer(2) = Temp.LowByte
' Turn ON relay if Temperature is > 25 deg C
' Just an example. Comment this out if not used.
IF (Temp >> 4) > 25 THEN
HIGH LED
ELSE
LOW LED
ENDIF
GOSUB DoUSBOut ' Send data to USB host
CMDByte = "L" ' USBBuffer(0) = "L"
IF LED = 1 THEN ' Read output pin
USBBuffer(1) = "O"
USBBuffer(2) = "N"
USBBuffer(3) = " "
ENDIF
IF LED = 0 THEN ' Read output pin
USBBuffer(1) = "O"
USBBuffer(2) = "F"
USBBuffer(3) = "F"
ENDIF
GOSUB DoUSBOut
GOTO ProgramStart
RelayControl:
CMDByte = "L" ' USBBuffer(0) = "L"
IF USBBuffer(7) = "1" THEN
HIGH LED ' LED or relay ON
' Load ON status into buffer
' This informs the USB host as to relay status
USBBuffer(1) = "O"
USBBuffer(2) = "N"
USBBuffer(3) = " "
ENDIF
IF USBBuffer(7) = "0" THEN
LOW LED ' LED or relay OFF
' Load OFF status into buffer
' This informs the USB host as to relay status
USBBuffer(1) = "O"
USBBuffer(2) = "F"
USBBuffer(3) = "F"
ENDIF
GOSUB DoUSBOut ' Send data to USB host
GOTO ProgramStart
END
Bookmarks