sht30 sht31 proton basic kodu code


SHT31 sensörü için bir çalışma yapmam gerekti ve sht30 için mustafa_cmbz rumuzlu üyenin hazırladığı bir örnek buldum picproje.org forumunda. Ama bu örnek sht30 içindi ve donanımsal I2C için yazılmıştı ve sht31 içinde uygundu. Bir kaç küçük değişiklik ile SHT31 için çalışacak hale getirdim. 2 örnek koduda aşağıya ekliyorum. Sht11 üretimden kalktığı ve artık tedariği zor olduğu için Sht30 ve Sht31 kullanmak isteyenler için faydalı olacaktır proton basic kodları.

1- sht31 I2C pin seçmeli proton basic kodu:

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   


2- sht30 donanımsal I2C sht30 kodu:

   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

   Symbol BUZZER = PORTB.7

   Output BUZZER  

   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: 

  GoSub MELODI

  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  

  MELODI:

   High BUZZER : DelayMS 70 : Low BUZZER : DelayMS 35

   High BUZZER : DelayMS 54 : Low BUZZER : DelayMS 70

   Return 

Yorumlar

Popüler Yayınlar:

grup priz ara kablo yapımı

elektrikli fırın devre bağlantı şeması

gsm sinyal seviyesi asu dbm nedir

dc motor yönü değiştirme devresi

chrome ile programsız video nasıl indirilir

fan aspiratör motoru dönüş yönü değiştirme