Sie sind auf Seite 1von 4

'****Inkubator 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 = 4
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 6
Define LCD_EREG = PORTA
Define LCD_EBIT = 7
Define LCD_COMMANDUS = 100
Define LCD_DATAUS = 100
Define LCD_INITMS = 500
Define 1WIRE_REG = PORTB
Define 1WIRE_BIT = 6
Symbol grijac = PORTB.3
Symbol plus = PORTA.3
Symbol minus = PORTA.4
Symbol meni = PORTA.5
Dim a As Byte
Dim b As Byte
Dim v As Word
Dim set As Byte
Dim potrosnja As Word
Dim temp1 As Byte
Dim temp2 As Byte
Dim hum As Byte
Dim humd As Byte
Dim podatak As Byte
Dim sum As Byte
Read 0, set 'INTERNAL EEPROM READING ADRESS 12 HIGH BYTE
Read 1, potrosnja 'INTERNAL EEPROM READING ADRESS 13 LOW BYTE
Read 5, v
Lcdinit
Lcddefchar 0, %01110, %01010, %01110, %00000, %00000, %00000, %00000, %00000 'd
egree symbol
Lcdcmdout LcdClear
If meni = 0 Then Gosub settmp
start1:
Gosub show_dht11
Lcdcmdout LcdClear
Lcdout "T:", #temp1, ",", 0, "C ST", #set, 0, "C"
Lcdcmdout LcdLine2Home
Lcdout "RH:", #hum, "% " #potrosnja, "h"
If temp1 >= set Then grijac = 0
If temp1 < set Then Gosub ugrijme
If meni = 0 Then Gosub settmp
Goto start1
ugrij:
End
settmp:
grijac = 0
loop:
Lcdcmdout LcdClear

Lcdcmdout LcdLine1Home
Lcdout "PodesavanjeTemp."
While meni = 0
Wend
loop45:
Lcdcmdout LcdLine2Home
Lcdout #set, 0, "C"
WaitMs 400
If plus = 0 Then set = set + 1 'temp set increment
If set > 30 Then set = 30
If minus = 0 Then set = set - 1 'temp set increment
If set < 15 Then set = 15
If meni = 0 Then Goto store
Goto loop45
store:
Write 0, set 'INTERNAL EEPROM WRITING ADRESS 12 HIGH BYTE
Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout " PODESENO "
While meni = 0
Wend
Return
show_dht11:
init:
a = 0
b = 0
TRISA.2 = 0
PORTA.2 = 1
WaitMs 2000
PORTA.2 = 0
WaitMs 20
TRISA.2 = 1
WaitUs 5
dht11response:
While PORTA.2 '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 PORTA.2 = 0 Then Goto e
WaitUs 3
a = 0
While PORTA.2
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
WaitUs 5
For b = 0 To 7
humh:
If a = 255 Then Goto err
If PORTA.2 = 0 Then Goto humh
hum = ShiftLeft(hum, 1)
WaitUs 8
If PORTA.2 = 1 Then podatak = 1 Else podatak = 0

hum = hum + podatak


a = 0
While PORTA.2
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
Next b
a = 0
For b = 0 To 7
huml:
If a = 255 Then Goto err
If PORTA.2 = 0 Then Goto huml
humd = ShiftLeft(humd, 1)
WaitUs 8
If PORTA.2 = 1 Then podatak = 1 Else podatak = 0
humd = humd + podatak
a = 0
While PORTA.2
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
Next b
a = 0
For b = 0 To 7
temph:
If a = 255 Then Goto err
If PORTA.2 = 0 Then Goto temph
temp1 = ShiftLeft(temp1, 1)
WaitUs 8
If PORTA.2 = 1 Then podatak = 1 Else podatak = 0
temp1 = temp1 + podatak
a = 0
While PORTA.2
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
Next b
a = 0
For b = 0 To 7
templ:
If a = 255 Then Goto err
If PORTA.2 = 0 Then Goto templ
temp2 = ShiftLeft(temp2, 1)
WaitUs 8
If PORTA.2 = 1 Then podatak = 1 Else podatak = 0
temp2 = temp2 + podatak
a = 0
While PORTA.2
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
Next b
a = 0

For b = 0 To 7
kontrolnibit:
If a = 255 Then Goto err
If PORTA.2 = 0 Then Goto kontrolnibit
sum = ShiftLeft(sum, 1)
WaitUs 8
If PORTA.2 = 1 Then podatak = 1 Else podatak = 0
sum = sum + podatak
a = 0
While PORTA.2
a = a + 1
If a = 255 Then Goto err
Wend
a = 0
Next b
a = hum + humd + temp1 + temp2
err:
If a <> sum Then
WaitMs 2000
Goto init
Endif
Return
ugrijme:
grijac = 1
Lcdcmdout LcdClear
Lcdout "T:", #temp1, ",", 0, "C ST", #set, 0, "C"
Lcdcmdout LcdLine2Home
Lcdout "RH:", #hum, "% " #potrosnja, "h"
WaitMs 60000
v = v + 1
If v = 60 Then
Write 5, v
v = 0
potrosnja = potrosnja + 1
Write 1, potrosnja
Endif
Return

Das könnte Ihnen auch gefallen