Compare value ...

1. Compare value ...

Hi good morning everyone,
i have a little project on PIC16F88 whit LM35.
When temperature go over Tmax Portb.6 go High.

I don't understand how to compare values

On the lCD display i have 3 value
Temp from Lm35
Tmax from eprom
Tmin from eprom

but i don't undesrstand why portb.6 go always High also if the temperature Tmax is low

thank you

the code is

temp var word
temperature var word
samples var word
sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte

Tmin=DatoEE

Tmax=DatoEE

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

FOR sample = 1 TO 20 'Take 20 samples
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 > Tmax then
PORTA.6=1
Endif

2. Re: Compare value ...

DatoEE is never defined
i see that no data is stored to eeprom therefore tmax and tmin = 255

then --
Code:
```If temperature > Tmax then
PORTA.6=1
Endif```
why would porta.6 change if temperature < Tmax your code only sets the pin it never clears it
the initial state of pin should also be set , there is no code visible to set trisb either

Code:
```If temperature > Tmax then
PORTA.6=1
else
PORTA.6=0
Endif```

this makes me wonder what your actual fosc is , you posted no config section and there is no OSC definition
Code:
`PAUSE 50 ' Wait 1/4 seconds per reading`

3. Re: Compare value ...

Hi, Forgive me, your questions are legitimate, I tried to post a surrogate code so as not to stretch too much, but I think I have created confusion.

anyway :

DatoEE is never defined
i see that no data is stored to eeprom therefore tmax and tmin = 255

' EEPROM Locations
'================================================= ==========================
DATA @0,16 ' 16 Tenp min.
DATA @1,30 ' 30 Temp Max.
'================================================= ==========================

then temp is 20 to 24 °C (ambiental)
Tmax is set 30°C

the configuration is

' -------- bit a bit controllo 0=output 1=input

INTCON = 0 ' NO INTERRUPT
ADCON0 = %00000101 'Disable Converter Module
ANSEL = %00000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
CMCON = 7 '
'76543210
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = %00000000 ' delle porte
'----------------------------------------------------

the string
PAUSE 50 ' Wait 1/4 seconds per reading

only reports an incorrect comment

so my problem is, i believe:
temperature is a word
Tmax is a byte

and I don't understand how compare the values

4. Re: Compare value ...

Hi, Forgive me, your questions are legitimate, I tried to post a surrogate code so as not to stretch too much, but I think I have created confusion.

anyway :

DatoEE is never defined
i see that no data is stored to eeprom therefore tmax and tmin = 255

' EEPROM Locations
'================================================= ==========================
DATA @0,16 ' 16 Tenp min.
DATA @1,30 ' 30 Temp Max.
'================================================= ==========================

then temp is 20 to 24 °C (ambiental)
Tmax is set 30°C

the configuration is

' -------- bit a bit controllo 0=output 1=input

INTCON = 0 ' NO INTERRUPT
ADCON0 = 000101 'Disable Converter Module
ANSEL = 000001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
CMCON = 7 '
'76543210
TRISA = 111111 ' impostazioni INP/OUT
TRISB = 000000 ' delle porte
'----------------------------------------------------

the string
PAUSE 50 ' Wait 1/4 seconds per reading

only reports an incorrect comment

so my problem is, i believe:
temperature is a word
Tmax is a byte

and I don't understand how compare the values

5. Re: Compare value ...

Hi, Forgive me, your questions are legitimate, I tried to post a surrogate code so as not to stretch too much, but I think I have created confusion.

anyway :

DatoEE is never defined
i see that no data is stored to eeprom therefore tmax and tmin = 255

' EEPROM Locations
'================================================= ==========================
DATA @0,16 ' 16 Tenp min.
DATA @1,30 ' 30 Temp Max.
'================================================= ==========================

then temp is 20 to 24 °C (ambiental)
Tmax is set 30°C

the configuration is

' -------- bit a bit controllo 0=output 1=input

INTCON = 0 ' NO INTERRUPT
ADCON0 = %00000101 'Disable Converter Module
ANSEL = %00000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
CMCON = 7 '
'76543210
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = %00000000 ' delle porte
'----------------------------------------------------

the string
PAUSE 50 ' Wait 1/4 seconds per reading

only reports an incorrect comment

so my problem is, i believe:
temperature is a word
Tmax is a byte

and I don't understand how compare the values

6. Re: Compare value ...

Try:

1.

2.
Display your variables on LCD or a serial port to be sure what values they are

Ioannis

7. Re: Compare value ...

Originally Posted by Ioannis
Try:

1.
with this the Pic16F88 not working

Originally Posted by Ioannis
2.
Display your variables on LCD or a serial port to be sure what values they are
Display on LCD
24.5 °C
Tmin 16 Tmax 30

cdout \$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

My problem is, i think:
temperature is a word
Tmax is a byte

and I don't understand how compare the values

8. Re: Compare value ...

Don't you see? You display a decimal number but the number is in fact 245 and not 24.5!

So, maybe you can use word variables and multiply them by 10 so you can compare 245 to 160 and 300.

My first suggestion was to make sure that bit 0 of ADCON0 was set. It needs some time and if you go fast to start ADC, the module might not work as expected. I am sorry that I made the mistake of bit 0 to 2. Please include it as this:

Code:
```ADCON0=%10000101
I would not set bit 2 at this stage but anyway.

Ioannis

9. Re: Compare value ...

Originally Posted by Ioannis

Code:
```ADCON0=000101

OK, Perfect this work well now

Originally Posted by Ioannis
Don't you see? You display a decimal number but the number is in fact 245 and not 24.5!

So, maybe you can use word variables and multiply them by 10 so you can compare 245 to 160 and 300.

Ioannis
I have modified code in this mode, but don't work yet

If temperature > (Tmax*10) then
PORTA.6=1
else
PORTA.6=0
Endif

PORTA.6 go high when power on after showing the values on the display

NOTE :
The variables are still "temperature WORD" and "Tmax BYTE". I tried to change Tmax from BYTE to WORD in the declaration area but it gives me an error when compile

10. Re: Compare value ...

You should make it word. 30*10=300 > than a byte can hold.
Also better make the multiplication outside the comparison.

Use the LCD as a monitor to check your values.

About compilation, I guess it is a syntax error thing.

Ioannis

11. Re: Compare value ...

Originally Posted by Ioannis
You should make it word. 30*10=300 > than a byte can hold.
Also better make the multiplication outside the comparison.

Use the LCD as a monitor to check your values.

About compilation, I guess it is a syntax error thing.

Ioannis
hi,

I have define Tcomp VAR WORD
and now i have :

Code:
```tcomp=tmax*100

lcdout \$FE, 2,   "Temp. ",dec2 (temperature/100),".", dec1 (temperature//100),\$DF,"C "
lcdout \$FE, \$C0, "Tmax ",#Tmax DIG 1,#Tmax Dig 0," Tco ",dec2 (Tcomp/100),".", dec1 (Tcomp//100)```
On display i see :

Temp. 23.5°C
Tmax 30 Tco 30.0

And PORTA.6 go at 1 the same

12. Re: Compare value ...

Try this:
Code:
```INTCON = 0 ' NO INTERRUPT
ADCON0 = %000101 'Disable Converter Module
ANSEL = %00000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
CMCON = 7
TRISA = %10001111 ' impostazioni INP/OUT
TRISB = %00000000 ' 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
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```

13. Re: Compare value ...

Originally Posted by louislouis
Try this:
Code:
```INTCON = 0 ' NO INTERRUPT
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
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.

15. Re: Compare value ...

Originally Posted by louislouis
Code:
```'****************************************************************
'*  Name    : 16F88_LM235.BAS                                   *
'*  Author  :                                    *
'*  Notice  : Copyright (c) 2020                                *
'*  Date    : 04/04/2020                                        *
'*  Version : 1.0                                               *
'*
'****************************************************************
'PIC 16F88
'    Hardware Assignments
'    --------------------
' LCD circuitery
'01     - Vss (GND)
'02     - Vdd (+5V)
'08 RS  - PORTB.2
'09 E   - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7

DEFINE LCD_DREG PORTB       'Porta B DATA OUT
DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7

DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2

DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3

DEFINE LCD_BITS 4           'LCD bus size 4 or 8
DEFINE LCD_LINES 2          'Number lines on LCD

DEFINE LCD_COMMANDUS 2000   'Command delay time in us
DEFINE LCD_DATAUS 50        'Data delay time in us

'    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'===========================================================================
DATA @0,16  '   16 Tenp min.
DATA @1,30  '   30 Temp Max.
'===========================================================================

'===========================================================================
'*****  SETTAGGIO PORTE

'      VAR      PORTA.0     'LM235M            Pin 17
IncButton    VAR    PORTA.1     'SW          Pin 18
DecButton    VAR    PORTA.2     'SW          Pin 1
SetButton    VAR    PORTA.3     'SW          Pin 2
'      VAR    PORTA.4     '                  Pin 3
'      VAR    PORTA.5     '                  Pin 4
Rele   VAR    PORTA.6     '                  Pin 15
'      VAR    PORTA.7     '                  Pin 16
'-----------------------------------------------
'       Var       PORTB.0   '                   Pin  6
'       var    PORTB.1   '                   Pin  7
l_rs    var       PORTB.2   'LCD  sig. RS       Pin  8
l_en    Var    PORTB.3   'LCD sig. E         Pin  9
l_d4    var       PORTB.4   'LCD 4              Pin 10
l_d5    var    PORTB.5   'LCD 5              Pin 11
l_d6    var    PORTB.6   'LCD 6              Pin 12
l_d7    var    PORTB.7   'LCD 7              Pin 13

'--------------------------------------------------------------

DEFINE ADC_BITS 10      'set number of bits in result
DEFINE ADC_CLOCK 3      'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS

