LCD update Screen Problem

I have simple code Here. I am calling two function display lcd and check key. by default screen should display date and time. if up arrow pressed go to particular window and show date and time. similarly down key pressed. display menu should decremented.

Problem:Date and time Displaying properly . once up key pressed menu being changed, But as soon as enter menu directly jumping back to date and time.i wanted to stay in menu for 10s then jump to date and display window. Every time before jump to date and time LCD screen screen getting circled with black

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
float latitude=13.0;//latitude in degrees
float longitude=60.0;
float Wind_Speed=13.0;
float Wind_Kmph=78.0;
float desire=45.0;
float actual=43.0;
static int dd;
static int mm;
static int yy;
static int s;
static int h;
static int m;
static int wkDay;
int lastDay = 0;
int lastMonth = 0;
int lastYear = 0;
int lastHour = 0;
int lastMinute = 0;
int lastSecond=0;

//Local time date variables
static int local_day;
static int local_month;
static int local_year;
int local_s;
static int local_h;
static int local_m;
typedef enum {
  DATE_TIME,
  COORDINATE,
  WINDSPEED,
  POSITIONTRACK,
  DISPAY_PARAMETER,
  SET_PARAMETER,
  DISPLAY_TYPE_MAX
}
DISPLAY_SCREEN_TYPE;
DISPLAY_SCREEN_TYPE display_screen_type=DATE_TIME;
#define btnRIGHT  0		// Okay
#define btnUP     1		// inc
#define btnDOWN   2		// dec
#define btnLEFT   3		// Select
#define btnSELECT 4		// Menu
#define btnNONE   5
#define beeper A1      // Alarm buzzer
#define shortBeep 100
#define longBeep  500
#define beep 300
int adc_key_in = 0;
int Update_Display=1;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Display_LCD();
  Chk_key(); 
}
void Display_LCD()
{
  switch(display_screen_type)
  {
    // lcdClear();
  case DATE_TIME:  
    timedBeep(shortBeep,1);     
    digitalClockDisplay();
    break;
  case COORDINATE:
    timedBeep(shortBeep,1);       
    Display_coordinate();
    break;
  case WINDSPEED:
    timedBeep(shortBeep,1);        
    Display_Wind();
    break;
  case POSITIONTRACK:
    timedBeep(shortBeep,1);    
    Display_angle();
    break;
  case DISPAY_PARAMETER:
    timedBeep(shortBeep,1);  
    Display_fun();
    break;//display_screen_type=SET_PARAMETER;Update_Display=1;break;
  case SET_PARAMETER: 
    timedBeep(shortBeep,1);  
    Set_Fun();
    break;//display_screen_type=DATE_TIME;Update_Display=1;break;
  case DISPLAY_TYPE_MAX:
    timedBeep(shortBeep,1);   
    break;
  default: 
    digitalClockDisplay();
    break;

  }


  if(display_screen_type>DISPLAY_TYPE_MAX)
  {
    display_screen_type=DATE_TIME;
  }
}


void Chk_key()
{
  int button=read_LCD_buttons();
  switch(button)
  {
  case btnRIGHT:// RIGHT/MENU BUTTON BEING SELECTED
    Action_RIGHT();
    break;
  case btnUP:// UP KEY/INCREMENT PRESSED   
    Action_UP();  
    break;
  case btnDOWN: // DOWN / DECREMENT KEY  PRESSED 
    Action_DOWN();
    break;
  case btnLEFT://LEFT / ESCAPE KEY PRESSED
    Action_LEFT();
    break;
  case btnSELECT://SELECT KEY PRESSED
    Action_SELECT(); 
    break;   
  } 
}

//...........................................................Action to be taken......................................................


void Action_UP()
{   
  switch(display_screen_type)
  {
  case DATE_TIME: 
    display_screen_type= COORDINATE; 
    delay(100);
    Update_Display=1;
    break;   
  case COORDINATE: 
    display_screen_type= WINDSPEED; 
    delay(100);
    Update_Display=1;
    break;    
  case WINDSPEED:  
    display_screen_type= POSITIONTRACK;
    delay(100); 
    Update_Display=1;
    break;        
  case POSITIONTRACK:
    display_screen_type= DATE_TIME; 
    delay(100);
    Update_Display=1;
    break; 
    //  default:display_screen_type= DATE_TIME; Update_Display=1;delay(500);break; 
  }  

}

