Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Question

Status
Not open for further replies.

Eng.Remon

New Member
Excuse me i wana know the difference between
mov p1,0ffh
mov p1,#0ffh
if i want p1 to be input port.
thnks
 
I think the one with # is immediate addressing. That may be moving the value of ff into p1. While the other one is direct addressing. Maybe that is moving the content of the address ff into p1.

What microcontroller is that?
 
Can't you find the datasheet of the microcontroller you're using? I wanted to find it, but you never tell which microcontroller is that.

Use PIC.
 
The processor is an 8051 variant.
The instruction you want is:
mov P1,#0FFH
This will write a 1 to the output latch turning on the weak p-channel pullup which allows an external source to pull it low without complaint making it an input.
 
yea it is 8051 but what is
mov p1,0ff does ? thats confusing in fact coz both of them are working :S
 
Eng.Remon said:
yea it is 8051 but what is
mov p1,0ff does ? thats confusing in fact coz both of them are working :S
Just because it works doesn't make it right. The second variant was already explained to you by bananasiong. It moves the contents of the SFR @ 0FFH to the accumulator. What you read from an unimplemented SFR is anybody's guess. If you got lucky and you are reading all 1's then hoo rah for you, you lucky fella.
 
Without the '#', it is direct addressing mode which means the CONTENT at this address (ff) is going to be moved into p1. So it depends what is inside this address.
With the '#', it is immediate addressing mode which means this value (ff) is going to be in p1 after executing this instruction.

Code:
mov p1,0ffh    ;[ff]-->p1, so [p1]=[ff]
mov p1,#0ffh  ;ff-->p1, so [p1]=ff
do you understand the codes above?
 
You should see the "#" as "Direct data" not as "immediate addressing" like bananasiong suggest because there is no address involved, it's constant data .

So you should read
Code:
mov P1, #0FFh
as "Move direct data 0FFh in P1"



Using
Code:
mov P1,0FFh
is bad practice since code isn't readable that way. No one knows what 0FFh represents.


First declare variables using the "ds" and "equ" statements then use the variables you declared.
Code:
;Declare a 16bit counter in RAM
MyCounter:  ds 2

;Assign name to each byte of MyCounter
MyCounterHB equ MyCounter+0
MyCounterLB equ MyCounter+1

;Reset MyCounter
clr a
mov MyCounterHB,a
mov MyCounterLB,a

Don't care about the addresses of "MyCounterHB" and "MyCounterLB" your assembler will handle that for you.

Clear now?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top