'    RAM Assignments and Variables
'===========================================================================
CounterA    var byte    ' General purpose Variable
CounterB    var byte    ' General purpose Variable
CounterC    var byte    ' General purpose Variable
temp        var word
temperature var word
samples     var word
Dummy       var word
sample      VAR BYTE
quanta      con 1250
DatoEE      var byte
Tmax        VAR Byte
Tmin        VAR Byte
Tcomp       VAR word
TimeOut     var word    ' Variable for SetUp Menu Time-Out
'===========================================================================

START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

' --------  bit a bit controllo 0=output  1=input

INTCON = 0           ' NO INTERRUPT
while !adcon0.0:wend ' Attende che il convertitore sia spento prima di fare il resto
ANSEL  = 000001   'Disable Inputs Tranne AN0
OSCCON = 100000   'Internal RC set to 4MHZ
CMCON  = 7           '
'76543210
TRISA  = 111111   ' impostazioni INP/OUT
TRISB  = 000000   ' delle porte
'----------------------------------------------------

' Per utilizare i pin RA6 ed RA7 come I/O bisogna impostare lo switch in fase
' di programmazione Oscillotar come "INTRC_IO"
PORTA.6=0

'    Leggi Dati dalla EEPROM
'===========================================================================
Tmin=DatoEE

Tmax=DatoEE
'===========================================================================

Lcdout \$FE, 1           'Clear screen

MAIN:

'Subroutine to measure temp
'----------------------------------------------------
temp = 0                            'Clear temp register
temperature = 0                     'Clear temperature register
sample = 0                          'Clear sample register
samples = 0                         'Clear samples register

do
sample = 0
FOR sample = 1 TO 20                'Take 20 samples
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> TMax then
PORTA.6=1
else
PORTA.6=0
Endif

'lcdout \$FE, \$C0, "Tmax ",#Tmax DIG 1,#Tmax Dig 0," Tco ",dec2 (Tcomp/100),".", dec1 (Tcomp//100)
loop

goto MAIN
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~```

16. Re: Compare value ...

Try this:

Code:
```'****************************************************************
'*  Name    : 16F88_LM235.BAS                                   *
'*  Author  :                                    *
'*  Notice  : Copyright (c) 2020                                *
'*  Date    : 04/04/2020                                        *
'*  Version : 1.0                                               *
'*
'****************************************************************
'PIC 16F88
'    Hardware Assignments
'    --------------------
' LCD circuitery
'01     - Vss (GND)
'02     - Vdd (+5V)
'08 RS  - PORTB.2
'09 E   - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7

' --------  bit a bit controllo 0=output  1=input

INTCON = 0 ' NO INTERRUPT
ADCON0 = %000101 'Disable Converter Module
ANSEL = %00000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
CMCON = 7
TRISA = %10001111 ' impostazioni INP/OUT
TRISB = %00000000 ' delle porte
'----------------------------------------------------

DEFINE LCD_DREG PORTB       'Porta B DATA OUT
DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7

DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2

DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3

DEFINE LCD_BITS 4           'LCD bus size 4 or 8
DEFINE LCD_LINES 2          'Number lines on LCD

DEFINE LCD_COMMANDUS 2000   'Command delay time in us
DEFINE LCD_DATAUS 50        'Data delay time in us

'    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'===========================================================================
'===========================================================================

'===========================================================================
'*****  SETTAGGIO PORTE

'      VAR      PORTA.0     'LM235M            Pin 17
IncButton    VAR    PORTA.1     'SW          Pin 18
DecButton    VAR    PORTA.2     'SW          Pin 1
SetButton    VAR    PORTA.3     'SW          Pin 2
'      VAR    PORTA.4     '                  Pin 3
'      VAR    PORTA.5     '                  Pin 4
Rele   VAR    PORTA.6     '                  Pin 15
'      VAR    PORTA.7     '                  Pin 16
'-----------------------------------------------
'       Var       PORTB.0   '                   Pin  6
'       var    PORTB.1   '                   Pin  7
l_rs    var       PORTB.2   'LCD  sig. RS       Pin  8
l_en    Var    PORTB.3   'LCD sig. E         Pin  9
l_d4    var       PORTB.4   'LCD 4              Pin 10
l_d5    var    PORTB.5   'LCD 5              Pin 11
l_d6    var    PORTB.6   'LCD 6              Pin 12
l_d7    var    PORTB.7   'LCD 7              Pin 13

'--------------------------------------------------------------

DEFINE ADC_BITS 10      'set number of bits in result
DEFINE ADC_CLOCK 3      'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS

'    RAM Assignments and Variables
'===========================================================================
CounterA    var byte    ' General purpose Variable
CounterB    var byte    ' General purpose Variable
CounterC    var byte    ' General purpose Variable
Dummy       var word
DatoEE      var byte
Tcomp       VAR word
TimeOut     var word    ' Variable for SetUp Menu Time-Out
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

START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Lcdout \$FE, 1           'Clear screen

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

rele=0

main:

samples=0
FOR sample = 1 TO 20 'Take 20 samples
samples = samples + temp
PAUSE 40 ' 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
rele=1
else
rele=0
Endif

