⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 button_handler.lst

📁 PKE(被动无钥门禁系统
💻 LST
📖 第 1 页 / 共 2 页
字号:
MPASM 03.90.01 Released                    BUTTON_HANDLER.ASM   11-21-2005  16:07:20         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00001 
                      00002 ;/*
                      00003 ;       Button_Handler.asm
                      00004 ;       
                      00005 ;       This class handles button events
                      00006 ;
                      00007 ;       Jan Ornter
                      00008 ;
                      00009 ;       DATE:   11-9-2005
                      00010 ;       VER.:   1.0
                      00011 ;
                      00012 ;       A simple sample implemantation is the following:
                      00013 ;
                      00014 ;       Implement the Button_Handler function (this is the function which 
                      00015 ;       is been called from the main routine. Disable the REC_EVENT (setting 
                      00016 ;       the correct bit in IOCA to zero). As the basestation may block 
                      00017 ;       RF-Communication, any RF-Message should be transmitted several times.
                      00018 ;       This is done by adding a counter in this handler routine and counter in
                      00019 ;       the interrupt service routine of Timer0, as this is counting the IDLE time
                      00020 ;       anyway. When EVENT_REG,0 is one (falling edge on RA0 occurred) 
                      00021 ;       then send (for example) an open door command over the RF interface.
                      00022 ;       When the repeat counter has finished, clear the Button events.
                      00023 ;       Enable REC_EVENT and return.
                      00024 ;
                      00025 ;*/
                      00026 
                      00027 #include Project.inc
                      00001 
                      00002 
                      00003         list p=16F636                           ; list directive to define processor
                      00004         #include <p16f636.inc>      ; processor specific variable definitions
                      00001         LIST
                      00002 ; P16F636.INC  Standard Header File, Version 1.00    Microchip Technology, Inc.
                      00317         LIST
                      00005 
                      00006         ERRORLEVEL 0,-302,-312  ; Messages, Warnings and Errors Printed
                      00007                                         ; Ignore [301] => Processor Mismatch. 
                      00008                                         ; Ignore [302] => Register in operand not in bank 0. 
                      00009                                                                 ; Ignore [312] => Pagesel not needed for
                             Device
                      00028 #include PIC16F639.inc
                      00001 
                      00002 #define CommsLED        PORTC,0         ; LED D4
                      00003 #define ErrorLED        PORTA,5         ; LED D5
                      00004 
                      00005 
                      00006 
                      00007 #define LFDATA          PORTC,3         ; Low Frequency Data IN
                      00008 
                      00009 #define REC_EVENT       4
                      00010 #define IDLE            6
                      00011 #define RF_START        7
                      00012 #define RF_Button       0
MPASM 03.90.01 Released                    BUTTON_HANDLER.ASM   11-21-2005  16:07:20         PAGE  2


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00013 
                      00014 
                      00015         ifndef MSG_INTERRUPT
                      00016         #define MSG_INTERRUPT   (1<<REC_EVENT)
                      00017         endif
                      00018 
                      00019 
                      00020         ifndef BUTTON_MASK
                      00021         #define BUTTON_MASK             B'00000001'
                      00022         endif
                      00023 
                      00024 
                      00025 ;/*
                      00026 ;       This register indicates the occurred events
                      00027 ;
                      00028 ;       @bitfield       N.A. | IDLE | RA5_EVENT | MSG_INTERRUPT | RA3_EVENT | RA2_EVENT | RA1_EVENT | RA
                            0_EVENT |
                      00029 ;
                      00030 ;*/
  0000                00031         extern  EVENT_REG
                      00032 ;/*
                      00033 ;       This register is a copy of PORTA, when the last button event occured
                      00034 ;*/
  0000                00035         extern  Button_old
                      00036 ;/*
                      00037 ;       Referrence to the DATA in the EEPROM.
                      00038 ;       The first four bytes are the Serial number
                      00039 ;       The next eight bytes are the Encryption Key
                      00040 ;*/
  0000                00041         extern  EE_DATA
                      00042 ;/*
                      00043 ;       Referrence to the beginning of userspace EEPROM memory.
                      00044 ;       The following 8 bytes are reserved for that purpose.
                      00045 ;*/
  0000                00046         extern  EE_USER
                      00047 
                      00048 
  0000                00049         extern  BUTTON_DELAY
                      00029 #include RF.inc
                      00001 
                      00002 #ifndef RF_INC
                      00003 #define RF_INC
                      00004 
                      00005 
                      00006 #ifndef RF.PIN
                      00007         #define RF.PIN          5               ; RF Modulation Output
                      00008         #define RF.PORT         PORTC
                      00009 #endif
  0000                00010         extern RF.Send_Header, RF.Send_Data, RF.SendBuffer
                      00011 
                      00012 
                      00013 
                      00014 ;/*
MPASM 03.90.01 Released                    BUTTON_HANDLER.ASM   11-21-2005  16:07:20         PAGE  3


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00015 ;
                      00016 ;       This macro initialises the RF module.
                      00017 ;       Initialize the Delay module first.
                      00018 ;
                      00019 ;*/
                      00020 RF.Init macro
                      00021         banksel TRISA
                      00022         bcf             RF.PORT,RF.PIN
                      00023         endm
                      00024 
                      00025 
                      00026 #endif
                      00030 
  0000                00031         global Button_Handler, Button_Handler_Init
                      00032 
                      00033 #define Delay   0x03
                      00034 #define Retry   0x0f
                      00035 
                      00036 
                      00037 Button_Handler_VAR      udata
0000                  00038 Counter         res 1
                      00039 
                      00040 
                      00041         code
                      00042         
                      00043 ;/*
                      00044 ;
                      00045 ;       Initilizes needed registers for the BUTTON_HANDLER
                      00046 ;
                      00047 ;       @auto-stack
                      00048 ;
                      00049 ;*/
0000                  00050 Button_Handler_Init
0000   ???? ????      00051         banksel Counter
0002   01??           00052         clrf    Counter
0003   01??           00053         clrf    BUTTON_DELAY
0004   0008           00054         return
                      00055         
                      00056 ;/*
                      00057 ;
                      00058 ;       This method is called by the main routine whenever a button event occurs.
                      00059 ;
                      00060 ;       @auto-call
                      00061 ;       
                      00062 ;       @auto-stack
                      00063 ;
                      00064 ;*/
0005                  00065 Button_Handler
0005   ???? ????      00066         banksel Counter
0007   08??           00067         movf    Counter,f
0008   1D03           00068         btfss   STATUS,Z                                ; is counter zero?
0009   2???           00069         goto    Button_Count                    ; no, then count down
000A   300F           00070         movlw   Retry                                   ; yes, then load counter (first call after butto
MPASM 03.90.01 Released                    BUTTON_HANDLER.ASM   11-21-2005  16:07:20         PAGE  4


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                            n has been pressed)
000B   00??           00071         movwf   Counter
000C   3003           00072         movlw   Delay                                   ; load delay counter again
000D   00??           00073         movwf   BUTTON_DELAY
000E                  00074 Button_Count
000E   1F80           00075         btfss   EVENT_REG, RF_START
000F   2???           00076         goto    END_BUTTON_HANDLER
0010   0B??           00077         decfsz  Counter,f                               ; is Counter one?
0011   2???           00078         goto    Button_Exec                             ; no, then transmit RF
0012   30FE           00079         movlw   (~BUTTON_MASK)                  ; yes, then clear all button events
0013   05??           00080         andwf   EVENT_REG,f
0014   2???           00081         goto    END_BUTTON_HANDLER
0015                  00082 Button_Exec
0015   3003           00083         movlw   Delay                                   ; load delay counter again
0016   00??           00084         movwf   BUTTON_DELAY
0017   1380           00085         bcf             EVENT_REG, RF_START             ; clear delay flag
                      00086         
                      00087         
                      00088         ;The action on a pressed button
0018                  00089 BOOT_BTN
0018   1C00           00090         btfss   EVENT_REG, RF_Button    ; was the button on RA0 pressed?
0019   2???           00091         goto    MIDDLE_BTN                              ; no, then end (the only used button)
001A   2???           00092         call    RF.Send_Header                  ; yes, then send a data packet over the RF-Interface
001B   3064           00093         movlw   0x64
001C   2???           00094         call    RF.Send_Data                    ;Send a command
                      00095 
001D                  00096 MIDDLE_BTN      
                      00097 ;       btfss   EVENT_REG, 2                    ; was the button on RA2 pressed?
                      00098 ;       goto    LOCK_BTN                                ; no, then end (the only used button)
                      00099 ;       call    RF.Send_Header                  ; yes, then send a data packet over the RF-Interface
                      00100 ;       movlw   0x65
                      00101 ;       call    RF.Send_Data                    ;Send a command
                      00102         
001D                  00103 LOCK_BTN
                      00104 ;       btfss   EVENT_REG, 3                    ; was the button on RA3 pressed?
                      00105 ;       goto    UNLOCK_BTN                              ; no, then end (the only used button)
                      00106 ;       call    RF.Send_Header                  ; yes, then send a data packet over the RF-Interface
                      00107 ;       movlw   0x66
                      00108 ;       call    RF.Send_Data                    ;Send a command
                      00109         
001D                  00110 UNLOCK_BTN
                      00111 ;       btfss   EVENT_REG, 4                    ; was the button on RA4 pressed?
                      00112 ;       goto    ALERT_BTN                               ; no, then end (the only used button)
                      00113 ;       call    RF.Send_Header                  ; yes, then send a data packet over the RF-Interface
                      00114 ;       movlw   0x67
                      00115 ;       call    RF.Send_Data                    ;Send a command
                      00116         
001D                  00117 ALERT_BTN
                      00118 ;       btfss   EVENT_REG, 5                    ; was the button on RA5 pressed?
                      00119 ;       goto    END_BUTTON_HANDLER              ; no, then end (the only used button)
                      00120 ;       call    RF.Send_Header                  ; yes, then send a data packet over the RF-Interface
                      00121 ;       movlw   0x68
                      00122 ;       call    RF.Send_Data                    ;Send a command
MPASM 03.90.01 Released                    BUTTON_HANDLER.ASM   11-21-2005  16:07:20         PAGE  5


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00123         
                      00124         
001D                  00125 END_BUTTON_HANDLER
001D   0008           00126         return
                      00127         
                      00128         END
MPASM 03.90.01 Released                    BUTTON_HANDLER.ASM   11-21-2005  16:07:20         PAGE  6

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -