News:

Let's find out together what makes a PIC Tick!

Main Menu

Sht31 and Sht30 Humidity and Temperature Sensor Proton Code

Started by dnaci, Feb 05, 2021, 05:01 PM

Previous topic - Next topic

dnaci

The sht30 and sht31 proton codes are below.

Sht11 production finished. It can be used instead of Sht11.

sht30:
Device = 18F25K22
Declare Xtal = 20
Declare LCD_Type 0
Declare LCD_DTPin PORTB.0
Declare LCD_ENPin PORTB.5
Declare LCD_RSPin PORTB.4
Declare LCD_Interface 4
Declare LCD_Lines 2
Declare HSDA_Pin PORTC.4
Declare HSCL_Pin PORTC.3
'Declare Hbus_Bitrate  400
Declare Slow_Bus On
All_Digital = True
Dim NEM_HAM      As Word
Dim ISI_HAM      As Word
Dim CRC1         As Byte
Dim CRC2         As Byte
Dim CRC_CALC     As Byte
Dim ISI          As Float   
Dim A As Byte
A = 0
Dim DERECE        As Word
DERECE  = $DF   
NEM_HAM = 0
ISI_HAM = 0
ISI     = 0
Dim RH           As Float
RH=0
'----------------------------
Cls : DelayMS 3000
ANA:
Print At 1,1,"Nem: ",Dec2 RH ," %RH"
Print At 2,1,"ISI: ",Dec2 ISI," ",DERECE,"C" 
DelayMS 2000
GoSub NEM_OKU
GoSub NEM_HESAPLA
GoTo ANA

NEM_OKU:
HBStart
HBusOut %10001000 ,[$2C,$0D]
DelayMS 50
HBusIn  %10001001 ,[ISI_HAM.HighByte,ISI_HAM.LowByte,CRC1,NEM_HAM.HighByte,NEM_HAM.LowByte,CRC2]
HBStop
Return
NEM_HESAPLA:
RH = 100 * (NEM_HAM.HighByte * 256 + NEM_HAM.LowByte) / 65535.0
ISI = ISI_HAM.HighByte * 256 + ISI_HAM.LowByte
ISI = -45 + (175 * ISI / 65535.0)
Return
End 

sht31:
Device = 18F46K20
Declare Xtal = 8   
Declare LCD_DTPin = PORTD.4
Declare LCD_RSPin = PORTD.0
Declare LCD_ENPin = PORTD.1
Declare LCD_Interface = 4
Declare LCD_Lines = 4
Declare LCD_Type = 0 
Declare SDA_Pin PORTC.0
Declare SCL_Pin PORTC.1
'Declare Hbus_Bitrate  400
Declare Slow_Bus On
Declare All_Digital = True
TRISA=%00000000
TRISB=%00000000
TRISC=%00000011
TRISD=%00000000
TRISE=%00000000
PORTA=0
PORTB=0
PORTC=0
PORTD=0
PORTE=0   
Dim NEM_HAM As Word
Dim ISI_HAM As Word
Dim CRC1 As Byte
Dim CRC2 As Byte
Dim CRC_CALC As Byte
Dim ISI As Float
Dim RH As Float       
Dim DERECE        As Word
DERECE = $DF
NEM_HAM = 0
ISI_HAM = 0
ISI = 0   
RH = 0
DelayMS 500

ANA:
GoSub sensoroku:
Cls
PORTD.3=1
Print At 1,1,"Nem: ",Dec2 RH ," %RH"
Print At 2,1,"ISI: ",Dec2 ISI," ",DERECE,"C" 
DelayMS 2000
PORTD.3=0
DelayMS 1000
GoTo ANA 

sensoroku:
BStart
BusOut %10001000 ,[$2C,$0D]
DelayMS 50
BusIn  %10001001 ,[ISI_HAM.HighByte,ISI_HAM.LowByte,CRC1,NEM_HAM.HighByte,NEM_HAM.LowByte,CRC2]
BStop
RH = 100 * (NEM_HAM.HighByte * 256 + NEM_HAM.LowByte) / 65535
ISI = ISI_HAM.HighByte * 256 + ISI_HAM.LowByte
ISI = -45 + (175 * ISI / 65535)
Return 
End