goto main```

17. Re: Compare value ...

On your last program, you still have in the room temperature a 3 digit value, say 250 and compare it with the Tmax that is 30.

If temperature is 250 and TMax is 30 what is the result? Portb.6 always set as you requested.

Try this and see if relay makes 2 clicks at the start of the program and then rest of the program works as expected.

If it does not click, then your port has a problem. Search other things...

Code:
```'****************************************************************
'*  Name    : 16F88_LM235.BAS                                   *
'*  Author  :                                    *
'*  Notice  : Copyright (c) 2020                                *
'*  Date    : 04/04/2020                                        *
'*  Version : 1.0                                               *
'*
'****************************************************************
'PIC 16F88
'    Hardware Assignments
'    --------------------
' LCD circuitery
'01     - Vss (GND)
'02     - Vdd (+5V)
'08 RS  - PORTB.2
'09 E   - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7

DEFINE LCD_DREG PORTB       'Porta B DATA OUT
DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7

DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2

DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3

DEFINE LCD_BITS 4           'LCD bus size 4 or 8
DEFINE LCD_LINES 2          'Number lines on LCD

DEFINE LCD_COMMANDUS 2000   'Command delay time in us
DEFINE LCD_DATAUS 50        'Data delay time in us

'    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'===========================================================================
DATA @0,16  '   16 Tenp min.
DATA @1,30  '   30 Temp Max.
'===========================================================================

'===========================================================================
'*****  SETTAGGIO PORTE

'      VAR      PORTA.0     'LM235M            Pin 17
IncButton    VAR    PORTA.1     'SW          Pin 18
DecButton    VAR    PORTA.2     'SW          Pin 1
SetButton    VAR    PORTA.3     'SW          Pin 2
'      VAR    PORTA.4     '                  Pin 3
'      VAR    PORTA.5     '                  Pin 4
Rele   VAR    PORTA.6     '                  Pin 15
'      VAR    PORTA.7     '                  Pin 16
'-----------------------------------------------
'       Var       PORTB.0   '                   Pin  6
'       var    PORTB.1   '                   Pin  7
l_rs    var       PORTB.2   'LCD  sig. RS       Pin  8
l_en    Var    PORTB.3   'LCD sig. E         Pin  9
l_d4    var       PORTB.4   'LCD 4              Pin 10
l_d5    var    PORTB.5   'LCD 5              Pin 11
l_d6    var    PORTB.6   'LCD 6              Pin 12
l_d7    var    PORTB.7   'LCD 7              Pin 13

'--------------------------------------------------------------

DEFINE ADC_BITS 10      'set number of bits in result
DEFINE ADC_CLOCK 3      'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS

'    RAM Assignments and Variables
'===========================================================================
CounterA    var byte    ' General purpose Variable
CounterB    var byte    ' General purpose Variable
CounterC    var byte    ' General purpose Variable
temp        var word
temperature var word
samples     var word
Dummy       var word
sample      VAR BYTE
quanta      con 1250
DatoEE      var byte
Tmax        VAR Byte
Tmin        VAR Byte
Tcomp       VAR word
TimeOut     var word    ' Variable for SetUp Menu Time-Out
'===========================================================================

START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
for sample =0 to 3
toggle portb.6
pause 250
next sample

' --------  bit a bit controllo 0=output  1=input

INTCON = 0           ' NO INTERRUPT
while !adcon0.0:wend ' Attende che il convertitore sia spento prima di fare il resto
ANSEL  = 000001   'Disable Inputs Tranne AN0
OSCCON = 100000   'Internal RC set to 4MHZ
CMCON  = 7           '
'76543210
TRISA  = 111111   ' impostazioni INP/OUT
TRISB  = 000000   ' delle porte
'----------------------------------------------------

' Per utilizare i pin RA6 ed RA7 come I/O bisogna impostare lo switch in fase
' di programmazione Oscillotar come "INTRC_IO"
PORTA.6=0

'    Leggi Dati dalla EEPROM
'===========================================================================
Tmin=DatoEE

Tmax=DatoEE
'===========================================================================

Lcdout \$FE, 1           'Clear screen

MAIN:

'Subroutine to measure temp
'----------------------------------------------------
temp = 0                            'Clear temp register
temperature = 0                     'Clear temperature register
sample = 0                          'Clear sample register
samples = 0                         'Clear samples register

do
sample = 0
FOR sample = 1 TO 20                'Take 20 samples
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

temperature=temperature/10

If temperature> TMax then
PORTA.6=1
else
PORTA.6=0
Endif

'lcdout \$FE, \$C0, "Tmax ",#Tmax DIG 1,#Tmax Dig 0," Tco ",dec2 (Tcomp/100),".", dec1 (Tcomp//100)
loop

