how to programe 8051 port by binary number ?

Discussion in 'Embedded Systems and Microcontrollers' started by thar07, Feb 2, 2015.

  1. thar07

    Thread Starter Member

    Jan 3, 2015
    71
    0
    how to program port "p0" to turn on a led connected to its third pin (p0.2) by using binary number as follows?

    mov p1,#11000000B


    p.s :- I can't understand how to access the exact pins by the above method and that is why I'm asking this question. I can do this by bit addressable method.
     
  2. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    Because the Port 0 is an open drain, so the first you need to connecting the LED to port 0.2 and in series with a resistor connecting to Vcc,
    P0.2 ← (-)LED(+) ← Resistor ← +5V.

    mov p0,#00000100B
     
    thar07 likes this.
  3. thar07

    Thread Starter Member

    Jan 3, 2015
    71
    0

    why "mov p0,#00100000B " code does not turn on p0.2 pin ?
     
  4. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    Code (Text):
    1.  
    2. d7 d6 d5 d4 d3 d2 d1 d0
    3. 0  0  0  0  0  1  0  0
    4.  
     
    thar07 likes this.
  5. thar07

    Thread Starter Member

    Jan 3, 2015
    71
    0
    Thank you very much :)
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,439
    3,360
    Setting or clearing a single bit depends on whether the MCU has single bit accessibility. If there is no such thing on the MCU then you have to resort to bit-wise OR operation to set a bit and NEGATED AND operation to clear a bit.

    Fortunately for you, the 8051 CPU has bit addressable CLR and SETB instructions. These are implemented in a rather unorthodox manner. There are 128 bit-addressable bits.

    To directly set bit-0 of PORT0 you can use
    SETB 80h

    or you can use
    SETB P0.0

    To clear bit-7 PORT0

    CLR 87h

    or

    CLR P0.7
     
  7. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    When we using SETB command, if we need to mix some data of other pins and send out to the port, then it will meet the problem.
     
Loading...