void Action_DOWN()
{
  /* lcdClear(); 
   lcd.print("DOWN");*/

  switch(display_screen_type)
  {
  case DATE_TIME: 
    display_screen_type= POSITIONTRACK;
    delay(100); 
    Update_Display=1;
    break;   
  case COORDINATE: 
    display_screen_type= DATE_TIME; 
    delay(100);
    Update_Display=1;
    break;    
  case WINDSPEED:  
    display_screen_type= COORDINATE; 
    delay(100);
    Update_Display=1;
    break;        
  case POSITIONTRACK:
    display_screen_type= WINDSPEED; 
    delay(100);
    Update_Display=1;
    break; 
    //default:display_screen_type= DATE_TIME; Update_Display=1;break; 
  }  
}


void  Action_LEFT()
{
  lcdClear(); 
  lcd.print("LEFT");
}

void Action_SELECT()
{
  lcdClear(); 
  lcd.print("SELECT"); 
}

void Action_RIGHT()
{
  lcdClear(); 
  lcd.print("RIGHT");
}




void timedBeep(int beepTime, int beepCount)
{
  for (int i = 0; i < beepCount; i ++)
  {
    digitalWrite(beeper, HIGH);
    delay(beepTime);
    digitalWrite(beeper, LOW);
    delay(beepTime);
  }
}

void lcdClear(){
  lcd.clear();
  lcd.begin(16,2);
  lcd.setCursor(0,0); 
}


int read_LCD_buttons()
{
  adc_key_in = analogRead(0);      // read the value from the sensor
  // my buttons when read are centered at these valies: 0, 131, 307, 481, 722
  // we add approx 50 to those values and check to see if we are close
  // No button pressed should be 1023
  if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  if (adc_key_in < 50)   return btnRIGHT; 
  if (adc_key_in < 195)  return btnUP;
  if (adc_key_in < 380)  return btnDOWN;
  if (adc_key_in < 555)  return btnLEFT;
  if (adc_key_in < 790)  return btnSELECT;  
  //return btnNONE;  // when all others fail, return this...

}

void Display_coordinate()
{
  //  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Latitude:");
  lcd.print(latitude);
  lcd.setCursor(0,1);  
  lcd.print("Longitude:");
  lcd.print(longitude);

}



void  Display_Wind()
{

  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("WS kmph:");
  lcd.print(Wind_Kmph);
  lcd.setCursor(0,1);  
  lcd.print("WS m/s:");
  lcd.print(Wind_Speed);

}

void   Display_angle()
{

  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("DESIRED: ");
  lcd.print(desire,DEC);
  lcd.setCursor(0,1);
  lcd.print("ACTUAL: ");
  lcd.print(actual,DEC);
}



void digitalClockDisplay()
{

  // Serial.print(local_s);
  //lcd.begin(16,2);
  int prv_flag=0;
  int current_flag=1;

  if( current_flag!=prv_flag)
  {
    lcd.setCursor(0,0);
    lcd.print("Date:");
    lcd.print(local_day);
    lcd.print("/");
    lcd.print(local_month);
    lcd.print("/");
    lcd.print(local_year);
    lcd.print("    ");
    lcd.setCursor(0,1);
    lcd.print("Time:");
    lcd.print(local_h);
    lcd.print(":");
    lcd.print(local_m);
    lcd.print(":");
    lcd.print(local_s);
    lcd.print("   ");

    lastDay = local_day;
    lastMonth = local_month;
    lastYear =local_year;
    lastHour = local_h;
    lastMinute = local_m; 
    lastSecond=local_s;
    prv_flag=1;
  }
  else
  {
    lcd.setCursor(0,0);
    lcd.print("Date:");
    lcd.print(lastDay);
    lcd.print("/");
    lcd.print(lastMonth);
    lcd.print("/");
    lcd.print(lastYear);
    lcd.print("    ");
    lcd.setCursor(0,1);
    lcd.print("Time:");
    lcd.print(lastHour);
    lcd.print(":");
    lcd.print(lastMinute);
    lcd.print(":");
    lcd.print(lastSecond);
    lcd.print("   ");

    delay(1000);  

  }

}


void Display_fun()
{
  lcdClear();
  lcd.print("DISPAY PARA:");
}

