Great, thanks Bruce. Unfortuanatly i am still getting a big 0 in VB. I'm sure its only something small i am doing wrong (hopefully) !!
Here is the code, can you spot anything obvious that i have done wrong?
Its a PIC18F2455 where i am putting 5v onto RA0.
Code:
DEFINE LOADER_USED 1
DEFINE OSC 48
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source /32
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
'DEFINE RESET_ORG 800h ' For Microchip USB loader
BufferSize con 8
DataBuffer Var Byte(BufferSize) ' data buffer
DataBufferCount Var Byte ' buffer size
Quanta con 1251
' Variables
X VAR byte
Adval VAR WORD
TRISA.0 = 1 ' RA0 input
ADCON1 = %00001110 ' A/D channel 0
ADCON2 = %10000011 ' Right justify for 10-bit
USBInit
Main:
GOSUB DoUSBIn
PORTB = DataBuffer[7]
ADCIN 0,Adval ' Read A/D channel 0 into ADval variable
ADval = ADval */ Quanta ' Quanta result
' Load data buffer
DataBuffer(0) = Adval dig 3
DataBuffer(1) = "."
DataBuffer(2) = Adval DIG 2
DataBuffer(3) = Adval DIG 1
DataBuffer(4) = Adval DIG 0
GOSUB DoUSBOut
FOR X = 0 to 99 ' Short delay between updates
PAUSEUS 1000
USBSERVICE ' Maintain HID connection during delay period
NEXT X
GOTO Main
' ************************************************************
' * receive data from the USB bus *
' ************************************************************
DoUSBIn:
DataBufferCount = BufferSize
USBService
USBIn 1, DataBuffer, DataBufferCount, DoUSBIn
RETURN
' ************************************************************
' * wait for USB interface to attach *
' ************************************************************
DoUSBOut:
DataBufferCount = BufferSize
USBService
USBOut 1, DataBuffer, DataBufferCount, DoUSBOut
RETURN
END
In VB, i have placed a label on the form and this is in the read event section
Code:
'*****************************************************************
' on read event...
'*****************************************************************
Public Sub OnRead(ByVal pHandle As Long)
' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
MyText = (CStr(BufferIn(1)) + Chr$(BufferIn(2)) + CStr(BufferIn(3)) + CStr(BufferIn(4)) + CStr(BufferIn(5)) + "V")
Label1.Caption = MyText ' Place string text into label displaying A/D value
' ** YOUR CODE HERE **
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontrolller...
End If
End Sub
Many thanks again.
Steve
Bookmarks