Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8bit number distributed to 8 pins

Status
Not open for further replies.

georgz

Full Member level 1
Full Member level 1
Joined
Jun 5, 2010
Messages
99
Helped
9
Reputation
18
Reaction score
5
Trophy points
1,288
Location
space
Activity points
1,832
Hi everyone, i want what the title describes. I have an 8bit number which
i want every one bit to be distributed to one of 8 pin of my microcontroller.
I use assembly, i havent found any command that could make my life easier
so here i am.
 

mov PORT, DATA

or in PIC

movfw DATA
movwf PORTB
 

    georgz

    Points: 2
    Helpful Answer Positive Rating
I should be more specific, i use pic.
@Kurenai_ryu i cant find a 'movfw' command anywhere
are you sure that it exist? With movwf command
i cant use one pin but 8 all together.
I want the command to be 'movwf PORTB,0'

Added after 5 minutes:

Let me give you an example to make things easier for both of us. Lets say that i use a variable, call it 'temp'.
Variable 'temp' has a value that is 80. 80 in binary is 1010000. So want this:
bcf PORTB,0
bcf PORTB,1
bcf PORTB,2
bcf PORTB,3
bcf PORTB,4
bsf PORTB,5
bcf PORTB,6
bsf PORTB,7
 

is this some kind of trick question?

wouldn't "PORTB = 0b10100000;" do it?

or its assembly equivalent.
 

If bits should be lsb -> portb.0 to msb -> portb.7 do like this:

banksel TRISB
clrf TRISB
banksel PORTB

movf DATA,w
movwf PORTB

DATA holds 8 bit value that will be transferred to PORTB. The similar procedure is needed for other ports. banksel is assembler macro and sets bank where TRISB registers reside. It is required for PIC16F series.

BR
 

    georgz

    Points: 2
    Helpful Answer Positive Rating
I get it now, so the 8bit value of the temp will be assigned bit by bit to the 8 pins of PORTB with this command automatically. Nice!
 

just to clarify...

the movfw is not a instruction of PIC itself, is a macro of PIC, say:

movfw PORTB

means

movf PORTB,W

{where W stands for '0'}

i like it more than movf reg,0 because sometimes i forgot the 0.. and movf reg just move the register over itself! (movf reg,1 by default....)
 

I try to avoid writing assembler but when I do I use macros & have W defined as zero to try to help it make more sense when you try to read it.

Keith.
 

Does anyone have any tutorial or guide about macros and instructions???

@keith1200rs, i really consider to learn C. I know that is easier to program with C but assembly gives you full controll over the pic.
 

georgz said:
... but assembly gives you full controll over the pic.

So does C.

I am not saying everyone should use C, just that I prefer it, at least on the larger PICs.

It is a while since I used them but Microchip used to include some useful macros - 16 bit code for example. Try searching their web site or maybe the help in MPLAB. Macros can help to make the code easier to follow.

Keith
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top