goto MAIN
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~```
Ioannis

18. Re: Compare value ...

On your last program, you still have in the room temperature a 3 digit value, say 250 and compare it with the Tmax that is 30.

If temperature is 250 and TMax is 30 what is the result? Portb.6 always set as you requested.
for a Temperature of 30 deg the temperature var would equal 3000 , what 3 digit number are we talking about, the display is to two
decimal points the comparison must be on equal terms
Code:
```If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif```

or

Code:
```If (temperature/100) > Tmax then
rele=1
else
rele=0
Endif```

19. Re: Compare value ...

Yeah Richard. I missed that.

Also he must check if the port is working.

Ioannis

20. Re: Compare value ...

Hi, I added the loop at the beginning of the program:

Code:
```for sample = 0 to 3
rele=1
pause 1000
rele=0
pause 1000
next sample```
Yours was too fast and I didn't hear the clicks. It is now OK, at start-up three times the relay turns ON / OFF, then the display appears.

As always, however, dividing the variable "temperature" by 10 or 100 and multiplying the variable "Tmax" by 10 or 100 the comapration between the two variables fails. and the end result is that the relay goes ON despite the Tmax is set to 30 and the value read by the sensor is 24 ° C (or at least I think, I say 24 ° C because it is what comes out on the display giving the string

Code:
`lcdout \$ FE, 2, "Temp", dec2 (temperatures / 100), ".", dec1 (temperatures // 100), \$ DF, "C")`
If I try to show the pure "Temperature" variable on the display like this:

Code:
`lcdout \$ FE, \$ C0, "TEmpe", temperatures`

an ASCII character appears on the display which changes as the temperature changes.

I'm currently running this code

Code:
```

'****************************************************************
'*  Name    : 16F88_LM235.BAS                                   *
'*  Author  :                                    *
'*  Notice  : Copyright (c) 2020                                *
'*  Date    : 04/04/2020                                        *
'*  Version : 1.0                                               *
'*
'****************************************************************
'PIC 16F88
'    Hardware Assignments
'    --------------------
' LCD circuitery
'01     - Vss (GND)
'02     - Vdd (+5V)
'08 RS  - PORTB.2
'09 E   - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7

' --------  bit a bit controllo 0=output  1=input

INTCON = 0 ' NO INTERRUPT
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
'----------------------------------------------------

DEFINE LCD_DREG PORTB       'Porta B DATA OUT
DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7

DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2

DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3

DEFINE LCD_BITS 4           'LCD bus size 4 or 8
DEFINE LCD_LINES 2          'Number lines on LCD

DEFINE LCD_COMMANDUS 2000   'Command delay time in us
DEFINE LCD_DATAUS 50        'Data delay time in us

'    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'===========================================================================
'===========================================================================

'===========================================================================
'*****  SETTAGGIO PORTE

'      VAR      PORTA.0     'LM235M            Pin 17
IncButton    VAR    PORTA.1     'SW          Pin 18
DecButton    VAR    PORTA.2     'SW          Pin 1
SetButton    VAR    PORTA.3     'SW          Pin 2
'      VAR    PORTA.4     '                  Pin 3
'      VAR    PORTA.5     '                  Pin 4
Rele   VAR    PORTA.6     '                  Pin 15
'      VAR    PORTA.7     '                  Pin 16
'-----------------------------------------------
'       Var       PORTB.0   '                   Pin  6
'       var    PORTB.1   '                   Pin  7
l_rs    var       PORTB.2   'LCD  sig. RS       Pin  8
l_en    Var    PORTB.3   'LCD sig. E         Pin  9
l_d4    var       PORTB.4   'LCD 4              Pin 10
l_d5    var    PORTB.5   'LCD 5              Pin 11
l_d6    var    PORTB.6   'LCD 6              Pin 12
l_d7    var    PORTB.7   'LCD 7              Pin 13

'--------------------------------------------------------------

DEFINE ADC_BITS 10      'set number of bits in result
DEFINE ADC_CLOCK 3      'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS

'    RAM Assignments and Variables
'===========================================================================
CounterA    var byte    ' General purpose Variable
CounterB    var byte    ' General purpose Variable
CounterC    var byte    ' General purpose Variable
Dummy       var word
DatoEE      var byte
Tcomp       VAR word
TimeOut     var word    ' Variable for SetUp Menu Time-Out
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

START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
for sample = 0 to 3
rele=1
pause 1000
rele=0
pause 1000
next sample

Lcdout \$FE, 1           'Clear screen

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

'rele=0

main:

samples=0
FOR sample = 1 TO 20 'Take 20 samples
samples = samples + temp
PAUSE 40 ' 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," TEmpe", temperature

Tmax=Tmax*100

If temperature > Tmax then
rele=1
else
rele=0
Endif

goto main```

21. Re: Compare value ...

Code:
```Tmax=Tmax*100  you cannot do this ,Tmax is a byte var

If temperature > Tmax then
rele=1
else
rele=0
Endif

goto main```

this will work the pbp inline intermediate results are word sized
Code:
```If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif```

22. Re: Compare value ...

Originally Posted by richard

[CODE]

this will work the pbp inline intermediate results are word sized
Code:
```If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif```
I tried, but nothing changes

my code now is :

Code:
```â€‹'****************************************************************'*  Name    : 16F88_LM235.BAS                                   *
'*  Author  :                                    *
'*  Notice  : Copyright (c) 2020                                *
'*  Date    : 04/04/2020                                        *
'*  Version : 1.0                                               *
'*
'****************************************************************
'PIC 16F88
'    Hardware Assignments
'    --------------------
' LCD circuitery
'01     - Vss (GND)
'02     - Vdd (+5V)
'08 RS  - PORTB.2
'09 E   - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7

' --------  bit a bit controllo 0=output  1=input

INTCON = 0 ' NO INTERRUPT
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
'----------------------------------------------------

DEFINE LCD_DREG PORTB       'Porta B DATA OUT
DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7

DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2

DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3

DEFINE LCD_BITS 4           'LCD bus size 4 or 8
DEFINE LCD_LINES 2          'Number lines on LCD

DEFINE LCD_COMMANDUS 2000   'Command delay time in us
DEFINE LCD_DATAUS 50        'Data delay time in us

'    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'===========================================================================
'===========================================================================

'===========================================================================
'*****  SETTAGGIO PORTE

'      VAR      PORTA.0     'LM235M            Pin 17
IncButton    VAR    PORTA.1     'SW          Pin 18
DecButton    VAR    PORTA.2     'SW          Pin 1
SetButton    VAR    PORTA.3     'SW          Pin 2
'      VAR    PORTA.4     '                  Pin 3
'      VAR    PORTA.5     '                  Pin 4
Rele   VAR    PORTA.6     '                  Pin 15
'      VAR    PORTA.7     '                  Pin 16
'-----------------------------------------------
'       Var       PORTB.0   '                   Pin  6
'       var    PORTB.1   '                   Pin  7
l_rs    var       PORTB.2   'LCD  sig. RS       Pin  8
l_en    Var    PORTB.3   'LCD sig. E         Pin  9
l_d4    var       PORTB.4   'LCD 4              Pin 10
l_d5    var    PORTB.5   'LCD 5              Pin 11
l_d6    var    PORTB.6   'LCD 6              Pin 12
l_d7    var    PORTB.7   'LCD 7              Pin 13

'--------------------------------------------------------------

DEFINE ADC_BITS 10      'set number of bits in result
DEFINE ADC_CLOCK 3      'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS

'    RAM Assignments and Variables
'===========================================================================
CounterA    var byte    ' General purpose Variable
CounterB    var byte    ' General purpose Variable
CounterC    var byte    ' General purpose Variable
Dummy       var word
DatoEE      var byte
Tcomp       VAR word
TimeOut     var word    ' Variable for SetUp Menu Time-Out
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

START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
for sample = 0 to 3
rele=1
pause 1000
rele=0
pause 1000
next sample

Lcdout \$FE, 1           'Clear screen

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

'rele=0

main:

samples=0
FOR sample = 1 TO 20 'Take 20 samples
samples = samples + temp
PAUSE 40 ' 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," TEmpe", temperature

If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif

goto main```

23. Re: Compare value ...

lcdout \$FE, \$C0," TEmpe", temperature

what does this line display the temperature value as ?

24. Re: Compare value ...

Originally Posted by richard
lcdout \$FE, \$C0," TEmpe", temperature

what does this line display the temperature value as ?
ASCII code, one strange character, and it changes every time the temperature changes

25. Re: Compare value ...

ASCII code, one strange character, and it changes every time the temperature changes
lcdout \$FE, \$C0," TEmpe", dec temperature

removing all the unused/unecessary stuff " just noise" , using a proper config and displaying a result more in keeping with lm35 accuracy

this works just fine
Code:
```'****************************************************************'*  '*  Name    : 16F88_LM235.BAS                                   *
'*  Author  :                                    *
'*  Notice  : Copyright (c) 2020                                *
'*  Date    : 04/04/2020                                        *
'*  Version : 1.0                                               *
'*
'****************************************************************
#CONFIG
__config  _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
__config  _CONFIG2, _FCMEN_ON & _IESO_ON
#ENDCONFIG
'PIC 16F88
'    Hardware Assignments
'    --------------------
' LCD circuitery
'01     - Vss (GND)
'02     - Vdd (+5V)
'08 RS  - PORTB.2
'09 E   - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7

ANSEL = %000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = 0 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB       'Porta B DATA OUT
DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2
DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4           'LCD bus size 4 or 8
DEFINE LCD_LINES 2          'Number lines on LCD DEFINE LCD_COMMANDUS 2000   'Command delay time in us
DEFINE LCD_DATAUS 50        'Data delay time in us

'    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...

'===========================================================================
'*****  SETTAGGIO PORTE

Rele   VAR    PORTA.6     '                  Pin 15
'--------------------------------------------------------------
DEFINE ADC_BITS 10      'set number of bits in result
DEFINE ADC_CLOCK 3      'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS

'    RAM Assignments and Variables
'===========================================================================
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

START:
Lcdout \$FE, 1           'Clear screen
rele=0

main:
samples=0
FOR sample = 1 TO 20 'Take 20 samples
samples = samples + temp
PAUSE 40 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= temp */ quanta

LCDOUT \$FE, 1 ' cancella LCD
LCDOUT \$FE, 2 ' ritorna al primo carattere
lcdout \$FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature//10),\$DF,"C"
lcdout \$FE, \$C0," TEmpe", dec temperature

If temperature > (Tmax*10) then
rele=1
else
rele=0
Endif

goto main```

26. Re: Compare value ...

I think, You want this:

Here is a Richard's corrected and tested code. I hope it will be works:
Code:
```'****************************************************************'*  '*  Name    : 16F88_LM235.BAS                                   *
'*  Author  :                                    *
'*  Notice  : Copyright (c) 2020                                *
'*  Date    : 04/04/2020                                        *
'*  Version : 1.0                                               *
'*
'****************************************************************
#CONFIG
__config  _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
__config  _CONFIG2, _FCMEN_ON & _IESO_ON
#ENDCONFIG
'PIC 16F88
'    Hardware Assignments
'    --------------------
' LCD circuitery
'01     - Vss (GND)
'02     - Vdd (+5V)
'08 RS  - PORTB.2
'09 E   - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7

ANSEL = %000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = 0 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB       'Porta B DATA OUT
DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2
DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4           'LCD bus size 4 or 8
DEFINE LCD_LINES 2          'Number lines on LCD DEFINE LCD_COMMANDUS 2000   'Command delay time in us
DEFINE LCD_DATAUS 50        'Data delay time in us

'    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...

'===========================================================================
'*****  SETTAGGIO PORTE

Rele   VAR    PORTA.6     '                  Pin 15
'--------------------------------------------------------------
DEFINE ADC_BITS 10      'set number of bits in result
DEFINE ADC_CLOCK 3      'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS

'    RAM Assignments and Variables
'===========================================================================
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

START:
Lcdout \$FE, 1           'Clear screen
rele=0

main:
sample = 1
samples= 0
FOR sample = 1 TO 20 'Take 20 samples
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 */ quanta

LCDOUT \$FE, 2 ' ritorna al primo carattere
lcdout \$FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"
lcdout \$FE, \$C0, "Tmin ",#Tmin, " Tmax ",#Tmax

If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif

goto main```

27. Re: Compare value ...

Originally Posted by louislouis
I think, You want this:
Here is a Richard's corrected and tested code. I hope it will be works:
Code:
```'****************************************************************'*  '*  Name    : 16F88_LM235.BAS                                   *
'*  Author  :                                    *
'*  Notice  : Copyright (c) 2020                                *
'*  Date    : 04/04/2020                                        *
'*  Version : 1.0                                               *
'*
'****************************************************************
#CONFIG
__config  _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
__config  _CONFIG2, _FCMEN_ON & _IESO_ON
#ENDCONFIG
'PIC 16F88
'    Hardware Assignments
'    --------------------
' LCD circuitery
'01     - Vss (GND)
'02     - Vdd (+5V)
'08 RS  - PORTB.2
'09 E   - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7

ANSEL = 0001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
TRISA = 111111 ' impostazioni INP/OUT
TRISB = 0 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB       'Porta B DATA OUT
DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2
DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4           'LCD bus size 4 or 8
DEFINE LCD_LINES 2          'Number lines on LCD DEFINE LCD_COMMANDUS 2000   'Command delay time in us
DEFINE LCD_DATAUS 50        'Data delay time in us

'    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...

'===========================================================================
'*****  SETTAGGIO PORTE

Rele   VAR    PORTA.6     '                  Pin 15
'--------------------------------------------------------------
DEFINE ADC_BITS 10      'set number of bits in result
DEFINE ADC_CLOCK 3      'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS

'    RAM Assignments and Variables
'===========================================================================
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

START:
Lcdout \$FE, 1           'Clear screen
rele=0

main:
sample = 1
samples= 0
FOR sample = 1 TO 20 'Take 20 samples
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 */ quanta

LCDOUT \$FE, 2 ' ritorna al primo carattere
lcdout \$FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"
lcdout \$FE, \$C0, "Tmin ",#Tmin, " Tmax ",#Tmax

If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif

goto main```

and the code is similar to mine, except for the initial strings.

Code:
```#CONFIG
__config  _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
__config  _CONFIG2, _FCMEN_ON & _IESO_ON
#ENDCONFIG```

without too much hesitation, however, I did copy and paste of your source in my compiler
Microcode Studio Plus 3.0.0.5
and as soon as I tried to issue the compile command it gave me errors.

Code:
```ERROR Line 11: Syntax error. (louislouis.pbp)
ERROR Line 12: Syntax error. (louislouis.pbp)
ERROR Line 13: Redefiniton of LABEL __config. (louislouis.pbp)
ERROR Line 13: Syntax error. (louislouis.pbp)
ERROR Line 14: Syntax error. (louislouis.pbp)```
What are all those strings? why won't my compiler accept them?
Thanks

28. Re: Compare value ...

did you have set the correct microcontroller to 16F88 in microcodestudio?

29. Re: Compare value ...

Originally Posted by louislouis
did you have set the correct microcontroller to 16F88 in microcodestudio?
here the Screenshoot

30. Re: Compare value ...

and if you take away the config part, it compiles without errors?
Copy and paste this, and try to compile.
Code:
```define osc 4

ANSEL = %000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = 0 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB       'Porta B DATA OUT
DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2
DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4           'LCD bus size 4 or 8
DEFINE LCD_LINES 2          'Number lines on LCD DEFINE LCD_COMMANDUS 2000   'Command delay time in us
DEFINE LCD_DATAUS 50        'Data delay time in us

'    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...

'===========================================================================
'*****  SETTAGGIO PORTE

Rele   VAR    PORTA.6     '                  Pin 15
'--------------------------------------------------------------
DEFINE ADC_BITS 10      'set number of bits in result
DEFINE ADC_CLOCK 3      'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS

'    RAM Assignments and Variables
'===========================================================================
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

START:
Lcdout \$FE, 1           'Clear screen
rele=0

main:
sample = 1
samples= 0
FOR sample = 1 TO 20 'Take 20 samples
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 */ quanta

LCDOUT \$FE, 2 ' ritorna al primo carattere
lcdout \$FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"
lcdout \$FE, \$C0, "Tmin ",#Tmin, " Tmax ",#Tmax

If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif

goto main```

31. Re: Compare value ...

Originally Posted by louislouis
and if you take away the config part, it compiles without errors?
Copy and paste this, and try to compile.
Yes, compile without problems

If I understand correctly, that's what I do when programming the chip, I set the fuses like this

32. Re: Compare value ...

Yes. And now it runs OK?

33. Re: Compare value ...

Originally Posted by louislouis
Yes. And now it runs OK?
No, I have always used fuses since the first moment I started creating the project.
I'm going crazy for this, I also changed PBP to version 2.47. I don't know what to think anymore.

it is evident that I have a problem, but I cannot attribute to what.

1) PBP compiler, tested with 2 versions 2.60 and 2.47
2) IDE MicroCode, I wouldn't say.
3) Microcontroller (the chip) cannot be, because if I pilot the door with the command PORTB.6 = 1 and PORTB.6 = 0 the relay attacks and disconnects regularly.
4) the BYTE or WORD variables, but I also tried to change the reference value by declaring them both as WORD.
5) The firmware is the same
6) The programmer?

