18f2525 with LM34
I've spent the last 2 days working on this and can't seem to solve my problem.
I have a 18f2525 @ 20Mhz connected to a LM34 Temperature sensor on RA5(AN4).
I have a pot connected to RA3 (+Vref) with 2.55 volts on RA3.
I've used Bruce's code, with some changes to suit my app.
I read .68 volts on pin 7 but get bogus numbers on the PC.
"Temperature is 38 Degrees"
"Temperature is 5 Degrees"
I've tried manipulating ADCON0, ADCON1, and ADCON2 with no success.
Here is the code as it was for my last attempt.
<code>
DEFINE LOADER_USED 1 ' Boot loader is being used
define OSC 20 ' We're using a 4 MHz oscillator
DEFINE HSER_RCSTA 90h 'setup receive register
DEFINE HSER_TXSTA 20h 'setup transmit register
DEFINE HSER_BAUD 38400 'setup baud rate
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 3 ' Set A/D clock
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS
samples VAR WORD ' Multiple A/D sample accumulator
sample VAR BYTE ' Holds number of samples to take
temp VAR BYTE ' Temperature storage
samples = 0 ' Clear samples accumulator on power-up
PORTA = %00000000
TRISA = %11111111 ' Set PORTA to all input
'ADCON0 = %00010001
ADCON1 = %00011010 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
'ADCON2 = %00111011
PAUSE 500 ' Wait .5 second
loop:
FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 5, temp ' Read channel 0 into temp variable
samples = samples + temp ' Accumulate 20 samples
PAUSE 250 ' Wait approximately 1/4 seconds per loop
NEXT sample
temp = samples/20
samples = 0 ' Clear old sample accumulator
GoSub hyperview
GOTO loop ' Do it forever
hyperview:
HSerout ["Temperature is ",dec temp," Degrees", 13,10]
'pause 1000
Return
END
</code>
I'm sure it's something simple, It just hasn't jumped out at me yet.
Any help would be apreciated.
PBP v2.45A, MCSP, MPASM and Microcode Loader
"It will never happen here!" just happened here.
My thoughts and prayers for Sandy Hook victims and families.
Bookmarks