Microcontroller › PIC › HOME AUTOMATION USING GSM WITH PIC16f877a › hi i’ve been tying to create
hi i’ve been tying to create a new program but it’s not working properly in proteus… i used PROTON IDE.. basic language THANK YOU AGAIN
‘****************************************************************
‘Home Automation controlled by Android Mobile Phones
‘****************************************************************
Device 16F877A ‘define device used
Declare Xtal = 4 ‘define oscillator used
‘****************************************************************
‘define configuration word bits
Declare Reminders OFF
Config XT_OSC,WDT_OFF,PWRTE_ON,BODEN_OFF,LVP_OFF,CP_OFF,DEBUG_OFF
Declare Reminders On
‘****************************************************************
‘assign values to serial communication
Hserial_Baud = 9600 ‘set BAUD rate to 9600 BAUD
Hserial_Clear = On
‘****************************************************************
‘set port assignments 1-input ; 0-output
TRISB = %00000000 ‘set all PORTB as outputs
TRISA = 0
TRISC = 0
‘****************************************************************
‘microcontroller declarations
RCSTA = $90 ‘ 10010000 Enable serial port & continuous receive
TXSTA = $24 ‘ 00100100 Enable transmit, BRGH = 1
‘SPBRG = 25 ‘ 9600 Baud @ 4MHz, 0.16%
ADCON1 = 7 ‘disables ADC
CMCON = 7 ‘disables Comparators
T1CON = $01 ‘00000001, 1:1 prescale value, enable TMR1
PIR1.0 = 0 ‘must be cleared: TMR1 overflow interrupt flag bit
PIE1 = $01 ‘enable TMR1 overflow interrupt
‘****************************************************************
‘program constants
‘assigned string values will be used instead of actual port assignments
‘for more convenient programming
Symbol app1 = PORTB.0
Symbol app2 = PORTB.1
Symbol app3 = PORTB.2
Symbol app4 = PORTB.3
Symbol app5 = PORTB.4
Symbol app6 = PORTB.5
Symbol app7 = PORTB.6
Symbol app8 = PORTB.7
Symbol mnum = 09157003397
‘****************************************************************
‘program variables
‘variables for global time
Dim SMS As Byte
‘Str mnum = “09157003397”,0
Clear ‘clear all RAM contents at startup
‘****************************************************************
‘initialize comm to GSM Module
gsm:
HSerOut [“AT”] ‘start serial communication
‘HSerIn 5000,sms ‘wait for GSM Module response OK
HSerOut [“AT+CFUN=1”]
DelayMS 2000
HSerOut [“AT+CMGF=1”] ‘set text mode
DelayMS 2000
HSerOut [“AT+CNMI=1,1,0,0,0”]
DelayMS 2000
‘****************************************************************
main:
While 1
HSerIn 5000,
HSerOut[“AT+CMGR=”,SMS]
DelayMS 2000
‘Hserin [“+CMGR”,SMS]
GoSub execute
‘GoSub deleteSMS
Wend
‘****************************************************************
execute:
If SMS = 10 Then
PORTB.0 = 1
GoSub replyOnSMS
EndIf
If SMS = 11 Then
PORTB.1 = 1
GoSub replyOnSMS
EndIf
If SMS = 12 Then
PORTB.2 = 1
GoSub replyOnSMS
EndIf
If SMS = 13 Then
PORTB.3 = 1
GoSub replyOnSMS
EndIf
If SMS = 14 Then
PORTB.4 = 1
GoSub replyOnSMS
EndIf
If SMS = 15 Then
PORTB.5 = 1
GoSub replyOnSMS
EndIf
If SMS = 16 Then
PORTB.6 = 1
GoSub replyOnSMS
EndIf
If SMS = 17 Then
PORTB.7 = 1
GoSub replyOnSMS
EndIf
If SMS = 21 Then
PORTB.1 = 0
GoSub replyOffSMS
EndIf
If SMS = 22 Then
PORTB.2 = 0
GoSub replyOffSMS
EndIf
If SMS = 23 Then
PORTB.3 = 0
GoSub replyOffSMS
EndIf
If SMS = 24 Then
PORTB.4 = 0
GoSub replyOffSMS
EndIf
If SMS = 25 Then
PORTB.5 = 0
GoSub replyOffSMS
EndIf
If SMS = 26 Then
PORTB.6 = 0
GoSub replyOffSMS
EndIf
If SMS = 27 Then
PORTB.7 = 0
GoSub replyOffSMS
EndIf
‘***************************************************************
End
‘***************************************************************
‘subroutines
deleteSMS:
HSerOut [“AT”]
DelayMS 2000
HSerOut [“AT+CMGD=”,SMS]
DelayMS 2000
Return
‘***************************************************************
replyOnSMS:
HSerOut [“AT”]
DelayMS 2000
HSerOut [“AT+CMGS=”,mnum]
‘ Write = Your appliance is ON
DelayMS 2000
Return
‘***************************************************************
replyOffSMS:
HSerOut [“AT”]
DelayMS 2000
HSerOut [“AT+CMGS=”,mnum]
‘ Write = Your appliance is OFF
DelayMS 2000
Return
‘***************************************************************