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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/12/04 06:53
Read: times


 
#75791 - RE: Using Port2 for RAM & I/O simultaneously
Responding to: ???'s previous message
hi,

Can I use the rest of the pins of port 2 for I/O?

Generally, you should avoid it. If your hardware uses external memory access then it is not so hard to implement extra input/output ports as memory mapped ports.
So read next lines below just as a trick which I do not recommend to use.

In fact, you may utilize these pins as output ones. But it requires some care about such way. As you know, during MOVX port 2 outputs high byte of external memory address. This byte comes either from DPH (if you use MOVX @DPTR) or from SFR P2 (if you use MOVX @Ri). Thus you need keep corresponded bits of DPH/P2 at correct state.
For example, how it may look in ASM:
; using free bits as output ones
CLR  P2.7
SETB P2.5
; ...
; now we need read external memory
MOV  DPTR,#MEM_ADDR
MOV  A,P2            ; read current state of bits
ANL  A,#11111000b    ; mask address bits
ORL  DPH,A           ; keep output bits at their state
MOVX A,@DPTR

In some cases MOV A,P2 may return wrong value (due weak pull-up of P2). If such schematics is used, then there are some ways:
1) keep local copy of output bits` states and use it instead P2 contents:
CLR  P2.7
CLR  P2_COPY.7
SETB P2.5
SETB P2_COPY.5
; ...
MOV  DPTR,#MEM_ADDR
MOV  A,P2_COPY       ; read copy of current state of bits
ANL  A,#11111000b    ; mask address bits
ORL  DPH,A           ; keep output bits at their state
MOVX A,@DPTR

2) using read-modify-write instructions and Ri instead DPTR, something like:
CLR  P2.7
SETB P2.5
; ...
ANL  P2,#11111000b      ; mask address bits
ORL  P2,#HIGH(MEM_ADDR) ; prepare high byte of address
MOV  R0,#LOW(MEM_ADDR)  ; load low byte of address
MOVX A@,R0

As about using rest of pins as input ones, so it requires external hardware by which it will be possible to disable a source during MOVX.

Regards,
Oleg

List of 17 messages in thread
TopicAuthorDate
Using Port2 for RAM & I/O simultaneously            01/01/70 00:00      
   RE: Using Port2 for RAM & I/O simultaneously            01/01/70 00:00      
      RE: Using Port2 for RAM & I/O simultaneously            01/01/70 00:00      
   RE: Using Port2 for RAM & I/O simultaneously            01/01/70 00:00      
      RE: Using Port2 for RAM & I/O simultaneously            01/01/70 00:00      
         RE: Using Port2 for RAM & I/O simultaneously            01/01/70 00:00      
            RE: Using Port2 for RAM & I/O simultaneously            01/01/70 00:00      
            RE: Using Port2 for RAM & I/O simultaneo            01/01/70 00:00      
         RE: Using Port2 for RAM & I/O simultaneo            01/01/70 00:00      
            RE: Using Port2 for RAM & I/O simultaneo            01/01/70 00:00      
               RE: Using Port2 for RAM & I/O simultaneo            01/01/70 00:00      
                  RE: Using Port2 for RAM & I/O simultaneo            01/01/70 00:00      
                     RE: Using Port2 for RAM & I/O simultaneo            01/01/70 00:00      
   Only as an input?            01/01/70 00:00      
      RE: Only as an input?            01/01/70 00:00      
         RE: Only as an input?            01/01/70 00:00      
            RE: Only as an input?            01/01/70 00:00      

Back to Subject List