I don't know what to think anymore

34. Re: Compare value ...

What kind of programmer do you use? What is your programming process?
First you compile in MCSP and then take the compiled HEX file and program to PIC with your picprogrammer? Or? How you program the PIC?

35. Re: Compare value ...

Here is the compiled HEX file. Take it in to your programmer and program your PIC. It must run.

36. Re: Compare value ...

Originally Posted by louislouis
What kind of programmer do you use? What is your programming process?
First you compile in MCSP and then take the compiled HEX file and program to PIC with your picprogrammer? Or? How you program the PIC?
It was a long time since I worked there, I pulled out old tools because I stopped at work for the "Corona Virus" and I wanted to have some fun.
Some time ago I used a self-built ProPic2, which went on parallel port.
Now that I no longer have the parallel port, I bought a K150 on the internet. This mounts on USB.

1) I write the code in MicroCode
2) the MicroCode settings are these

3) I take the .Hex file

5) I mount the chip on the K150
6) I program
7) At the end I reassemble my chip in the BreadBoard

and go ON

37. Re: Compare value ...

Originally Posted by louislouis
Here is the compiled HEX file. Take it in to your programmer and program your PIC. It must run.
Excellent, I tried. But it behaves the same way !!

I noticed that by entering your firmware the fuses are set automatically as I manually set them.
And that's OK.

