The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

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
    _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 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 Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012