You are on page 1of 2

'****Dehidratoe PIC 16F628 2X16 LCD DHT11****

Define SIMULATION_WAITMS_VALUE = 1
TRISA = %00111111 'port a je izlaz
PORTA = 0
TRISB = %00000000 'port b je izlaz
PORTB = 0
AllDigital
Define LCD_LINES = 2
Define LCD_CHARS = 16
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 4
Define LCD_EREG = PORTB
Define LCD_EBIT = 5
Define LCD_COMMANDUS = 5000
Define LCD_DATAUS = 100
Define LCD_INITMS = 500
Define 1WIRE_REG = PORTB
Define 1WIRE_BIT = 6
Symbol grijac = PORTA.6
Symbol ventilator = PORTA.5
Dim podatak As Byte
Dim templ As Byte
Dim temph As Byte
Dim temperatura As Word
Dim v As Bit
Dim a As Byte
Dim b As Byte
Dim humh As Byte
Dim huml As Byte
Dim sum As Byte
Dim dht11data As Long
Lcdinit
Lcddefchar 0, %01110, %01010, %01110, %00000, %00000, %00000, %00000, %00000 'd
egree symbol
Lcdcmdout LcdClear
Lcdout " DEHIDRATOR HRANE "
Gosub showdht11
End
showdht11:
init:
a = 0
b = 0
TRISB.6 = 0
PORTB.6 = 1
WaitMs 2000
PORTB.6 = 0
WaitMs 20
TRISB.6 = 1
WaitUs 5
dht11response:
While PORTB.6 'cekam nulu
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
WaitUs 5
e:
a = a + 1
If a = 255 Then Goto err 'cekam 1
If PORTB.6 = 0 Then Goto e
WaitUs 3
a = 0
While PORTB.6
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
WaitUs 5
For b = 0 To 39
data:
If a = 255 Then Goto err
If PORTB.6 = 0 Then Goto data
dht11data = ShiftLeft(dht11data, 1)
WaitUs 8
If PORTB.6 = 1 Then podatak = 1 Else podatak = 0
dht11data = dht11data + podatak
a = 0
While PORTB.6
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
Next b
For b = 0 to7
kontrolnibit:
If a = 255 Then Goto err
If PORTB.6 = 0 Then Goto kontrolnibit
sum = ShiftLeft(sum, 1)
WaitUs 8
If PORTB.6 = 1 Then podatak = 1 Else podatak = 0
sum = sum + podatak
a = 0
While PORTB.6
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
Next b
humh = dht11data.LB
huml = dht11data.HB
temph = dht11data.3B
templ = dht11data.4B
a = humh + huml + temph + templ
err:
If a <> sum Then
hum = 0
temp = 1000
Endif
Return

You might also like