Garage Door Radio Receiver

State Diagram

Declarations

#rem  Garage_Receiver_Code.bas This is the receiver on the motor support

This version uses the keypad transmitter

It has A sink (open collector) output, and a 5V regulator with 7-16V input

If incorrect code received yhen a 15-sec hold is imposed

A "2" cancels the hold

John Saunders 6/27/2017 N2400_8, , 

#endrem


#picaxe 08M2


'Output Ports

symbol Out_Port    = C.1        'Controls the low logic output, pim 9



'Input ports

symbol Rcvr_Port   = C.4

symbol Int_Port    = pinC.3


'Variables

'Interrupt

symbol RcvrInLF    = b1            

symbol RcvrInCR    = b2        

symbol RcvrIn1     = b3

symbol RcvrIn2     = b4

symbol RcvrIn3     = b5

symbol Code1     = b6

symbol Code2     = b7

symbol Code3     = b8

symbol Pulse_Cnt   = b10

symbol CodeValid   = bit1

'Global

symbol HoldCnt     = b11            'Used for lockout

symbol Hold         = bit0        '1 if hold active

'Constants

symbol HoldDur     = 22        

symbol DoorData     = 0

symbol ResetData   = 3


DATA DoorData,(“XXX”)

DATA ResetData,(“YYY”)

Init and Main

init:

SETFREQ m8

LOW Out_Port

LET Hold = 0

LET HoldCnt = 0

SETINT  %00001000,%00001000    'Interrupt when C,3 high


main:

PAUSE 133

INC HoldCnt

IF HoldCnt >= HoldDur THEN

    LET HoldCnt = 0

    LET Hold = 0

ENDIF

GOTO main


RETURN

Iterrupt

Interrupt:

LET RcvrIn1="Z"

LET Pulse_Cnt = 0

DO WHILE Int_Port = 1

    INC Pulse_Cnt

    PAUSE 1

LOOP                'There is a 10 ms gap before the code to allow the serin to execute

IF Pulse_Cnt < 8 OR Pulse_Cnt > 21 THEN NotMine 

SERIN [80],Rcvr_Port,N2400_8,(“something”),RcvrIn1,RcvrIn2,RcvrIn3,RcvrInLF,RcvrInCR

IF RcvrIn1 = "Z" OR RcvrInLF <> 13 OR RcvrInCR <> 10 THEN NotMine

LET CodeValid = 0

'SERTXD (RcvrIn1,RcvrIn2,RcvrIn3,13,10)

READ DoorData,Code1,Code2,Code3  

'SERTXD (RcvrIn1,RcvrIn2,RcvrIn3,",",Code1,Code2,Code3,13,10)

IF RcvrIn1 = Code1 AND RcvrIn2 = Code2 AND RcvrIn3 = Code3 AND Hold = 0 THEN

    HIGH Out_Port

    PAUSE 1200

    LOW Out_Port

    LET CodeValid = 1

ENDIF

READ ResetData,Code1,Code2,Code3  

IF RcvrIn1 = Code1 AND RcvrIn2 = Code2 AND RcvrIn3 = Code3 THEN

    LET Hold = 0

    LET CodeValid = 1

ENDIF

IF CodeValid = 0    THEN

    LET Hold = 1

    LET HoldCnt = 0

ENDIF

PAUSE 500

NotMine:

SETINT  %00001000,%00001000    'Interrupt when C,3 high

RETURN