Jump to content
Sign in to follow this  
moyoyoyo

how to do multiple outputs 1 instruction

Recommended Posts

THis should be a no brainer for you guys but I tried it at home and it didn't work. Lets say that I want to set 2 output pins on my PIC16f84 hight. Can I do this in one single isntruction or would I need 2 instruction.

 

exsample,

 

 set_high_portb(0x60) ;\* is this legal or would I have to do*/

 

set_high_portb(5)

set_high_portb(6)

Share this post


Link to post
Share on other sites
Guest Skywalker

Just use a logical AND

 

easy example to set the second and the eights Pin of PortB to high:

void main(void)

{

 PORTB = PORTB & 10000010b; // =130dec = 82hex (0x82 in c2c)

} :D

Share this post


Link to post
Share on other sites
Guest coolfire

Hi

 

just try

 

void main(void)

{

 PORTB = PORTB & 10000010b; // =130dec = 82hex (0x82 in c2c)

} :D

Share this post


Link to post
Share on other sites

wait a minute. lets say I do as you guys say.

 

portb = portb & 0x82

 

the output of portb should be 10000010

 

now lets say later on I call a function and in the function I have the following comand

 

portb = portb & 0x86

 

The question is the following. Is the output of portb going to be equal 0x86 (10000110) or is it going to be (0x86 & 0x82) which as I understand it it will result in 0x82?

Share this post


Link to post
Share on other sites
Guest tkeze543

If portb originaly = 0x00 then the output would be 0x00 if you want to set specific bits and leave the rest unchanged then perform an OR function on them.

 

PORTB = PORTB | 0x82;

 

If you want to change the port totally then set the port equal to the value that you want.

 

PORTB = 0x82;

 

If you need to clear specific bits and leave others unchanged then AND them with the inverted value of the bits you wish to set. Lets say you want to clear the bits that where set originally, PORTB = PORTB|0x82, then perform the following PORTB = PORTB & ~(0x82).

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...