

;----
; in data area have...
;
CURR:	DS	1			;place to hold current port 2 sample
PREV:	DS	1			;place to hold previous port 2 sample

;----
; setup in system initialize
;
INIT:
    MOV   P2, #0FFH              ;ensure that P2 works as inputs
    MOV   CURR, #0FFH            ;Init the Current and previous values
    MOV   PREV, #0FFH
;----
; then in your main polling loop
;
MAIN_LOOP:
    MOV   A, P2                  ;get current input states
    MOV   CURR, A                ;save as current value
;                                               
DO_GO_TO_LOWS:                   ;        ____
    CPL   A                      ;compute CURR * PREV
    ANL   A, PREV                ;such that 1 bits show changes from 1->0
;
B0_LOW:
    JNB   ACC.0, B1_LOW
;
    PUSH  ACC
    CALL  PROC_P2_0_LOW          ;go off to handle the action for P2.0 going low
    POP   ACC
;
B1_LOW:
    JNB   ACC.1, B2_LOW
;
    PUSH  ACC
    CALL  PROC_P2_1_LOW          ;go off to handle the action for P2.1 going low
    POP   ACC
;
B2_LOW:
    JNB   ACC.2, B3_LOW
;
    PUSH  ACC
    CALL  PROC_P2_2_LOW          ;go off to handle the action for P2.2 going low
    POP   ACC
;
B3_LOW:
    JNB   ACC.3, B4_LOW
;
    PUSH  ACC
    CALL  PROC_P2_3_LOW          ;go off to handle the action for P2.3 going low
    POP   ACC
;
B4_LOW:
    JNB   ACC.4, B5_LOW
;
    PUSH  ACC
    CALL  PROC_P2_4_LOW          ;go off to handle the action for P2.4 going low
    POP   ACC
;
B5_LOW:
    JNB   ACC.5, B6_LOW
;
    PUSH  ACC
    CALL  PROC_P2_5_LOW          ;go off to handle the action for P2.5 going low
    POP   ACC
;
B6_LOW:
    JNB   ACC.6, B7_LOW
;
    PUSH  ACC
    CALL  PROC_P2_6_LOW          ;go off to handle the action for P2.6 going low
    POP   ACC
;
B7_LOW:
    JNB   ACC.7, DO_GO_TO_HIGHS
;
    PUSH  ACC
    CALL  PROC_P2_7_LOW          ;go off to handle the action for P2.7 going low
    POP   ACC
;
DO_GO_TO_HIGHS:
    MOV   A, PREV                ;               ____
    CPL   A                      ;compute CURR * PREV
    ANL   A, CURR                ;such that 1 bits show changes from 0->1
;
B0_HIGH:
    JNB   ACC.0, B1_HIGH
;
    PUSH  ACC
    CALL  PROC_P2_0_HIGH         ;go off to handle the action for P2.0 going high
    POP   ACC
;
B1_HIGH:
    JNB	ACC.1, B2_HIGH
;
    PUSH  ACC
    CALL  PROC_P2_1_HIGH         ;go off to handle the action for P2.1 going high
    POP   ACC
;
B2_HIGH:
    JNB   ACC.2, B3_HIGH
;
    PUSH  ACC
    CALL  PROC_P2_2_HIGH         ;go off to handle the action for P2.2 going high
    POP   ACC
;
B3_HIGH:
    JNB   ACC.3, B4_HIGH
;
    PUSH  ACC
    CALL  PROC_P2_3_HIGH         ;go off to handle the action for P2.3 going high
    POP   ACC
;
B4_HIGH:
    JNB   ACC.4, B5_HIGH
;
    PUSH  ACC
    CALL  PROC_P2_4_HIGH         ;go off to handle the action for P2.4 going high
    POP   ACC
;
B5_HIGH:
    JNB   ACC.5, B6_HIGH
;
    PUSH  ACC
    CALL  PROC_P2_5_HIGH         ;go off to handle the action for P2.5 going high
    POP   ACC
;
B6_HIGH:
    JNB   ACC.6, B7_HIGH
;
    PUSH  ACC
    CALL  PROC_P2_6_HIGH         ;go off to handle the action for P2.6 going high
    POP   ACC
;
B7_HIGH:
    JNB   ACC.7, DO_END_CLEANUP
;
    PUSH  ACC
    CALL  PROC_P2_7_HIGH         ;go off to handle the action for P2.7 going high
    POP   ACC
;
DO_END_CLEANUP:
    MOV   A, CURR                ;save the currrent value as next loops previous value
    MOV   PREV, A
;
    JMP   MAIN_LOOP              ;loop to repeat the polling

;------
; then you have these action subroutines
; to fill in with action code.
;

;
;action for P2.0 going to low
;
PROC_P2_0_LOW:       
   RET
;
;action for P2.1 going to low
;
PROC_P2_1_LOW:       
   RET
;
;action for P2.2 going to low
;
PROC_P2_2_LOW:       
   RET
;
;action for P2.3 going to low
;
PROC_P2_3_LOW:       
   RET
;
;action for P2.4 going to low
;
PROC_P2_4_LOW:       
   RET
;
;action for P2.5 going to low
;
PROC_P2_5_LOW:       
   RET
;
;action for P2.6 going to low
;
PROC_P2_6_LOW:       
   RET
;
;action for P2.7 going to low
;
PROC_P2_7_LOW:       
   RET
;
;action for P2.0 going to high
;
PROC_P2_0_HIGH:       
   RET
;
;action for P2.1 going to high
;
PROC_P2_1_HIGH:       
   RET
;
;action for P2.2 going to high
;
PROC_P2_2_HIGH:       
   RET
;
;action for P2.3 going to high
;
PROC_P2_3_HIGH:       
   RET
;
;action for P2.4 going to high
;
PROC_P2_4_HIGH:       
   RET
;
;action for P2.5 going to high
;
PROC_P2_5_HIGH:       
   RET
;
;action for P2.6 going to high
;
PROC_P2_6_HIGH:       
   RET
;
;action for P2.7 going to high
;
PROC_P2_7_HIGH:       
   RET
;

