AVR Bluetooth Smart Home

Published on May 2016 | Categories: Documents | Downloads: 48 | Comments: 0 | Views: 406
of 4
Download PDF   Embed   Report

Comments

Content

'---------------------------------------------------------------------------------------'copyright : (c) 2008-2009, AVRprojects.info 'purpose : Bluetooth Smart Home '---------------------------------------------------------------------------------------$regfile = "m8def.dat" $crystal = 3686400 $baud = 115200 Load1 Load2 Load3 Load4 Load5 Alias Alias Alias Alias Alias Pinb.4 Pinb.3 Pinb.2 Pinb.1 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 Dim Dim Dim Dim Dim W As Word Tmp As Byte T As Integer , T1 As Integer T2 As Integer , T3 As Integer Bd(9) As Byte Devstat As Byte

Dim Dsid1(8) As Byte 'Dallas ID 64 bits incl CRC Dim DsId2(8) As Byte Devstat = 0 Portb = Devstat Cls Cursor Off Locate 1 , 3

'Clear display 'set cursor position

Lcd "Welcome to" Lowerline Lcd "avrprojects.info" ' Wait 1

'second line

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 Do Light Light Light Adc = Getadc(5) = Light / 10 = Light - 10 ' skip rom ' Convert T 'Issues the "Match R 'lcd " Sensor found"

1wreset ' reset the bus 1wwrite &HCC 1wwrite &H44 Waitms 400 1wverify Dsid1(1) OM " If Err = 0 Then Read1820 T2 = T T3 = T1 Lcd "T1:" ; T1 ; "." ; T End If 1wverify Dsid2(1) If Err = 0 Then " 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 Print "Lig:" ; Light ; "Y" Print "Tp1:" ; T1 ; "." ; T ; "Y" Print "Tp2:" ; T3 ; "." ; T2 ; "Y" Print "Z"

' lcd " Sensor found

Device_control Waitms 300 Device_control Waitms 300 Device_control Waitms 400 Loop 'Read the DS1820 Sub Read1820 alculate 1wwrite &HBE Bd(1) = 1wread(9) Bd1 = Bd(1) Bd2 = Bd(2) Bd7 = Bd(7) Bd8 = Bd(8) 1wreset Tmp = Bd1 And 1 If Tmp = 1 Then Decr Bd1 T = Bd1 T = T * 50 T = T - 25 T1 = Bd8 - Bd7 T1 = T1 * 100 T1 = T1 / Bd8 T = T + T1 T1 = T / 100 T = T Mod 100 r End Sub Sub Device_control Tmp = Inkey() m serial port If Tmp = 65 Then Set Devstat.4 Portb = Devstat Elseif Tmp = 66 Then Reset Devstat.4 Portb = Devstat Elseif Tmp = 67 Then Set Devstat.3 Portb = Devstat Elseif Tmp = 68 Then Reset Devstat.3 Portb = Devstat Elseif Tmp = 69 Then Set Devstat.2 Portb = Devstat Elseif Tmp = 70 Then Reset Devstat.2 Portb = Devstat Elseif Tmp = 71 Then Set Devstat.1 Portb = Devstat Elseif Tmp = 72 Then 'get ascii value fro 'DEVICE 1 ON 'DEVICE 1 Off 'we got something 'we got something 'we got something 'we got something 'we got something 'we got something

' reads sensor ans c ' T for 0.1 C ' read 9 data bytest

' read bytes in array ' reset the bus ' 0.1C precision

'store tens 'store decimal numbe

Reset Devstat.1 Portb = Devstat Elseif Tmp = 73 Then Set Devstat.0 Portb = Devstat Elseif Tmp = 74 Then Reset Devstat.0 Portb = Devstat Elseif Tmp = 75 Then Devstat = &HFF Portb = Devstat Elseif Tmp = 76 Then Devstat = &H0 Portb = Devstat End If End Sub End

'we got something 'we got something 'we got something 'we got something

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close