Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 3 of 3

Thread: bitwise operation help

  1. #1

    bitwise operation help

    given a register, eg MCUCR
    when i have code like this
    MCUCR |= _BV(some number here)
    doesit only mean a simple "OR" on both, or it does also other thing.
    I am asking because when i compile the code i get a warning sayint that left shif is >= to width type (for MCUCR).

  2. #2
    You mind telling us what language/platform this is on? I did some googling on that _BV, looks like a C macro involving Atmel 8-bit microcontrollers or something?

    Quote Originally Posted by http://www.micahcarrick.com/05-12-2006/avr-tutorial-digital-output.html
    _BV() is a compiler macro defined as #define _BV( bit ) ( 1<<(bit) ) in <avr/sfr_defs.h>
    Either way, |= is a binary operator that takes the bitwise OR of both operands and stores the result in the left operand. That basically means that a |= b is short for a = a | b, in the exact same way that a += b is short for a = a + b.

    So in your case, supposing MCUCR is an 8-bit register, what you're doing is this:

    MCUCR = MCUCR | (1 << some_number)
    Judging from your compiler's error, I'm guessing your problem is that some_number is >= 8, which means that the result of 1 << some_number will take up at least 2 bytes. The result of the bitwise OR will then also take up at least 2 bytes, and you can't assign that result back to MCUCR because it's only an 8-bit register.
    Wait, what?

  3. #3
    i am using c++, on linux ... and having a lot of trouble with atmega16 microcontroler...now i have to deal with PWM stuff... doea anyone knows where can i find some good references about PWM and microcontrollers programming?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012