Steve,
You're dealing with bytes. PORTA.1 = USBBuffer[1] isn't the way to go since you can't place a byte value on a single port "bit".
Just place the byte you need on the whole port. You can send a single byte value from the PC app, and simply place it on the port.
I.E. PORTA = USBBuffer[1] should work fine - assuming that's the byte element you want.
Sending data from the PIC to PC is equally simple. Here's one example. Note this isn't everything. Just the sections I added to the framework file created with EasyHID.
Code:
DEFINE OSC 48
DEFINE LOADER_USED 1
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 ' <-- I used the Microchip USB loader
BufferSize con 8
DataBuffer Var Byte(BufferSize) ' data buffer
DataBufferCount Var Byte ' buffer size
Quanta con 1251
TRISD = 0
PORTD = 0
' 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
PORTD = 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
On the PC side, modify the USB framework file created with EasyHID something like this;
Dim MyText As String ' create your string storage space
In the OnRead sub-routine;
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
Judy,
Reading three pulse widths or A/D values doesn't really have anything to do with USB. The USB PIC is just another PIC with the addition of the USB module. Using the onboard A/D is pretty much the same as any other PIC.
All you need here is the datasheet, and a little time to experiment getting your pulse measurement & A/D routines working. Sending this all to the PC via the USB module is no more than stuffing your values into the outgoing buffer like in the previous example.
Just be sure to keep the USB connection alive by avoiding the use of blocking functions, long delays, etc,,. It's really not that hard, but you will need to experiment a tad.
Bookmarks