| 
				
					
						| ' {$STAMP BS2} ' {$PBASIC 2.5}
 '*************************************
 ' Programma:termometro_ntc
 ' Versione: 1.0 data 6/11/2016
 ' Termometro che utilizza come
 ' sensore una reistenza NTC
 ' il valore è mostrato su LCD parallelo
 '
 ' Applicazione realizzata da Adriano Gandolfo
 ' Sito https://www.adrirobot.it
 ' Blog http://it.emcelettronica.com/author/adrirobot
 ' Pagina Facebook https://www.facebook.com/Adrirobot-318949048122955
 ' Istagram https://www.instagram.com/adrirobot/
 ' This example code is in the public domain.
 '*************************************
 ' -----[ definizione dei pin ]-----
 E PIN 1 ' Enable Pin For LCD
 RW PIN 2 ' R/W Pin For LCD
 RS PIN 3 ' LCD Register Select
 LcdBusOut VAR OUTB
 LcdBusIn VAR INB
 sen PIN 0 ' Pin a cui è collegato il sensore
 
 ' -----[ Costanti ]----------------------------------
 
 LcdCls CON $01 ' clear the LCD
 LcdHome CON $02 ' move cursor home
 LcdCrsrL CON $10 ' move cursor left
 LcdCrsrR CON $14 ' move cursor right
 LcdDispL CON $18 ' shift chars left
 LcdDispR CON $1C ' shift chars right
 LcdDDRam CON $80 ' Display Data RAM control
 LcdCGRam CON $40 ' Character Generator RAM
 LcdLine1 CON $80 ' DDRAM address of line 1
 LcdLine2 CON $C0 ' DDRAM address of line 2
 
 ' -----[ Variabili ]-----------
 char VAR Byte ' Character To Send To LCD
 inst VAR char ' Induction To Send To LCD
 addr VAR Byte ' address in EE and display
 index VAR Word ' Character Pointer
 idx VAR Byte ' Loop counter
 value VAR Byte ' Increment Decr. valu
 temp VAR Byte ' Temp Variable
 gradi VAR Word
 cent VAR Word
 decimale VAR Word
 
 ' -----[ EEPROM Data ]-------
 Smiley DATA $00, $0A, $0A, $00, $11, $0E, $06, $00 ' 0 
						smiley
 celsius DATA $00, $07, $05, $07, $00, $00, $00, $00 ' 1 
						grado
 EndCG DATA $00
 
 msg1 DATA "Termometro LCD ", 0 ' Primo messaggio
 msg2 DATA "www.adrirobot.it", 0 ' Secondo messaggio
 msg3 DATA "Temperatura:",0 ' Terzo messaggio
 msg4 DATA ".",0
 msg5 DATA 1, "C",0
 
 ' -----[ Initializazione LCD ]----
 LOW RW ' Set LCD To Write Mode
 OUTS = %0000000000000000 ' Set All Output Low
 DIRS = %0000000011111111 ' Set I/O Direction
 PAUSE 200
 OUTS = %00110000 ' Reset The LCD
 PULSOUT E,1 ' Send Command Three Times
 PAUSE 10
 PULSOUT E,1
 PAUSE 10
 PULSOUT E,1
 PAUSE 10
 OUTS = %00100000 ' Set To 4-bit Operation
 PULSOUT E,1
 Inst = %00101000 ' Function Set (2-Line Mode)
 GOSUB Send_Inst
 Inst = %00001110 ' Turn On Cursor
 GOSUB Send_Inst
 Inst = %00000110 ' Set Auto-Increment
 GOSUB Send_Inst
 Inst = %00000001 ' Clears LCD
 GOSUB Send_Inst
 Inst = 14 ' Set Cursor To Underline
 GOSUB Send_Inst
 
 Download_Chars: ' download custom chars
 char = LcdCGRam ' point to CG RAM
 GOSUB Send_Inst ' prepare to write CG data
 FOR idx = Smiley TO EndCG-1 ' build custom chars
 READ idx, char ' get byte from EEPROM
 GOSUB Write_LCD_Char ' put into LCD CG RAM
 NEXT
 
 ' -----[ Programma ]----
 char = LcdCls ' Cancella LCD
 GOSUB Send_Inst
 ' Messaggio iniziale
 char = LcdLine1 + 0 ' Porta il cursore alla 1 linea 
						posizione 0
 GOSUB Send_Inst
 idx = Msg1 ' Scrive Termometro LCD
 GOSUB Write_Message
 char = 0 ' Scrive carattere SMILE
 GOSUB Send_Text
 char = LcdLine2 + 0 ' Porta il cursore alla 2 linea 
						posizione 0
 GOSUB Send_Inst
 idx = Msg2 ' Scrive www.adrirobot.it
 GOSUB Write_Message
 PAUSE 1000
 char = LcdCls ' Cancella LCD
 GOSUB Send_Inst
 char = LcdLine1 + 0
 GOSUB Send_Inst
 idx = Msg3 ' Scrive Temperatura:
 GOSUB Write_Message
 char = LcdLine2 + 4
 GOSUB Send_Inst
 idx = msg5
 GOSUB Write_Message ' Scrive C
 
 ' -----[ Lettura temperatiura ]----
 Lettura_temperatura:
 HIGH sen
 PAUSE 3
 RCTIME sen,1,gradi
 cent = (5720- gradi + 50) / 110
 decimale = (((5900- gradi + 50) // 110) * 10)/110
 'DEBUG HOME, DEC cent,",", DEC decimale,"°C",CR
 char = LcdLine2 + 0
 GOSUB Send_Inst
 value= cent
 GOSUB C_ASCII
 idx = msg4
 GOSUB Write_Message
 char = decimale + 48 ' Convert to ASCII
 GOSUB Send_Text ' Write value
 GOTO lettura_temperatura
 END
 
 ' -----[ Subroutines ]-----
 'Questa subroutine posiziona il cursore, convertiti
 'Un numero a 3 cifre per l'ASCII, e scrive il
 'Codice ASCII per il display LCD.
 
 C_ASCII: ' convert to ASCII value
 'char = (value / 100) ' Get 100s position
 'value = (value //100) ' Get Mod
 'char = char + 48 ' Convert to ASCII
 'GOSUB Send_Text ' Write value
 char = (value / 10) ' Get 10s position
 value = (value // 10) ' Get Mod
 char = char + 48 ' Convert to ASCII
 GOSUB Send_Text ' Write value
 char = value + 48 ' Convert to ASCII
 GOSUB Send_Text ' Write value
 RETURN
 
 Write_LCD_Char: ' HIGH RS = Write a character
 HIGH RS ' to the LCD display
 LcdBusOut = char.HIGHNIB
 PULSOUT E, 3
 LcdBusOut = char.LOWNIB
 PULSOUT E, 3
 
 Write_Message:
 DO
 READ idx, char ' Legge i caratterie dall EE
 IF (char = 0) THEN EXIT ' se 0 il messaggio è completo
 GOSUB Send_Text ' scrive il carattere
 idx = idx + 1 ' punta al prossimo carattere
 LOOP
 RETURN
 
 Send_Inst:
 LOW RS ' Set Instruction Mode
 OUTB = Inst.HIGHNIB ' Send High Nibble
 PULSOUT E,1
 OUTB = Inst.LOWNIB ' Send Low Nibble
 PULSOUT E,1
 HIGH RS ' Set LCD Back To Text Mode
 RETURN
 
 Send_Text:
 OUTB = Char.HIGHNIB ' Send High Nibble
 PULSOUT E,1
 OUTB = char.LOWNIB ' Send Low Nibble
 PULSOUT E,1
 PAUSE 100
 RETURN
 |  |