I think i have 75% of my code working except for the following:
The main purpose of the PIC is to look for button pushes on the PIC inputs and perform a specific task depending on which buttons are pushed. However, when a VB application is loaded, any of the variables which are set in the VB program and sent to the PIC via USB are then used by the PIC for timing functions.
Its basically a programmable timer, where the VB program is being used to set the timing variables.
However, the PIC code at the moment is ignoring the button inputs until you send the data from VB to the PIC.
So, push a button, nothing happens. Keep a button held AND send data from VB to the PIC and it recognises the button push. Push button again on its own and nothing happens, until of course you hold the button down AND send data again.
Can anyone figure out whats going wrong by looking at this code.
I'm guessing once you Gosub DoUSBIn this keeps looping until some data is received. Is there a way to set it so that if no data is exchanged, it comes out of the loop. ie perform primary function, but always look at USB for any possible data, if none continue with primary function. As the need to send data from VB to the PIC is minimal. ie once the timing variables are sent, the need to change them from time to time is minimal. If i comment out the Gosub DoUSBIn line, the primary function of the PIC works fine.Code:DEFINE OSC 20 DEFINE LOADER_USED 1 ' ---------- [ I/O Definition ] ---------- TRISA = %11111111 ' Set PORTA to all input TRISB = %10000001 ' Set PORTB (0)INPUT (1-5)OUTPUTS TRISC = %00000111 ' Set PORTC (0-2 input) rest Outputs PORTB = 0 ' ----- [ Variable Definitions ] ---------- Loop Var Byte MaskSwitch Var Byte DelayOut Var Byte Seconds Var byte ' 0-59 SecondsDelay Var byte Minutes Var byte ' 0-59 MinutesDelay Var byte Hours Var byte ' 0-23 HoursDelay Var byte SecondsDelayOut Var Byte MinutesDelayOut Var Byte HoursDelayOut Var Byte ' the USB buffer... USBBuffer Var Byte[USBBufferSizeMax] USBBufferCount Var Byte USBBufferSizeMax con 32 ' maximum buffer size USBBufferSizeTX con 32 ' input USBBufferSizeRX con 32 ' output ' ----- [ Variable Constants ] ---------- HoursDelay = 0 MinutesDelay = 2 '1 To 60 SecondsDelay = 0 '1 To 60 ' ---------- [ System Inputs ] ---------- SW1 Var PORTC.0 SW2 Var PORTC.1 ' ---------- [ System Outputs ] ---------- Red VAR PORTB.1 ' All LEDs connected ' between RC pins and ' ground via resistor ' ************************************************************ ' * Main Program Section * ' * main program loop - remember, you must keep the USB * ' * connection alive with a call to USBService every couple * ' * of milliseconds or so... * ' ************************************************************ usbinit ' initialise USB... Main: Gosub DoUSBIN Gosub DoUSBoUT MaskSwitch=PORTC & $07 Select Case MaskSwitch Case 1 '%00000001 If SW1=1 Then Gosub Procedure_SW1 If SW1=0 THEN EndIf Case 2 '%00000010 If SW2=1 Then Gosub Procedure_SW2 If SW2=0 THEN EndIf Case Else Goto Main End Select Goto Main ' ************************************************************ ' * receive data from the USB bus * ' ************************************************************ DoUSBIn: USBBufferCount = USBBufferSizeRX ' RX buffer size USBService ' keep connection alive USBIn 1, USBBuffer, USBBufferCount, DoUSBIn ' read data, if available Return ' ************************************************************ ' * wait for USB interface to attach * ' ************************************************************ DoUSBOut: USBBufferCount = USBBufferSizeTX ' TX buffer size USBService ' keep connection alive USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data Return Procedure_SW1: 'Do Something Return Procedure_SW2: ' Do Something Else Return
Many thanks.




Bookmarks