Mov r1, r0, mcu 8051

MrChips

Joined Oct 2, 2009
30,800
What is the question?

Perhaps you are asking where is the read-modify-write?

This is done internally by the hardware.
The port register is read.
Then it is modified by XOR with a literal constant.
Finally it is written back to the port register.

Three instructions have been replaced by one instruction.
 

BillO

Joined Nov 24, 2008
999
Hi

Please help me with the query included in the attachment. Thank you.

Regards
PG
The instruction:

XLR P1, #0FFH

Reads port 1, XOR's that value with 0FFH then writes the result back out to port 1.

So, the one instruction does the read-modify-write.
"Description: XRL does a bitwise "EXCLUSIVE OR" operation between operand1 and operand2, leaving the resulting value in operand1. The value of operand2 is not affected. A logical "EXCLUSIVE OR" compares the bits of each operand and sets the corresponding bit in the resulting byte if the bit was set in either (but not both) of the original operands, otherwise the bit is cleared."
In this case, operand 1 is port1 and operand 2 is the constant value FF (1111 1111).

Just like Mr. Chips said.
 

Thread Starter

PG1995

Joined Apr 15, 2011
832
Hi

A port of 8051 must be written with 0xFF to make it an input port so that data can be received. Suppose, port 1 is being used as an input port. Then, this instruction is performed: MOV P1, #23. This instruction simply means that the P1 is now used as an output port and it is no longer an input port, right? In order to make it an input port once again, we need to program it with 0xFF. In other words, when you have programmed a port to be an input port by writing 1's to it, then you shouldn't use instructions such as "MOV Px, #Data" because after the execution of these instructions the port would cease to be an input one. Do I have it write? Please let me know. Thanks.

Regards
PG
 

BillO

Joined Nov 24, 2008
999
Yes, you have the right idea. You need to write 1 to any pin that you use as an input because of the way the port IO is designed on an 8051. However, any pin that has been set to logic 1 can be used as an input while it is still at logic 1.

Unless you need all pins of a port as input, you do not have to write FF to the port. As an example, you could keep the 4 MSB high and use them as inputs while using the 4 LSB as outputs. That way the data being written to the port would have a value from 0 to F then to keep the 4 MSB as input OR the data byte with 0xF0 before writing to the port.

I hope I did not confuse you, as this is an interesting and a kind of complicated component of 8051 programming.
 

Thread Starter

PG1995

Joined Apr 15, 2011
832
Yes, you have the right idea. You need to write 1 to any pin that you use as an input because of the way the port IO is designed on an 8051. However, any pin that has been set to logic 1 can be used as an input while it is still at logic 1.

Unless you need all pins of a port as input, you do not have to write FF to the port. As an example, you could keep the 4 MSB high and use them as inputs while using the 4 LSB as outputs. That way the data being written to the port would have a value from 0 to F then to keep the 4 MSB as input OR the data byte with 0xF0 before writing to the port.

I hope I did not confuse you, as this is an interesting and a kind of complicated component of 8051 programming.
Thanks a lot, BillO.

Yes, you have de-confused me! :)

Best wishes
PG
 

Thread Starter

PG1995

Joined Apr 15, 2011
832
Hi

Could you please help me with the queries below? It would be really nice of you. I have an exam tomorrow and I need your help. Thanks.

You could find Q1 here, Q2 here, and Q2, Q3, Q4, and Q5 here. Thank you.

Regards
PG

PS: If you are unable to see the images, then please use this username:imgshack4every1 and password:imgshack4every1 to log into the imageshack. Hopefully, it would resolve the issue. Thanks.
 
Last edited:

absf

Joined Dec 29, 2010
1,968
Could you please help me with the queries below? It would be really nice of you. I have an exam tomorrow and I need your help. Thanks.

You could find Q1 here, Q2 here, and Q2, Q3, Q4, and Q5 here. Thank you.
Have to register in order to get to your questions?

Allen
 

Thread Starter

PG1995

Joined Apr 15, 2011
832
Have to register in order to get to your questions?

Allen
Hi Allen

I don't think so. Because I have used direct links to the images and I have just checked it by signing out of my imageshack account and was still able to view the images. If the problem still persists on your end, then let me know. I would try to attach the images here but attaching them here would lower their resolution. Thanks.

Regards
PG
 

BillO

Joined Nov 24, 2008
999
Q1 - If the device you are controlling is really slow, you might need a delay, but according to the text, it is an edge triggered device, so usually no delay would be needed.

Q2 - We covered this in the past. See post #26.

Q3 - The latch is associated with using the port for output. The latch is set by a write to the port.

Q4 - The latch and the port are the same thing. Writing anything to a port affects the latch, so if you wrote #44 to the port, that #44 would be what the latch is set to. In other words, the latch is the output function of the port.

Q5 - The latch is the output of the port. Any time you write data to the port for output, you are writing to the latch. ALE has nothing to do with the port latch. ALE is used to latch data in an external latch to be used as high order address information.
 

Thread Starter

PG1995

Joined Apr 15, 2011
832
Thanks a lot, Bill. It's very nice of you.

I didn't put Q2 clearly. Actually I didn't understand this line, "This type of a program is required to read in data from an A to D converter after verifying if the conversion is over (indicated by showing a high on P2.0 here)."

Is my calculation of extra delay (which is mostly ignored in delay calculations) correct? Please let me know. I have calculated it for AT89C51 using 12 MHz frequency XTAL. Thanks

Rich (BB code):
;-------Delay Subroutine

;period of one MC = 0.001 ms
;75(50(255x2x0.001)) = 1912.5 ms = 2 s

    org 0x300

    Delay:
        mov R0, #75        ;1 MC
    L1: mov R1, #50
    L2: mov R2, #255
    L3: DJNZ R2, L3        ;2 MC
        DJNZ R1, L2
        DJNZ R0, L1 
        RET            ;2 MC

end

;please notice that we have ignored extra delay corresponding to some instructions in the Delay 
;subroutine and this extra delay is: {50(1+2) + 75(1+2) + 2} x 0.001 = 0.377 ms = 0.000377 s
Best wishes
PG
 
Last edited:
Top