Can anyone suggest the difference between these two programs

#include<avr/sleep.h>

ISR(TIMER1_OVF_vect)
{
  static boolean state=false;
  Serial.println("Woke from sleep mode");
  if(state)
  {
    state=false;
    digitalWrite(13,LOW);
  }
  else
  {
    state=true;
    digitalWrite(13,HIGH);
  }
  TIFR1=0x00;
}

void setup()
{
  pinMode(13,OUTPUT);
  TCCR1A=0x00;
  TCCR1B=0x05;
  TIFR1=0x00;
  TIMSK1=0x01;
  Serial.begin(9600);
  MCUCR|=0xF0;
}

void loop()
{
  Serial.println("Going to sleep mode");
  sleep_cpu();
}



and



#include<avr/sleep.h>

ISR(TIMER1_OVF_vect)
{
  static boolean state=false;
  //Serial.println("Woke from sleep mode");
  if(state)
  {
    state=false;
    digitalWrite(13,LOW);
  }
  else
  {
    state=true;
    digitalWrite(13,HIGH);
  }
  TIFR1=0x00;
}

void setup()
{
  pinMode(13,OUTPUT);
  TCCR1A=0x00;
  TCCR1B=0x05;
  TIFR1=0x00;
  TIMSK1=0x01;
//  Serial.begin(9600);
  MCUCR|=0xF0;
}

void loop()
{
//  Serial.println("Going to sleep mode");
  sleep_cpu();
}

actually the first program doesnt work in sleep mode, it always prints the data "going to sleep mode" and prints "woke from sleep mode" after every 4 seconds..
I'm finding it hard to figure out why its not working when i use serial port communications..

I can't yet see the differences, but I can see what is the same - neither is posted in a code box.

The second one has Serial.println("Going to sleep mode"); commented out.

Btw, there are programs, like the diff command in Linux and Unixes, which show the differences between two files.

Guys i know the character wise difference between them..
I want to know why commented out program goes to sleep mode, and why uncommented one doesnt go to sleep mode.

Perhaps the "tx register empty" signal wakes the processor shortly after it is put to sleep.

Serial data sending in an ISR is not a good idea. It takes too long.

In the second code, you still have a call to Serial.print() although Serial.begin() is commented out. Why?

PaulS:
Serial data sending in an ISR is not a good idea. It takes too long.

In the second code, you still have a call to Serial.print() although Serial.begin() is commented out. Why?

Sorry for that..
programming mistake.

Thanks for all the replies...
Though i couldnt figure out how to use the above with serial port enabled and working..:frowning:
I am able to use WDT timer for this purpose...:slight_smile: :slight_smile: