Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/30/03 05:43
Read: times


 
#57491 - RE: More on DIP Switch Code
Responding to: ???'s previous message
You know, any of these "test and jump" ... "test and jump" schemes for parsing the multiple cases of a value from a port (or other variable) really are only an appropriate way to handle the job if the number of conditions is really small (say no more than 2 or 3). The list of parsing code gets messy, is hard to maintain (despite what I have heard others claim) and gets longer than the really rather simple table transfer scheme.

In the case of the table method, if there are cases you wish to ignore just include a jump to a routine that does nothing.


DIPSWT_FUNC:
   MOV   A, P2   ; get the DIP switch value
   ANL   A, #0FH ; mask to the low 4 bits
   MOV   B, #3   ; setup the table index * 3
   MUL   AB      ; A = table index
   MOV   DPTR, #TABLE
   JMP   @A+DPTR ; jump to and through table
;
TABLE:
   LJMP  DIP_SWT_IGNOR  ; swt=0 ignore this combination
   LJMP  DIP_SWT_FUNC1  ; swt=1 go to func 1 handler
   LJMP  DIP_SWT_IGNOR  ; swt=2 ignore this combination
   LJMP  DIP_SWT_IGNOR  ; swt=3 ignore this combination
   LJMP  DIP_SWT_IGNOR  ; swt=4 ignore this combination
   LJMP  DIP_SWT_IGNOR  ; swt=5 ignore this combination
   LJMP  DIP_SWT_FUNC6  ; swt=6 go to func 6 handler
   LJMP  DIP_SWT_IGNOR  ; swt=7 ignore this combination
   LJMP  DIP_SWT_FUNC8  ; swt=8 go to func 8 handler
   LJMP  DIP_SWT_IGNOR  ; swt=9 ignore this combination
   LJMP  DIP_SWT_FUNC10 ; swt=10 go to func 10 handler
   LJMP  DIP_SWT_IGNOR  ; swt=11 ignore this combination
   LJMP  DIP_SWT_FUNC12 ; swt=12 go to func 12 handler
   LJMP  DIP_SWT_IGNOR  ; swt=13 ignore this combination
   LJMP  DIP_SWT_FUNC14 ; swt=14 go to func 14 handler
   LJMP  DIP_SWT_IGNOR  ; swt=15 ignore this combination
;
DIP_SWT_IGNOR:
   RET                  ; exit from subroutine if ignore
;
DIP_SWT_FUNC1:          ; Function 1 handler
    ...
    ...
   RET
;
DIP_SWT_FUNC6:          ; Function 6 handler
    ...
    ...
   RET
;
DIP_SWT_FUNC8:          ; Function 8 handler
    ...
    ...
   RET
;
DIP_SWT_FUNC10:         ; Function 10 handler
    ...
    ...
   RET
;
DIP_SWT_FUNC12:         ; Function 12 handler
    ...
    ...
   RET
;
DIP_SWT_FUNC14:         ; Function 14 handler
    ...
    ...
   RET
;


You can see the nice modular and easy to follow code that this approach leads to. It is very easy to add cases to the table or take others away.

Michael Karas


List of 16 messages in thread
TopicAuthorDate
More on DIP Switch Code            01/01/70 00:00      
   RE: More on DIP Switch Code            01/01/70 00:00      
      RE: More on DIP Switch Code            01/01/70 00:00      
         RE: More on DIP Switch Code            01/01/70 00:00      
            RE: More on DIP Switch Code            01/01/70 00:00      
      RE: More on DIP Switch Code            01/01/70 00:00      
      RE: More on DIP Switch Code            01/01/70 00:00      
         RE: More on DIP Switch Code            01/01/70 00:00      
            RE: More on DIP Switch Code            01/01/70 00:00      
               RE: More on DIP Switch Code            01/01/70 00:00      
                  RE: More on DIP Switch Code            01/01/70 00:00      
      RE: More on DIP Switch Code            01/01/70 00:00      
         RE: More on DIP Switch Code            01/01/70 00:00      
      RE: More on DIP Switch Code            01/01/70 00:00      
         RE: More on DIP Switch Code            01/01/70 00:00      
   RE: More on DIP Switch Code            01/01/70 00:00      

Back to Subject List