rf communication between 16f84 and 16f84

Discussion in 'Embedded Systems and Microcontrollers' started by lihle, Apr 2, 2010.

  1. lihle

    Thread Starter Active Member

    Apr 12, 2009
    83
    3
    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:

    Code ( (Unknown Language)):
    1.  
    2. ;*
    3. ;**********************************************************************
    4.  
    5.     list      p=16f84            ; list directive to define processor
    6.     #include <p16f877.inc>        ; processor specific variable definitions
    7.    
    8.     __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_ON & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
    9. ;
    10. ;************************Temporal Registers**************************************************
    11. Temp1    equ    70h
    12. Temp2    equ    71h
    13. Temp3    equ    73h
    14. Temp4    equ    74h
    15. Temp5    equ    75h
    16. RECEIVED   equ    7ah
    17.  
    18. ;**********************Eque Section*********************************************************
    19. ALARM_PORT     EQU   0
    20. ARM_LED          EQU   1
    21. SIREN_LED        EQU   2
    22. READY_ON         EQU   1
    23. PIR_SENSORS    EQU   0
    24.      
    25.       ORG   0x0000       ;begin at address 0
    26.       NOP
    27.       GOTO          INITIALIZE
    28. ;********************Initialisation********************************************************
    29. INITIALIZE   CLRF    Temp1
    30.                  CLRF    Temp2
    31.                  BSF    STATUS,RP0
    32.                  CLRF    PORTA
    33.                  CLRF    PORTB
    34.                  BCF    STATUS,RP0
    35.                  BCF    STATUS,RP1
    36.                   BSF    T1CON,TMR1ON
    37.                 banksel    TRISC
    38.                 bcf    TRISC,6 ; C6 =0 as outout
    39.                bsf    TRISC,0 ; C0 = 1 as input
    40.                bsf    TRISC,1 ; C1 =1 as input  
    41.        
    42. ;******************Main Program***********************************************************
    43. START    BSF    STATUS,RP0    ;select bank1
    44.              MOVLW    B'111111111'    ;set portA all inputs,RB0,RB1
    45.              MOVWF    TRISA
    46.               MOVLW    B'00000000'    ;set portB as output
    47.              MOVWF    TRISB
    48.              MOVLW    B'00000011'    ;RC0 anRC1              
    49.              MOVWF    TRISC
    50.              BCF    STATUS,RP0
    51.            ;CLRF    T1CON     ;turn off Timer1
    52. MAIN         call    Recievecode
    53.                call    DELAY3
    54.                 BSF    PORTB,2      ;return to main
    55. ;***********************************************************************************************************
    56. ;timing delays
    57. ;***********************************************************************************************************
    58. DELAY3          MOVLW   05H    ;These are delay loops for timing
    59.                    MOVWF   Temp2
    60. DELAY4          MOVLW   0FFH
    61.                    MOVWF   Temp1
    62. DELAYLOOP    DECFSZ   Temp1,1
    63.      GOTO   DELAYLOOP
    64.      DECFSZ   Temp2,1
    65.      GOTO   DELAY4
    66.      RETURN
    67. ;**********************************************************************************************************  
    68. ;arm the security system
    69. ARM_SECURITY    MOVF   RCREG      ;test for recieved signal
    70.                          MOVWF    RECEIVED   ;store in reg
    71.                          BCF    STATUS,Z   ;clear status
    72.                          MOVLW    0x27    ;dec 39
    73.                          XORWF    RECEIVED,0   ;check for equality
    74.                          BTFSC    STATUS,Z   ;is 1 if match else 0
    75.                          BSF    PORTB,ARM_LED  ;activate led
    76.                          BCF    PORTB,ARM_LED  ;de-activate led
    77.                           RETURN
    78. ;sense any interruption in the PIR
    79. ALARM_SENSE    BTFSC    PORTA,0        ;test for zero
    80.                        GOTO    ALARM_SENSE    ;return if not zero
    81. ;activate the siren and call the gsm module
    82. SET_ALARM    BCF    PORTB,1     ;turn off arm led
    83.                     BSF    PORTB,0      ;turn alarm on
    84.                     BSF    PORTB,SIREN_LED   ;turn on siren led
    85.                     CALL     DELAY3    
    86.                     RETURN
    87.      
    88. ;*************************************************************************************
    89. Receivecode   clrf   Temp4
    90. wait1H
    91.                     btfss   PORTA,1
    92.                    goto   Receivecode
    93.                    clrf   TMR0
    94.                    movwf   Temp4
    95. testst    btfsc   PORTA,1
    96.              goto   testst
    97.              movf   TMR0,w
    98.              sublw   .5
    99.              btfsc   STATUS,C
    100.               goto   wait1H
    101. testa0H    btfss   PORTA,1
    102.               goto   testa0H
    103.               clrf   TMR0
    104. testa0L    btfsc   PORTA,1
    105.               goto   testa0L
    106.                nop
    107.                movf   TMR0,w
    108.                sublw   .3
    109.                btfss   STATUS,C
    110.                bsf   Temp4,0
    111. testa1H    btfss   PORTA,1
    112.               goto   testa1H
    113.                clrf   TMR0
    114. testa1L    btfsc   PORTA,1
    115.               goto   testa1L
    116.               nop
    117.               movf   TMR0,w
    118.               sublw   .3
    119.               btfss   STATUS,C
    120.               bsf   Temp4,1
    121. testa2H    btfss   PORTA,1
    122.               goto   testa2H
    123.               clrf   TMR0
    124. testa2L    btfsc   PORTA,1
    125.               goto   testa2L
    126.                nop
    127.               movf   TMR0,w
    128.                sublw   .3
    129.               btfss   STATUS,C
    130.               bsf   Temp4,2
    131. testa3H    btfss   PORTA,1
    132.               goto   testa3H
    133.              clrf   TMR0
    134. testa3L    btfsc   PORTA,1
    135.              goto   testa3L
    136.               nop
    137.               movf   TMR0,w
    138.              sublw   .3
    139.                btfss   STATUS,C
    140.               bsf   Temp4,3
    141. testa4H    btfss   PORTA,1
    142.               goto   testa4H
    143.               clrf   TMR0
    144. testa4L    btfsc   PORTA,1
    145.              goto   testa4L
    146.             nop
    147.              movf   TMR0,w
    148.               sublw   .3
    149.               btfss   STATUS,C
    150.               bsf   Temp4,4
    151. testa5H    btfss   PORTA,1
    152.              goto   testa5H
    153.               clrf   TMR0
    154. testa5L    btfsc   PORTA,1
    155.     goto   testa5L
    156.     nop
    157.     movf   TMR0,w
    158.     sublw   .3
    159.     btfss   STATUS,C
    160.     bsf   Temp4,5
    161. testa6H    btfss   PORTA,1
    162.     goto   testa6H
    163.     clrf   TMR0
    164. testa6L    btfsc   PORTA,1
    165.     goto   testa6L
    166.     nop
    167.     movf   TMR0,w
    168.     sublw   .3
    169.     btfss   STATUS,C
    170.     bsf   Temp4,6
    171. testa7H    btfss   PORTA,1
    172.     goto   testa7H
    173.     clrf   TMR0
    174. testa7L    btfsc   PORTA,1
    175.     goto   testa7L
    176.     nop
    177.     movf   TMR0,w
    178.     sublw   .3
    179.     btfss   STATUS,C
    180.     bsf   Temp4,7
    181.     movlw   27h
    182.     subwf   Temp4,w
    183.     btfss   STATUS,Z
    184.     goto   Receivecode
    185.     bsf   PORTB,2
    186.     return
    187. END
    188.  
    189.  
     
    Last edited by a moderator: Apr 3, 2010
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You say you use the 16f84. But you have included the header file for the 16f887. Your code will not work because of this. The config bits also belong to the 16887. You can find the correct config bits option for the 16f84 at the end of the 16f84 include file
    Also then you post code, please use the code option described here http://forum.allaboutcircuits.com/misc.php?do=bbcode it will make your post more easy to read. You can edit your postings in this forum ;)
     
  3. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    and also post a circuit schematic.... this could also help in determining if your code is correct....


    B. Morse
     
  4. lihle

    Thread Starter Active Member

    Apr 12, 2009
    83
    3
    Bmorse

    No the header was just a mistake coz i have change the template without noticing.

    lihle
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    This is exceedingly confusing. Please edit your first post so the code is correct. You can not expect to get any help before this is done. And while you are editing use the code option described here http://forum.allaboutcircuits.com/misc.php?do=bbcode#code
    And your schematics is also strongly sought after
     
  6. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    If you would kindly edit your first post and add the CODE and /CODE delimeters around your code. It makes navigating and cutting and pasteing your code multitudes easier.
     
Loading...