user30149: I have a project in which I am putting my ATtiny85 to sleep. Here is the watchdog configuration (in the setup) that works just fine:
void setup()
{
  /*  Setup the LCD */
  lcd.init();                           // initialize the lcd
  lcd.backlight();                      // Print a message to the LCD.
  lcd.clear();
  lcd.setCursor(0,0);

  /* Inform the user about initialization process */
  lcd.print("Initializing...");
  delay(1000);

  /* Config pins */
  pinMode( LED_PIN, INPUT );
  pinMode( STATUS_PIN, OUTPUT );

  /* Initialize pins */
  digitalWrite( STATUS_PIN, HIGH );

  /*** Setup the WDT ***/

  /* Clear the reset flag of watchdog interrupts, so that they are available again. */
  MCUSR &= ~(1<<WDRF);

  /* Enable configuration changes */
  WDTCR |= (1<<WDCE) | (1<<WDE);


/*
WDP3       WDP2    WDP1     WDP0         Number of WDT     Typical Time-out at
                                         Oscillator Cycles     VCC = 5.0V
  0         0      0        0             2K (2048) cycles       16 ms
  0         0      0        1             4K (4096) cycles       32 ms
  0         0      1        0             8K (8192) cycles       64 ms
  0         0      1        1            16K (16384) cycles    0.125 s
  0         1      0        0            32K (32768) cycles    0.25 s
  0         1      0        1            64K (65536) cycles    0.5 s
  0         1      1        0            128K (131072) cycles 1.0 s
  0         1      1        1            256K (262144) cycles 2.0 s
  1         0      0        0            512K (524288) cycles 4.0 s
  1         0      0        1            1024K (1048576) cycles 8.0 s
*/
  /* set new watchdog timeout prescaler value */
  WDTCR =  0<<WDP3 | 1<<WDP2 | 1<<WDP1 | 0<<WDP0 ;

  lcd.clear();
  lcd.print("Initialisation");
  lcd.setCursor(0,1);
  lcd.print("complete.");
  delay(500); 
}

Here is the function that actually puts my microcontroller to sleep:
void enterSleep(void)
{
//  /* disable all interrupts */
//  cli();
  lcd.clear();
  lcd.print("Asleep...");

  /* Enable the WD interrupt (note no reset). */
  WDTCR |= (1<<WDIE);

  set_sleep_mode( SLEEP_MODE_PWR_DOWN );   /* EDIT: could also use SLEEP_MODE_PWR_DOWN for lowest power consumption. */
  sleep_enable();
  // Status pin goes low
  digitalWrite( STATUS_PIN, LOW );
  /* Now enter sleep mode. */
  sleep_mode();

  /* The program will continue from here after the WDT timeout*/
  sleep_disable(); /* First thing to do is disable sleep. */

  // Status pin goes low
  digitalWrite( STATUS_PIN, HIGH );

  /* Re-enable the peripherals. */
  power_all_enable();

  /* Disable the WD interrupt */
  WDTCR &= ~_BV(WDIE);
}

Then I decided to do a switch case construction, so that I won't have to change manually WDTCR register each  time I want to change the sleep time. So here is my new setup code:
int sleepTime = 0;

void setup()
{
  /*  Setup the LCD */
  lcd.init();                           // initialize the lcd
  lcd.backlight();                      // Print a message to the LCD.
  lcd.clear();
  lcd.setCursor(0,0);

  /* Inform the user about initialization process */
  lcd.print("Initializing...");
  delay(1000);

  /* Config pins */
  pinMode( IN_PIN, INPUT );
  pinMode( STATUS_PIN, OUTPUT );
  pinMode( DEBUG_PIN, OUTPUT );

  /* Initialize pins */
  digitalWrite( STATUS_PIN, HIGH );
  digitalWrite( DEBUG_PIN, LOW );

  /*** Setup the WDT ***/
//  sleepDevice.watchdogInit();
    /*** Setup the WDT ***/  
    /* Clear the reset flag of watchdog interrupts, so that they are available again. */
    MCUSR &= ~(1<<WDRF);

    /* Enable configuration changes*/
    WDTCR |= (1<<WDCE) | (1<<WDE);


  /*
  WDP3       WDP2    WDP1     WDP0         Number of WDT     Typical Time-out at
                                           Oscillator Cycles     VCC = 5.0V
    0         0      0        0             2K (2048) cycles       16 ms
    0         0      0        1             4K (4096) cycles       32 ms
    0         0      1        0             8K (8192) cycles       64 ms
    0         0      1        1            16K (16384) cycles    0.125 s
    0         1      0        0            32K (32768) cycles    0.25 s
    0         1      0        1            64K (65536) cycles    0.5 s
    0         1      1        0            128K (131072) cycles 1.0 s
    0         1      1        1            256K (262144) cycles 2.0 s
    1         0      0        0            512K (524288) cycles 4.0 s
    1         0      0        1            1024K (1048576) cycles 8.0 s
  */

  switch( sleepTime ){
    case 0:
      WDTCR =  0<<WDP3 | 1<<WDP2 | 1<<WDP1 | 0<<WDP0 ;
      break;
    case 1:
      WDTCR =  0<<WDP3 | 1<<WDP2 | 0<<WDP1 | 1<<WDP0 ;
      break;
    default:
      WDTCR =  0<<WDP3 | 0<<WDP2 | 1<<WDP1 | 0<<WDP0 ;
      break;
  }

  lcd.clear();
  lcd.print("Initialisation");
  lcd.setCursor(0,1);
  lcd.print("complete.");
  delay(500); 
}

The enterSleep function is not changed.
But this time sleeping does not work at all! In fact, ATtiny sort of freezes. Does any one has any idea why it is so? To me it looks like the Arduino IDE is confused with switch case instruction, but maybe there is something wrong with my code...

user30149: Alright, thanks to you guys I fixed the issue. 
The main thing is that any changes in the configuration have to be made within 4 cycles after the CONFIG ENABLE bit is set. It is done with this instruciton:
/* Enable configuration 
WDTCR |= (1<<WDCE) | (1<<WDE);

Now switch works like a charm. So the final code for watchdog setup looks like this:
void Sleeper::watchdogInit( void ){
    /*** Setup the WDT ***/  
      /* Clear the reset flag of watchdog interrupts, so that they are available again. */
      MCUSR &= ~(1<<WDRF);

    /*
    WDP3       WDP2    WDP1     WDP0         Number of WDT     Typical Time-out at
                                             Oscillator Cycles     VCC = 5.0V
      0         0      0        0             2K (2048) cycles       16 ms
      0         0      0        1             4K (4096) cycles       32 ms
      0         0      1        0             8K (8192) cycles       64 ms
      0         0      1        1            16K (16384) cycles    0.125 s
      0         1      0        0            32K (32768) cycles    0.25 s
      0         1      0        1            64K (65536) cycles    0.5 s
      0         1      1        0            128K (131072) cycles 1.0 s
      0         1      1        1            256K (262144) cycles 2.0 s
      1         0      0        0            512K (524288) cycles 4.0 s
      1         0      0        1            1024K (1048576) cycles 8.0 s
    */

    switch( sleepTime ){
        case 0:
            /* Enable configuration changes*/
            WDTCR |= (1<<WDCE) | (1<<WDE);
            WDTCR =  0<<WDP3 | 1<<WDP2 | 1<<WDP1 | 0<<WDP0 ;
            break;
        case MSEC_500:
            /* Enable configuration changes*/
            WDTCR |= (1<<WDCE) | (1<<WDE);
            WDTCR =  0<<WDP3 | 1<<WDP2 | 0<<WDP1 | 1<<WDP0 ;
            break;
        case MSEC_250:
            /* Enable configuration changes*/
            WDTCR |= (1<<WDCE) | (1<<WDE);
            WDTCR =  0<<WDP3 | 1<<WDP2 | 0<<WDP1 | 0<<WDP0 ;
            break;
        case MSEC_125:
            /* Enable configuration changes*/
            WDTCR |= (1<<WDCE) | (1<<WDE);
            WDTCR =  0<<WDP3 | 0<<WDP2 | 1<<WDP1 | 1<<WDP0 ;
            break;
        case MSEC_64:
            /* Enable configuration changes*/
            WDTCR |= (1<<WDCE) | (1<<WDE);
            WDTCR =  0<<WDP3 | 0<<WDP2 | 1<<WDP1 | 0<<WDP0 ;
            break;
        case MSEC_32:
            /* Enable configuration changes*/
            WDTCR |= (1<<WDCE) | (1<<WDE);
            WDTCR =  0<<WDP3 | 0<<WDP2 | 1<<WDP1 | 0<<WDP0 ;
            break;
    default:
      /* Enable configuration changes*/
      WDTCR |= (1<<WDCE) | (1<<WDE);
      WDTCR =  0<<WDP3 | 0<<WDP2 | 1<<WDP1 | 0<<WDP0 ;
      break;
    }


30149: <p>I have a project in which I am putting my ATtiny85 to sleep. Here is the watchdog configuration (in the setup) that works just fine:</p>



