Hi i've recently begun experimenting with the 18F4550 i've got a working example program that lets me flash an led connected to PORTB.7, I use VB6 on the PC side.
Basically my project has been halted by an unexpected problem in compiling some code added to work the A/D. Both Bruce's USB_AD.zip example and my own code cannot compile this:
ADCON1 = %00001110 ' A/D channel 0
ADCON2 = %10000011 ' Left justify for 10-bit
I get a syntax error.... any ideas - full code posted below.
I'm running version 2.2.1.1 of microcode studio. I'm using the new beta program for the EPIC parallel programmer (with the 40 pin adapter)
DEFINE OSC 20
DEFINE LOADER_USED 1
'ADC defines
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
Quanta con 1251
Adval VAR WORD
USBBufferSizeMax con 64 ' maximum buffer size
USBBufferSizeTX con 64 ' input
USBBufferSizeRX con 64 ' output
' the USB buffer...
USBBuffer Var Byte[USBBufferSizeMax]
USBBufferCount Var Byte
x VAR BYTE
TRISA.0 = 1 ' RA0 input
ADCON1 = %00001110 ' A/D channel 0
ADCON2 = %10000011 ' Left justify for 10-bit
usbinit ' initialise USB...
x = 0
LOW PORTB
BlinkLED:
if x = 7 then ProgramStart
x = x + 1
HIGH PORTB.7
PAUSE 1000
LOW PORTB.7
PAUSE 500
goto blinkLED
ProgramStart:
x = 0
gosub DoUSBIn
gosub DoUSBOut
goto ProgramStart
' ************************************************** **********
' * 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
if usbbuffer[2] = 1 then
high portb.7
ENDIF
IF USBbuffer[2] = 0 THEN
LOW portb.7
ENDIF
goto DoAD
return
DoAD:
ADCIN 0,adval ' Read A/D channel 0 into ADval variable
ADval = ADval */ Quanta ' Quanta result
' Load data buffer
USBBuffer[0] = Adval dig 3 'Y.LowByte
USBBuffer[1] = "."
USBBuffer[2] = Adval DIG 2
USBBuffer[3] = Adval DIG 1
USBBuffer[4] = aDVAL DIG 0
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
Bookmarks