LCD library problem

A very simple program just to turn on a LED when there is an interrupt (“RISING”) signal on pin D2 (When a pushbutton is connected) on the Mega 2560, a timer that counts to 180 secs and turns off the LED and stays OFF until the next interrupt, all works perfect until I decided to use an LCD to display some messages. As soon as I added an lcd statement to the loop() routine, the LED goes ON on RISING but shuts off right away, the counter continues to 180 though, but the LED should hjave stayed on until the counter is due. So why is any lcd statement shutting OFF the LED even when the conditions in the WHILE statement are meet?

All works fine until the line:

lcd.setCursor(0,0);

Is added in the loop routine, just that single line trashes everything and wont led the LED stay ON for the time of the counter. I added a serial.print statement and was able to see that the counter is properly decrementing so apparently only the state of the D2 pin is affected by this “lcd” line.

Any clues?

Thanks

//

#include <LiquidCrystal.h>
#include <EEPROM.h>

// Some global variables
byte seconds_pass = 0;
byte STAT_TX = EEPROM.read(101);
byte TTA = EEPROM.read(100);

void setup(){
//
lcd.begin(16, 2);

pinMode(ptt_pin, OUTPUT);
pinMode(cor_pin, INPUT);
//

lcd.clear();
lcd.setCursor(0,0);
lcd.print(" CONTROL “);
lcd.setCursor(0,1);
lcd.print(” ACTIVE");
//
//
// Enable Timer #5 for one 1 Hz.
cli(); //
TCCR1A = 0; //
TCCR1B = 0; //
TCNT1 = 0; //
OCR1A = 15624;
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS12) | (1 << CS10);
TIMSK1 |= (1 << OCIE1A);
sei(); //
//
// DEFINE ISR
attachInterrupt(0,ISR0,RISING);
//
// ************* END OF SETUP ROUTINE **********
}
//
// Timer Interrupt routine
ISR(TIMER1_COMPA_vect){

seconds_pass++; // Just increase the variable each second

}

//
void loop(){

while(STAT_TX == 1 && digitalRead(cor_pin) == true && seconds_pass <= TTA) {
//
lcd.setCursor(0,0);
lcd.setCursor(0,1);
lcd.print("LED OFF IN “);
lcd.print(TTA - seconds_pass);
lcd.print(” SECS ");
}
//
lcd.setCursor(0,0); // <<<<<<<< THE BUG <<<<<<<<<<<<<<<<<<<

seconds_pass = 0; // To avoid overflow of variable (reset to 0).
PORTA = B00000000; // Turn off LED.

}
// ---------------------------------------------------------------------------------------------------
//
void ISR0(){ // ISR for INT 0 on D2

if(debounce(cor_pin) == HIGH){

PORTA = B00001000; // Activate PTT
seconds_pass = 0;
}
}

//

boolean debounce(byte pin)
{
boolean state;
boolean previousState;

previousState = digitalRead(pin); // store switch state
for(int counter=0; counter < debounceDelay; counter++)
{
delayMicroseconds(1000); // wait for 1 millisecond
state = digitalRead(pin); // read the pin
if( state != previousState) //
{
counter = 0; // reset the counter if the state changes
previousState = state; // and save the current state
}
}
return state;
}

Is that the whole sketch ?

Error: You are manipulating seconds_pass in an ISR without declaring it 'volatile'.

Error: Your code doesn't declare 'lcd', 'ptt_pin', or 'cor_pin'.