Question: The DPS register selects whether the usual DPH0/DPL0 pair is active or whether DPH1/DPL1 is active. However, this concept doesn't seem to work for all DPTR-related instructions, particularly the register load instructions. The following code illustrates the problem (it is a fast copy routine, with pointers to source and destination, a byte count in R3): mov DPS,#0 ;initialize the DPS reg (1) mov DPH,R4 ;load destination pointer from R4, R5 (2) mov DPL,R5 ;R5 has low pointer (3) inc DPS ;switch data pointers (4) mov DPH,R6 ;load source ptr from parms in R6, R7 (5) mov DPL,R7 ;R7 has low pointer (6) loop: movx A,@DPTR ;get byte from source pointer (8) inc DPTR ;advance the source pointer (9) inc DPS ;switch to destination pointer (10) movx @DPTR,A ;store byte in destination (11) inc DPTR ;advance destination pointer (12) inc DPS ;switch back to source pointer (13) djnz R3,loop ;decrement count, loop back for more (14) ret ;done (15) The problem occurs in lines 5 and 6. Even though there was an instruction in line 4 to switch to the other data pointer (inc DPS), the statements in lines 5 and 6 appear to overwrite special function register addresses 82H and 83H, not 84H and 85H. In other words, even though you might think that the second data pointer is the active data pointer, instructions that reference DPH and DPL always refer to the first (DPH0/DPL0) data pointer. In order to initialize the second data pointer (DPL1 and DPH1) properly, one must explicitly reference DPL1 and DPH1. Thus lines 5 and 6 must be coded as: mov DPH1,R6 ;load source ptr from parms in R6, R7 (5) mov DPL1,R7 ;R7 has low pointer (6) This seems to work. How can this problem be explained?
By performing an inc DPS, this selects whether DPTR is pointing at DPH0/DPL0 or DPH1/DPL1. Thus, without using the DPTR reference, one must explicitly address DPHx/DPLx. Please see page 6-19 of the EZ-USB Series 2100 Technical Reference Manual for the normal usage of the dual data pointers.
The steering via DPS occurs only for instructions that access the whole DPTR, not for instructions that access halves of the DPTR register (as you were trying to do). So, a MOV DPTR,#8000H could go into either DPTR1 or DPTR0, depending on the state of DPS, while a reference to DPH or DPL always means DPH0 or DPL0.