hi guys
i am trying to develop a security system that could be armed and disarm wireless
the code to arm the system would be transmitted using a simple pushbuttom connected to the microcontroller.when you press the button the choosen code to arm the sysyem is transmitted serial to the other pic.i am using rf module in this so i have tested the code but it can correspond with the reciever.
i have atteched the receiving code.
thanks in advance
here below:
i am trying to develop a security system that could be armed and disarm wireless
the code to arm the system would be transmitted using a simple pushbuttom connected to the microcontroller.when you press the button the choosen code to arm the sysyem is transmitted serial to the other pic.i am using rf module in this so i have tested the code but it can correspond with the reciever.
i have atteched the receiving code.
thanks in advance
here below:
Rich (BB code):
;*
;**********************************************************************
list p=16f84 ; list directive to define processor
#include <p16f877.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_ON & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
;
;************************Temporal Registers**************************************************
Temp1 equ 70h
Temp2 equ 71h
Temp3 equ 73h
Temp4 equ 74h
Temp5 equ 75h
RECEIVED equ 7ah
;**********************Eque Section*********************************************************
ALARM_PORT EQU 0
ARM_LED EQU 1
SIREN_LED EQU 2
READY_ON EQU 1
PIR_SENSORS EQU 0
ORG 0x0000 ;begin at address 0
NOP
GOTO INITIALIZE
;********************Initialisation********************************************************
INITIALIZE CLRF Temp1
CLRF Temp2
BSF STATUS,RP0
CLRF PORTA
CLRF PORTB
BCF STATUS,RP0
BCF STATUS,RP1
BSF T1CON,TMR1ON
banksel TRISC
bcf TRISC,6 ; C6 =0 as outout
bsf TRISC,0 ; C0 = 1 as input
bsf TRISC,1 ; C1 =1 as input
;******************Main Program***********************************************************
START BSF STATUS,RP0 ;select bank1
MOVLW B'111111111' ;set portA all inputs,RB0,RB1
MOVWF TRISA
MOVLW B'00000000' ;set portB as output
MOVWF TRISB
MOVLW B'00000011' ;RC0 anRC1
MOVWF TRISC
BCF STATUS,RP0
;CLRF T1CON ;turn off Timer1
MAIN call Recievecode
call DELAY3
BSF PORTB,2 ;return to main
;***********************************************************************************************************
;timing delays
;***********************************************************************************************************
DELAY3 MOVLW 05H ;These are delay loops for timing
MOVWF Temp2
DELAY4 MOVLW 0FFH
MOVWF Temp1
DELAYLOOP DECFSZ Temp1,1
GOTO DELAYLOOP
DECFSZ Temp2,1
GOTO DELAY4
RETURN
;**********************************************************************************************************
;arm the security system
ARM_SECURITY MOVF RCREG ;test for recieved signal
MOVWF RECEIVED ;store in reg
BCF STATUS,Z ;clear status
MOVLW 0x27 ;dec 39
XORWF RECEIVED,0 ;check for equality
BTFSC STATUS,Z ;is 1 if match else 0
BSF PORTB,ARM_LED ;activate led
BCF PORTB,ARM_LED ;de-activate led
RETURN
;sense any interruption in the PIR
ALARM_SENSE BTFSC PORTA,0 ;test for zero
GOTO ALARM_SENSE ;return if not zero
;activate the siren and call the gsm module
SET_ALARM BCF PORTB,1 ;turn off arm led
BSF PORTB,0 ;turn alarm on
BSF PORTB,SIREN_LED ;turn on siren led
CALL DELAY3
RETURN
;*************************************************************************************
Receivecode clrf Temp4
wait1H
btfss PORTA,1
goto Receivecode
clrf TMR0
movwf Temp4
testst btfsc PORTA,1
goto testst
movf TMR0,w
sublw .5
btfsc STATUS,C
goto wait1H
testa0H btfss PORTA,1
goto testa0H
clrf TMR0
testa0L btfsc PORTA,1
goto testa0L
nop
movf TMR0,w
sublw .3
btfss STATUS,C
bsf Temp4,0
testa1H btfss PORTA,1
goto testa1H
clrf TMR0
testa1L btfsc PORTA,1
goto testa1L
nop
movf TMR0,w
sublw .3
btfss STATUS,C
bsf Temp4,1
testa2H btfss PORTA,1
goto testa2H
clrf TMR0
testa2L btfsc PORTA,1
goto testa2L
nop
movf TMR0,w
sublw .3
btfss STATUS,C
bsf Temp4,2
testa3H btfss PORTA,1
goto testa3H
clrf TMR0
testa3L btfsc PORTA,1
goto testa3L
nop
movf TMR0,w
sublw .3
btfss STATUS,C
bsf Temp4,3
testa4H btfss PORTA,1
goto testa4H
clrf TMR0
testa4L btfsc PORTA,1
goto testa4L
nop
movf TMR0,w
sublw .3
btfss STATUS,C
bsf Temp4,4
testa5H btfss PORTA,1
goto testa5H
clrf TMR0
testa5L btfsc PORTA,1
goto testa5L
nop
movf TMR0,w
sublw .3
btfss STATUS,C
bsf Temp4,5
testa6H btfss PORTA,1
goto testa6H
clrf TMR0
testa6L btfsc PORTA,1
goto testa6L
nop
movf TMR0,w
sublw .3
btfss STATUS,C
bsf Temp4,6
testa7H btfss PORTA,1
goto testa7H
clrf TMR0
testa7L btfsc PORTA,1
goto testa7L
nop
movf TMR0,w
sublw .3
btfss STATUS,C
bsf Temp4,7
movlw 27h
subwf Temp4,w
btfss STATUS,Z
goto Receivecode
bsf PORTB,2
return
END
Last edited by a moderator: