Hi All,

Please see code below, I have it hooked it up to a Bluetooth device and it is working great, not sure about the A/D routine and whether I got it set correctly and reading the correct values, can someone please check:?..;-)

Many Thanks,

Gavo

Include "MODEDEFS.BAS" ' Include Shiftin/out modes

DEFINE OSC 20
Define LOADER_USED 1



Define ADC_BITS 12 ' Set number of bits in result
Define ADC_CLOCK 0 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

AD_Raw VAR WORD' 10-bit result of A/D conversion
AD_Result VAR WORD' Quantasized ADC result
Average VAR WORD' Variable for building up the average result
Samples VAR BYTE' Amount of samples taken
Volts VAR BYTE' Holds the Volts part of the result (only for display purposes)
Millivolts VAR WORD' Holds the Millivolts part of the result (only for display purposes)
adval VAR WORD' Create adval to store result
Quanta CON 1250 'quanta level = (5/1024) * 256 == 1250

' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h
' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 24h
' Set baud rate
DEFINE HSER_BAUD 115200
' Set SPBRG directly (normally set by HSER_BAUD)
DEFINE HSER_SPBRG 10


B0 VAR BYTE
B1 VAR BYTE
B2 VAR WORD
B3 VAR WORD
B4 VAR word
B5 VAR WORD
B6 VAR WORD
B7 VAR BYTE
B8 VAR BYTE
B9 VAR BYTE
B10 VAR WORD

ADCON0 = %00000011
ADCON1 = %10000010

TRISC.7 = 1
TRISC.6 = 0
pause 100

goto loop1

loop1:

HSEROUT["Volt and Millivolts Check...", 13,10]
Average=0 ' Clear the Average variable befor use
For Samples=0 TO 9 ' We will take 100 samples of the ADC
ADCIN 0,AD_Raw ' Place the conversion of channel0 into AD_RAW
Average=Average+AD_Raw ' Build up the Average result
Next ' Close the loop
Average=Average/10 ' Calculate the average by dividing by the number of samples taken
AD_Result=(Average) */ Quanta' Quantasize the result
Adval=AD_Result

volts = ad_result / 1000
millivolts = ad_result // 1000

lcdout $FE,$C0,#Volts ,".",#millivolts,"mV"
Hserout ["Measure ", #volts, ".", #millivolts,"mV",10, 13] ' Send text followed by carriage return and linefeed
PAUSE 1500
GOTO LOOP1



END