Академический Документы
Профессиональный Документы
Культура Документы
----------
'copyright : (c) 2008-2009, AVRprojects.info
'purpose : Bluetooth Smart Home
'-------------------------------------------------------------------------------
----------
$regfile = "m8def.dat"
$crystal = 3686400
$baud = 115200
Load1 Alias Pinb.4
Load2 Alias Pinb.3
Load3 Alias Pinb.2
Load4 Alias Pinb.1
Load5 Alias Pinb.0
Pir Alias Pind.6
Declare Sub Read1820
Declare Sub Device_control
Config Pir = Input
Config Load1 = Output
Config Load2 = Output
Config Load3 = Output
Config Load4 = Output
Config Load5 = Output
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.1 , Db6 = Portc.0 , Db7 = Port
b.5 , E = Portc.3 , Rs = Portc.4
Config Lcd = 16 * 2 'configure lcd scree
n
Config Adc = Single , Prescaler = Auto , Reference = Internal
'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128
'Because the ADC needs a clock from 50-200 KHz
'The AUTO feature, will select the highest clockrate possible
Config 1wire = Portd.3
Dim Light As Integer
'Temp variables
Dim Bd1 As Byte
Dim Bd2 As Byte
Dim Bd7 As Byte
Dim Bd8 As Byte
Dim W As Word
Dim Tmp As Byte
Dim T As Integer , T1 As Integer
Dim T2 As Integer , T3 As Integer
Dim Bd(9) As Byte
Dim Devstat As Byte
Dim Dsid1(8) As Byte 'Dallas ID 64 bits incl CRC
Dim DsId2(8) As Byte
Devstat = 0
Portb = Devstat
Cls 'Clear display
Cursor Off
Locate 1 , 3 'set cursor position
Lcd "Welcome to"
Lowerline 'second line
Lcd "avrprojects.info"
' Wait 1
W = 1wirecount()
' Here I assume 2 sensors - no errorcontrol made, but would be easy to do with t
he "Err"-variable
' Getting the two sensors IDs.
DsId1(1) = 1wsearchfirst()
Do
Dsid2(1) = 1wsearchnext()
Loop Until Err = 1
Start Adc
Do
Light = Getadc(5)
Light = Light / 10
Light = Light - 10
1wreset ' reset the bus
1wwrite &HCC ' skip rom
1wwrite &H44 ' Convert T
Waitms 400
1wverify Dsid1(1) 'Issues the "Match R
OM "
If Err = 0 Then 'lcd " Sensor found"
Read1820
T2 = T
T3 = T1
Lcd "T1:" ; T1 ; "." ; T
End If
1wverify Dsid2(1)
If Err = 0 Then ' lcd " Sensor found
"
Read1820
End If
Print "X"
Cls
Lcd "Lig:" ; Light ; "%"
Locate 1 , 9
If Pir = 0 Then
Print "Pir:Normal" ; "Y"
Lcd "PIR:Nor"
Else
Print "Pir:Ab-Normal" ; "Y"
Lcd "PIR:ANor"
End If
Lowerline
Lcd "T1:" ; T1 ; "." ; T ; " T2:" ; T3 ; "." ; T2