I use two LM34s with a 16f876 and it's been rock solid with the following snippetts....
Code:
DEFINE LOADER_USED 1
DEFINE OSC 4
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
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
'Subroutine to get room temperature
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
roomdegrees:
FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 2, roomtemp ' Read channel 2 into temp variable
samples = samples + roomtemp ' Accumulate 20 samples
NEXT sample
roomtemp = samples/20
samples = 0 ' Clear old sample accumulator
SerOut2 PORTC.6,SPbaud, [$00, $80, $29,roomtemp] 'update siteplayer with room temperature
if r7sched = 0 then return 'manual control = 0, auto control = 1
if roomtemp >= roomspt + 1 then
SerOut2 PORTC.6,SPbaud, [$00, $80, $3C,1] 'update siteplayer with exhaust status on
checkrelays = 1
endif
if roomtemp <= roomspt - 1 then
SerOut2 PORTC.6,SPbaud, [$00, $80, $3C,0] 'update siteplayer with exhaust status off
checkrelays = 1
endif
return
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
'Subroutine to get tank temperature
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
tankdegrees:
FOR sample = 1 TO 20 ' Take 5 samples
ADCIN 4, watertemp ' Read channel 4 into watertemp variable
samples = samples + watertemp ' add 5 samples
NEXT sample
watertemp = samples/20
samples = 0 ' Clear old samples
SerOut2 PORTC.6,SPbaud, [$00, $80, $28,watertemp] 'update siteplayer with water temperature
if r8sched = 0 then return 'manual control = 0, auto control = 1
if watertemp > waterspt then
serOut2 PORTC.6,SPbaud, [$00, $80, $3D,0] 'update siteplayer with heater status off
checkrelays = 1
endif
if watertemp <= waterspt - 1 then
SerOut2 PORTC.6,SPbaud, [$00, $80, $3D,1] 'update siteplayer with heater status on
checkrelays = 1
endif
return
I know you're using a different micro but maybe this will help some.
Bookmarks