<pre class="lang-cpp prettyprint-override"><code>void setup()
{
  /*  Setup the LCD */
  lcd.init();                           // initialize the lcd
  lcd.backlight();                      // Print a message to the LCD.
  lcd.clear();
  lcd.setCursor(0,0);

  /* Inform the user about initialization process */
  lcd.print("Initializing...");
  delay(1000);

  /* Config pins */
  pinMode( LED_PIN, INPUT );
  pinMode( STATUS_PIN, OUTPUT );

  /* Initialize pins */
  digitalWrite( STATUS_PIN, HIGH );

  /*** Setup the WDT ***/

  /* Clear the reset flag of watchdog interrupts, so that they are available again. */
  MCUSR &amp;= ~(1&lt;&lt;WDRF);

  /* Enable configuration changes */
  WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);


/*
WDP3       WDP2    WDP1     WDP0         Number of WDT     Typical Time-out at
                                         Oscillator Cycles     VCC = 5.0V
  0         0      0        0             2K (2048) cycles       16 ms
  0         0      0        1             4K (4096) cycles       32 ms
  0         0      1        0             8K (8192) cycles       64 ms
  0         0      1        1            16K (16384) cycles    0.125 s
  0         1      0        0            32K (32768) cycles    0.25 s
  0         1      0        1            64K (65536) cycles    0.5 s
  0         1      1        0            128K (131072) cycles 1.0 s
  0         1      1        1            256K (262144) cycles 2.0 s
  1         0      0        0            512K (524288) cycles 4.0 s
  1         0      0        1            1024K (1048576) cycles 8.0 s
*/
  /* set new watchdog timeout prescaler value */
  WDTCR =  0&lt;&lt;WDP3 | 1&lt;&lt;WDP2 | 1&lt;&lt;WDP1 | 0&lt;&lt;WDP0 ;

  lcd.clear();
  lcd.print("Initialisation");
  lcd.setCursor(0,1);
  lcd.print("complete.");
  delay(500); 
}
</code></pre>

<p>Here is the function that actually puts my microcontroller to sleep:</p>

<pre class="lang-cpp prettyprint-override"><code>void enterSleep(void)
{
//  /* disable all interrupts */
//  cli();
  lcd.clear();
  lcd.print("Asleep...");

  /* Enable the WD interrupt (note no reset). */
  WDTCR |= (1&lt;&lt;WDIE);

  set_sleep_mode( SLEEP_MODE_PWR_DOWN );   /* EDIT: could also use SLEEP_MODE_PWR_DOWN for lowest power consumption. */
  sleep_enable();
  // Status pin goes low
  digitalWrite( STATUS_PIN, LOW );
  /* Now enter sleep mode. */
  sleep_mode();

  /* The program will continue from here after the WDT timeout*/
  sleep_disable(); /* First thing to do is disable sleep. */

  // Status pin goes low
  digitalWrite( STATUS_PIN, HIGH );

  /* Re-enable the peripherals. */
  power_all_enable();

  /* Disable the WD interrupt */
  WDTCR &amp;= ~_BV(WDIE);
}
</code></pre>

<p>Then I decided to do a switch case construction, so that I won't have to change manually <code>WDTCR</code> register each  time I want to change the sleep time. So here is my new setup code:</p>

<pre class="lang-cpp prettyprint-override"><code>int sleepTime = 0;

void setup()
{
  /*  Setup the LCD */
  lcd.init();                           // initialize the lcd
  lcd.backlight();                      // Print a message to the LCD.
  lcd.clear();
  lcd.setCursor(0,0);

  /* Inform the user about initialization process */
  lcd.print("Initializing...");
  delay(1000);

  /* Config pins */
  pinMode( IN_PIN, INPUT );
  pinMode( STATUS_PIN, OUTPUT );
  pinMode( DEBUG_PIN, OUTPUT );

  /* Initialize pins */
  digitalWrite( STATUS_PIN, HIGH );
  digitalWrite( DEBUG_PIN, LOW );

  /*** Setup the WDT ***/
//  sleepDevice.watchdogInit();
    /*** Setup the WDT ***/  
    /* Clear the reset flag of watchdog interrupts, so that they are available again. */
    MCUSR &amp;= ~(1&lt;&lt;WDRF);

    /* Enable configuration changes*/
    WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);


  /*
  WDP3       WDP2    WDP1     WDP0         Number of WDT     Typical Time-out at
                                           Oscillator Cycles     VCC = 5.0V
    0         0      0        0             2K (2048) cycles       16 ms
    0         0      0        1             4K (4096) cycles       32 ms
    0         0      1        0             8K (8192) cycles       64 ms
    0         0      1        1            16K (16384) cycles    0.125 s
    0         1      0        0            32K (32768) cycles    0.25 s
    0         1      0        1            64K (65536) cycles    0.5 s
    0         1      1        0            128K (131072) cycles 1.0 s
    0         1      1        1            256K (262144) cycles 2.0 s
    1         0      0        0            512K (524288) cycles 4.0 s
    1         0      0        1            1024K (1048576) cycles 8.0 s
  */

  switch( sleepTime ){
    case 0:
      WDTCR =  0&lt;&lt;WDP3 | 1&lt;&lt;WDP2 | 1&lt;&lt;WDP1 | 0&lt;&lt;WDP0 ;
      break;
    case 1:
      WDTCR =  0&lt;&lt;WDP3 | 1&lt;&lt;WDP2 | 0&lt;&lt;WDP1 | 1&lt;&lt;WDP0 ;
      break;
    default:
      WDTCR =  0&lt;&lt;WDP3 | 0&lt;&lt;WDP2 | 1&lt;&lt;WDP1 | 0&lt;&lt;WDP0 ;
      break;
  }

  lcd.clear();
  lcd.print("Initialisation");
  lcd.setCursor(0,1);
  lcd.print("complete.");
  delay(500); 
}
</code></pre>

