Quote Originally Posted by louislouis View Post
Try this:
Code:
INTCON = 0 ' NO INTERRUPT
ADCON1 = 001110 '
ADCON0 = 0101 'Disable Converter Module
ANSEL = 000001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
CMCON = 7 
TRISA = 001111 ' impostazioni INP/OUT
TRISB = 000000 ' delle porte
'----------------------------------------------------

temp var word
temperature var word
samples var word

sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte

Tmin=16
Tmax=30

  
  
temp = 0 'Clear temp register
temperature = 0 'Clear temperature register
sample = 1 'Clear sample register
samples = 0 'Clear samples register

PORTA.6=0
   
do
samples=0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= (temp*10) */ quanta


Pause 200 ' Timeout for LCD to settle
LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0

      
If temperature/1000 > Tmax then
PORTA.6=1
else
PORTA.6=0
Endif
loop
it's all very strange!
Testing the code with temperature / 1000 in the same way PORTA.6 goes ON
Not even dividing by 1000 is it possible to obtain the right comparison


Then I added the Do .. loop and everything went crazy.
The room temperature changed with each cycle and the DOOR. 6 went its own without ON and OFF criteria without considering the temperature.