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 *
'* : All Rights Reserved *
'* 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
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
'----------------------------------------------------
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 ADCin Parameters
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
Grade var Byte
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
ADCIN 0, temp 'Read AN0 into temp variable
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
Bookmarks