Jump to content
Sign in to follow this  
makro2

how to combine set_bit and clear_bit

Recommended Posts

I'd like to have a function which works like this

bit( variable, bitnum, high/low );

 

I just added optocouplers to my project, so some signals got inverted. That's why i need easy way to invert some signals.

--------------------------------------------

example:

#define cs_enabled 1

#define data_high   1

 

bit( portb, CS, cs_enabled);

Share this post


Link to post
Share on other sites
Guest Pavel

If a dedicated function isn't a must you can use the ^ operation. Something like:

 

#define FLIPBIT(a,b)   a ^= 1<<b

 

Than to toggle a bit (for example bit 0 of port ;) use expression:

 

...
FLIPBIT(portb,0);
...

 

Regards,

Pavel

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...