<p>The <code>enterSleep</code> function is not changed.
But this time sleeping does not work at all! In fact, ATtiny sort of freezes. Does any one has any idea why it is so? To me it looks like the Arduino IDE is confused with switch case instruction, but maybe there is something wrong with my code...</p>
 30149: <p>Alright, thanks to you guys I fixed the issue. 
The main thing is that any changes in the configuration have to be made within 4 cycles after the CONFIG ENABLE bit is set. It is done with this instruciton:</p>

<pre><code>/* Enable configuration 
WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);
</code></pre>

<p>Now switch works like a charm. So the final code for watchdog setup looks like this:</p>

<pre><code>void Sleeper::watchdogInit( void ){
    /*** Setup the WDT ***/  
      /* Clear the reset flag of watchdog interrupts, so that they are available again. */
      MCUSR &amp;= ~(1&lt;&lt;WDRF);

    /*
    WDP3       WDP2    WDP1     WDP0         Number of WDT     Typical Time-out at
                                             Oscillator Cycles     VCC = 5.0V
      0         0      0        0             2K (2048) cycles       16 ms
      0         0      0        1             4K (4096) cycles       32 ms
      0         0      1        0             8K (8192) cycles       64 ms
      0         0      1        1            16K (16384) cycles    0.125 s
      0         1      0        0            32K (32768) cycles    0.25 s
      0         1      0        1            64K (65536) cycles    0.5 s
      0         1      1        0            128K (131072) cycles 1.0 s
      0         1      1        1            256K (262144) cycles 2.0 s
      1         0      0        0            512K (524288) cycles 4.0 s
      1         0      0        1            1024K (1048576) cycles 8.0 s
    */

    switch( sleepTime ){
        case 0:
            /* Enable configuration changes*/
            WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);
            WDTCR =  0&lt;&lt;WDP3 | 1&lt;&lt;WDP2 | 1&lt;&lt;WDP1 | 0&lt;&lt;WDP0 ;
            break;
        case MSEC_500:
            /* Enable configuration changes*/
            WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);
            WDTCR =  0&lt;&lt;WDP3 | 1&lt;&lt;WDP2 | 0&lt;&lt;WDP1 | 1&lt;&lt;WDP0 ;
            break;
        case MSEC_250:
            /* Enable configuration changes*/
            WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);
            WDTCR =  0&lt;&lt;WDP3 | 1&lt;&lt;WDP2 | 0&lt;&lt;WDP1 | 0&lt;&lt;WDP0 ;
            break;
        case MSEC_125:
            /* Enable configuration changes*/
            WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);
            WDTCR =  0&lt;&lt;WDP3 | 0&lt;&lt;WDP2 | 1&lt;&lt;WDP1 | 1&lt;&lt;WDP0 ;
            break;
        case MSEC_64:
            /* Enable configuration changes*/
            WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);
            WDTCR =  0&lt;&lt;WDP3 | 0&lt;&lt;WDP2 | 1&lt;&lt;WDP1 | 0&lt;&lt;WDP0 ;
            break;
        case MSEC_32:
            /* Enable configuration changes*/
            WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);
            WDTCR =  0&lt;&lt;WDP3 | 0&lt;&lt;WDP2 | 1&lt;&lt;WDP1 | 0&lt;&lt;WDP0 ;
            break;
    default:
      /* Enable configuration changes*/
      WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);
      WDTCR =  0&lt;&lt;WDP3 | 0&lt;&lt;WDP2 | 1&lt;&lt;WDP1 | 0&lt;&lt;WDP0 ;
      break;
    }
</code></pre>
