This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MOV PORT, A not working appropriately.

I'm running this code:

;; Test 8 operations
MOV R0,#08
LOOP: MOV A,P2
JB P1.1, L
RR A
JMP CONT
L: RL A
CONT: MOV P2,A
MOV P2,A
DJNZ R0,LOOP
END

And when I execute (MOV P2,A) it just moves to the latch, not to the pins. So that when I read it again I'll a wrong result.

Parents
  • A classic 8051 have no input/output configuration. The pins are always outputs but the pins have strong drive low, while only weak pull-up to hold them high.

    So when using them as inputs you write a one to the bit position. Then external electronics can override the pull-up and force the pin low. So while a write of 0cFF makes all pins usable as inputs, the reading of the port will indicate the actual pin state after external electronics have had a chance to override.

    But that also mean that when you write a zero to the port pin, it gets locked as low and will read back as low.

    Do you now see an issue with having a loop that multiple times reads and writes the port and tries to shift the result?

Reply
  • A classic 8051 have no input/output configuration. The pins are always outputs but the pins have strong drive low, while only weak pull-up to hold them high.

    So when using them as inputs you write a one to the bit position. Then external electronics can override the pull-up and force the pin low. So while a write of 0cFF makes all pins usable as inputs, the reading of the port will indicate the actual pin state after external electronics have had a chance to override.

    But that also mean that when you write a zero to the port pin, it gets locked as low and will read back as low.

    Do you now see an issue with having a loop that multiple times reads and writes the port and tries to shift the result?

Children
  • Is this pull-up resistor "configuration" important if I'm only running the code on the Keil debugger?

    "Do you now see an issue with having a loop that multiple times reads and writes the port and tries to shift the result?"

    Not exactly. This is my code/issue:

    
                    ORG             0000h
                    JMP             0100h
                    ORG             0100h
    
    
            MOV     R0,#7
    
    LOOP1:  CLR     C
                    MOV             A,P1
                    RRC             A
                    MOV             P1,A ;This one works perfectly
                    DJNZ    R0,LOOP1
    
                    MOV     R0,#7
    
    LOOP2:  CLR     C
                    MOV             A,P1
                    RLC             A
                    MOV             P1,A ;But, for some reason, this one just send the 
    ;value to the latch
                    DJNZ    R0,LOOP2
    
                    END