PIC Basic SHT15 digital thermometer with 16F877

sht15-1
เซนเซอร์ตรวจจับอุณหภูมิและความชื้น SHT15 เป็น IC แบบดิจิตอล สามารถวัดอุณภูมิในช่วง -40°C ถึง 125°C และความชื้นในช่วง 0 – 100% RH มีความคลาดเคลื่อนอุณหภูมิ ±0.1°C ความชื้น ±0.1 RH ใช้สายสัญญาณ 2 เส้นในการส่งข้อมูล

 

FEATURES

  • Energy consumption: 80uW (at 12bit, 3V, 1 measurement / s)
  • RH operating range: 0 – 100% RH
  • T operating range: -40 – +125°C (-40 – +257°F)
  • RH response time: 8 sec (tau63%)
  • Output: digital (2-wire interface)

ตัวอย่างโปรแกรมอ่านค่าจาก SHT15

 

include “modedefs.bas”
‘** Asigamiento de Pines
define OSC 10
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG  PORTB
DEFINE LCD_EBIT 1

TRISA=%11111111
TRISB=%00000000
ADCON1=7

clk    VAR PORTA.0 ‘ SCK
dta    VAR PORTA.1 ‘ DATA

‘** Constantes

cmdtr CON %00000011 ‘ Command “read temperature”
cmdhr CON %00000101 ‘ Command “read humitity”

‘** Variables

result VAR WORD ‘ RAW Data from Sensor
chksum VAR BYTE ‘ Checksum
cmd    VAR WORD ‘ Sensor Command
RHlin  VAR WORD ‘ Rel. Humidity (RH) Linear (% *10)
RHtc   VAR WORD ‘ Rel. Humidity (RH) temp. compensated (% *10)
Temp   VAR WORD ‘ Temperature (°C *100)
i      VAR BYTE

main:
        GoSub init
            cmd = cmdtr
        GoSub readsensor
            Temp=result-3995
        GoSub init
            cmd = cmdhr
        GoSub readsensor
            RHlin=(26542-(54722**result+result))**result-40 ‘ RH linear
            RHtc=655+(result*5)+(result**15917)
            RHtc=(RHtc**(Temp/10+2480))-(RHtc**2730)+RHlin ‘ RH temp. compensated

            lcdout $fe,$1,”T:”,DEC2 Temp/100,”.”,DEC1 temp/10
            lcdout $fe,$C0,”H:”,DEC2 RHTC/10,”.”,DEC1 RHTC
        PAUSE 500
        
    GoTo main

‘** Iniciar Sensor
init:
        High dta
        Low clk
        For i=1 to 10
        High clk
        Pause 1
        Low clk
        Pause 1
        Next i
        Call tstart
    Return

‘** Comienzo de Transferencia
tstart:
        High clk
        Pause 1
        Low dta
        Pause 1
        Low clk
        Pause 1
        High clk
        Pause 1
        High dta
        Pause 1
        Low clk
    Return

‘** Leyendo Datos del SHT
readsensor:
        GoSub tstart
        GoSub WaitSensor

        ShiftOut dta,clk,1,[cmd\8] ‘ send command
        Input dta ‘ wait acknowledge
        Low clk
        While dta=1
        Wend
        PulsOut clk,10 ‘ send ack
        While dta=0
        Wend
        While dta=1 ‘ wait for conversion to complete
        Wend
        Low clk
        ShiftIn dta,clk,0,[result.highbyte\8] ‘ get first byte
        Low dta
        PulsOut clk,10 ‘ send ack
        ShiftIn dta,clk,0,[result.lowbyte\8] ‘ get second byte
        Low dta
        PulsOut clk,10 ‘ send ack
        ShiftIn dta,clk,0,[chksum\8] ‘ get third byte (checksum)
        High dta
        PulsOut clk,10 ‘ send ack
        Input dta ‘ End of Transmission
        Input clk
    Return

WaitSensor:
            result=4096
Loop:
        result=result-1
        IF dta && result.bit11 Then Loop
Return

sht15-2

Facebook Comments