how to programe 8051 port by binary number ?

Thread Starter

thar07

Joined Jan 3, 2015
71
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.
 

ScottWang

Joined Aug 23, 2012
7,501
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
 

Thread Starter

thar07

Joined Jan 3, 2015
71
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

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

MrChips

Joined Oct 2, 2009
34,807
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
 

ScottWang

Joined Aug 23, 2012
7,501
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.
 
Top