Professional Documents
Culture Documents
Operation:
The circuit will take around 30 to 40 seconds to initialize the
modem. The status of the devices before the power failure is
restored. Then it will wait for the sms commands from the user.
The user has to send the password first to register his mobile
number. The default password is microcontroller the
microcontroller will send a password accepted message to the
sender. It also store the mobile number in its eeprom. So the user
dont need to send the password everytime. The various
commands to control the devices are given below.
To switch on the device 1: light on
Source code:
'----------------------------------------------------------------------------------------'copyright
'purpose
: SMS controller
'----------------------------------------------------------------------------------------$regfile = "m8def.dat"
$crystal = 3686400
$baud = 9600
$hwstack = 64
$swstack = 64
$framesize = 64
Config Portb.0 = Output
Config Portb.1 = Output
Config Portb.2 = Output
Config Portb.3 = Output
Config Portb.4 = Output
Config Portb.5 = Output
'Print Pass_stored
Relay1 = 0
Relay2 = 0
Relay3 = 0
Relay4 = 0
Pass_stored = Number
Gps = Status1
If Gps = 0 Then
Relay1 = 0
Else
Relay1 = 1
End If
Gps = Status2
If Gps = 0 Then
Relay2 = 0
Else
Relay2 = 1
End If
Gps = Status3
If Gps = 0 Then
Relay3 = 0
Else
Relay3 = 1
End If
Gps = Status4
If Gps = 0 Then
Relay4 = 0
Else
Relay4 = 1
End If
Wait 1
Rled = 1
Gled = 0
Wait 20
Print "AT"
Wait 2
Print "AT+CMGD=1"
Wait 2
Print "AT+CREG?"
Wait 2
Print "ATE0"
Wait 2
Print "AT+CNMI=1,1,0,0,0"
Wait 2
Print "AT+CMGF=1"
Wait 2
'Print #2 , "AT+CSQ"
'signal strength
'Wait 2
Rled = 0
Gled = 1
Do
Print "AT"
Wait 2
Print "AT+CMGF=1"
Print "AT+CMGR=1"
Getline
If Inmsg <> "OK" Then
Rled = 1
Gled = 1
Num = Inmsg
Getline
Gps = Split(num , Ar(1) , ",")
Num = Ar(2)
Gps = Len(num)
Gps = Gps - 2
Num = Mid(num , 2 , Gps)
Inmsg = Lcase(inmsg)
'
Wait 2
'other numbers
Num = Pass_stored
Msg = "Light Switched OFF"
Send_sms
Elseif Inmsg = "fan on" Then
Relay2 = 1
Status2 = 1
Num = Pass_stored
Msg = "Fan Switched ON"
Send_sms
Elseif Inmsg = "fan off" Then
Relay2 = 0
Status2 = 0
Num = Pass_stored
Msg = "Fan Switched OFF"
Send_sms
Elseif Inmsg = "ac on" Then
Relay3 = 1
Status3 = 1
Num = Pass_stored
Msg = "AC Switched ON"
Send_sms
Elseif Inmsg = "ac off" Then
Relay3 = 0
Status3 = 0
Num = Pass_stored
Msg = "AC Switched OFF"
Send_sms
Elseif Inmsg = "tv on" Then
Relay4 = 1
Status4 = 1
Num = Pass_stored
Msg = "AC Switched ON"
Send_sms
Elseif Inmsg = "tv off" Then
Relay4 = 0
Status4 = 0
Num = Pass_stored
Msg = "AC Switched OFF"
Send_sms
Else
Num = Pass_stored
Msg = "Invalid Command.."
Send_sms
End If
End If
Wait 2
Print "AT+CMGD=1"
Wait 3
Rled = 0
Gled = 1
End If
Gled = 0
Waitms 1
Gled = 1
Wait 8
Gled = 0
Waitms 1
Gled = 1
Loop
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'
SEND SMS
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Send_sms
Rled = 1
Wait 3
Print "AT+CMGS=" ; Chr(34) ; Num ; Chr(34)
'send sms
Waitms 200
Print Msg ; Chr(26)
Wait 5
Print "AT"
Wait 2
Rled = 0
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Getline
Inmsg = ""
Do
Gps = Inkey()
If Gps > 0 Then
Select Case Gps
Case Else
Inmsg = Inmsg + Chr(gps)
End Select
End If
Loop
End Sub
End