void Set_Fun()
{
  lcdClear();
  lcd.print("SET PARAMETER:");
}
void lcdClear(){
  lcd.clear();
  lcd.begin(16,2);
  lcd.setCursor(0,0); 
}

lcd.begin is done ONCE ONLY in setup() and never again. You have it sprinkled all over the place.

Also, you do not seem to use Update_display anywhere?

The code for up and down buttons is more efficient as

void Action_UP()
{
   display_screen_type= (display_screen_type+1) %  DISPLAY_TYPE_MAX;
}

and -1 with zero rollover for Action_DOWN().

  int prv_flag=0;
  int current_flag=1;

  if( current_flag!=prv_flag)
  {

The flags will never be the same as you are just initialising them to be different.

lcd.begin is done ONCE ONLY in setup() and never again. You have it sprinkled all over the place.
I kept in Setup() function now
Also, you do not seem to use Update_display anywhere?
Initially i used Update_display in display function using counter , if count reach 10 , Update_display=1 and display window. but i found time being not displayed so put direct condition

The Problem i am facing in above code. i can increment / decrement Display menu but when they enter menuthey not staying log than 5s directly comes to DATE_TIME and display date and time

Make sure that you understand the timing techniques in blink without delay example as it is the same as you should be using here.

marco_c:
Make sure that you understand the timing techniques in blink without delay example as it is the same as you should be using here.

I could not able to understand above statement. I am using Delay only in action function. While doing some test i found that if there is delay program in loop . all the lcd program get delayed ,even while pressing key. FOr above problem How can i solve issue. i am doing below algorithm.

check_display()
  Default display date and time
check any key pressed()
  if yes take action by monitoring display menu
  if not stay in current Display.

But this what happening

check_display()
  Default display date and time//  working properly
check any key pressed()
  if yes take action by monitoring display menu // working properly 
  if not stay in current Display.

// but instead of staying in current display going back to default display even none key pressed.

What happens if you have the up or down key pressed for more than one cycle of the checking? Remember that the display check loop runs in a few milliseconds or less.

[quote author=marco_c link=topic=224041.msg1623428#msg1623428 date=1394189858]
What happens if you have the up or down key pressed for more than one cycle of the checking? Remember that the display check loop runs in a few milliseconds or less.
[/quote]

ya when up and down key being pressed menu being change . But it never long particular window. Assume default it date and time. when up key pressed change menu screen . now stay in particular window for while and get intialize to date and time.Below changes i made started working fine. But problem Here is i can stay in particular window. I can achieve purpose of action .
Assume In display mode :i can change Displays 
but when mode is in Set_parameter i can't increment the value. of the value while setting  

[code]
void Action_DOWN()
{
 if(display_screen_type <=DATE_TIME)
        display_screen_type=POSITIONTRACK;
    else
        display_screen_type--; 
}

void Action_UP()
{
if(display_screen_type >=POSITIONTRACK)
display_screen_type=DATE_TIME;
else
display_screen_type++;

}

[/code]

void Display_LCD()
{
 switch(display_screen_type)
  {
 
  case DATE_TIME: digitalClockDisplay(); timedBeep(beep,1); break;  
  case COORDINATE: Display_coordinate();timedBeep(beep,1); break;     
  case WINDSPEED:Display_Wind();timedBeep(beep,1); break;  
  case POSITIONTRACK:  Display_angle(); timedBeep(beep,1); break;    
  case DISPAY_PARAMETER: Display_fun();timedBeep(beep,1); break; 
  case SET_PARAMETER:Set_Fun(); timedBeep(beep,1);break;
  case GET_PASSWORD:Get_Password();timedBeep(beep,1);break;
}

You are missing the point. You keep saying what the code should do but you really need to look at what the code is actually doing.

  1. When you press a button, it is pressed for a few hundred milliseconds (say 300 milliseconds). In this time you will have checked for the button press at least 2 times, and that is only because you have put delay() in the code. Without delays you will have checked for the press a few hundred times. The point is that you are looking for button to be in the pressed state, not that the button has moved from being NOT pressed to being pressed. The transition is what you want to pick up, not the state of the button. This is called edged detection and you will find a lot on the forum about this.

  2. There is nowhere in your code that I can see any attempt to wait for 5 seconds. Look at the blinkwithoutdelay example on how you need to structure writing for something to happen while also waiting for a timer to expire. You cannot use delay() as it blocks everything else from working. If you think that you are waiting then try to explain how that actually works.