Jump to content
Sign in to follow this  
Badejavu

Addressing Bits In Boost C

Recommended Posts

I am trying to send a 16bit data with MSB first over serial comm. How can I get around sending the individual bits 15-0 using the boostC compiler using the sample below e.g. SIN = data.15……SIN = data.0.
void play_AUDIO_COMMAND(unsigned short data)
{
for (unsigned char loop =15; loop>=0; loop--)
{
SIN = data.loop;// Compiler gives error
SCLK = HIGH;
delay_us(50);
SCLK = LOW;
}
SCLK = HIGH;

}

 

 

Error message:

Main1.CAudio.C(47:17): error: unexpected '.' operator

Audio.C(47:12): error: failed to generate expression

Audio.C(47:12): error: invalid operand 'data.loop'

Audio.C(47:10): error: failed to generate expression

 

 

 

Thanks

Bade

Share this post


Link to post
Share on other sites

SIN = (data >>loop) & 1;

 

or

 

SIN = (data & (1>>loop)) ? 1 : 0;

 

Which ever produces the smallest code.

Share this post


Link to post
Share on other sites

Thanks..I was hoping I could address it directly using the compiler.

P.S .Your second approach(?: conditional assignment) was helpful . I just learned it, hopefully it will help me shorten other "if else" statements :)

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