| ??? 05/12/03 02:41 Read: times |
#45273 - RE: project Responding to: ???'s previous message |
I have read this discussion and come to the conclusion that there is some confusion all around. It seems as if Lance wants to have an action take place at the changes of the port 2 pins and not based upon their current level at any given time. It is thus necessary to apply some state logic to detect specifically when these changes take place.
I show a block of code below that will perform these checks for all 8 bits of port 2. This will function nicely as long as the high or low levels persist on the inputs at P2 for at least as long as it takes the program to make one iteration of the main polling loop. This code is shown with a bunch of calls to subroutines that will provide the actions needed for each port 2 bit state change. It could be possible eliminate one or more of these subroutines and put the action code right in line in place of the call however this is not a particularly modular way to program stuff like this. Even though this code seems long I made it this way so that it is easier to understand. There are ways to make the code much shorter by using a look-up-table that has entries with the mask values and corresponding subroutine address pointers. The poll code would then scan the port 2 detect bits in a loop and call the appropriate subroutines indirectly through the table. (However showing how to do that is subject for another time). Lastly. Please note that I just threw this code together and did not run it through an assembler so it may or may not assemble the first time you try it. Here it is........................................
;----
; 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
;
Hope this helps. Michael Karas |