But the behavior seems identical to that compiled by me. After an initial click, the relay goes ON even when the temperature is lower than 30 ° and when it exceeds 30 ° nothing happens.

38. Re: Compare value ...

This compiled HEX test your PORTA.6 (pin 15) on your PIC if is it wired right.
It switch ON and OFF the relay five times, on LCD write: Rele ON if activate the pin
and Rele OFF when deactivate the pin.
If this perform As I wrote then the rele is wired OK and works. Then the fault must be elsewhere.
Then we go troubleshoot further more.

39. Re: Compare value ...

[QUOTE = louislouis; 145045] Questo HEX compilato verifica il tuo PORTA.6 (pin 15) sul PIC se è cablato correttamente.
Accedere e spendere il relè cinque volte, sul display LCD scrive: Rele ON se si attiva il pin
e Rele OFF quando si disattiva il pin.
Se questo funziona Come ho scritto, il rele è cablato OK e funziona. Quindi la colpa deve essere altrove.
Quindi andremo a risolvere i problemi. [/ QUOTE]

Ti confermo.
Il relè attiva e disattiva 5 volte l'

ultimo passaggio, spegne il relè, pulisce lo schermo e non appena lo schermo mostra le temperature, il relè viene attivato.

A quel punto non succede più nulla, anche quando la temperatura ambiente supera i 30 °

40. Re: Compare value ...

OK, please program this HEX and tell what number shown on display. Then warm up the sensor with fingers or soldering iron. The numbers should be arround 600 for 30degC and 700 for 35degC and so on.