bianchi77
Advanced Member level 4
- Joined
- Jun 11, 2009
- Messages
- 1,313
- Helped
- 21
- Reputation
- 44
- Reaction score
- 20
- Trophy points
- 1,318
- Location
- California
- Activity points
- 9,442
Guys I have a state machine like this :
How can I avoid this :
From blinking, if I eliminate "clear screen" the whole screen will be full.....
any ideas ?
thanks
Code:
void task0(void)
{
typedef enum {
DISPLAY_TIME,
SET_WEEK_DAY,
SET_MONTH,
SET_YEAR,
SET_HOUR,
SET_MINUTE,
SET_SECOND,
INCREASE_WEEKDAY,
GO_BACK
} my_states;
//static uint8_t state;
static my_states state_var = DISPLAY_TIME;
int button_input;
switch (state_var) {
case DISPLAY_TIME :
display_time();//display time
button_input = button_is_pressed();//read button
if (button_input==1)//if button pressed, state = b;
{
state_var = SET_WEEK_DAY;
}else //else
{
display_time();//read ds1307 into time structure
//read time struct and display on lcd
}
break; // break;
case SET_WEEK_DAY: //set date
//state_var = SET_WEEK_DAY; //set the state for editing weekday
lcd_cmd(0x01);//clear screen
lcd_string("SET_WEEKDAY");
button_input = button_is_pressed();//read button
if (button_input==1)
{
state_var = SET_MONTH;
}
if (button_input==2) // // if button 2 pressed ( button up)
{
//lcd_cmd(0x01);//clear screen
lcd_string("INC_WEEKDAY");//increase day of the week (increment_day);
//state_var = increase_weekday
state_var = INCREASE_WEEKDAY;
}
if(button_input==3) //if BUTTON3 pressed
{
//lcd_cmd(0x01);//clear screen
lcd_string("CANCEL");
state_var = DISPLAY_TIME;
}
break;
case INCREASE_WEEKDAY :
lcd_cmd(0x01);//clear screen
lcd_xy(0,0);//put on 0,1
lcd_string("INCREASE_WEEKDAY");
button_input = button_is_pressed();//read button
if(button_input==3) //if BUTTON3 pressed
{
lcd_cmd(0x01);//clear screen
lcd_string("WEEKDAY_SAVED");
state_var = SET_MONTH; //goto SET_MONTH
}
break;
case SET_MONTH:
lcd_cmd(0x01); //clear screen
lcd_string("SET_MONTH");
button_input = button_is_pressed();//read button
if (button_input==1)
{
state_var = SET_YEAR;
}
if (button_input==2) // // if button 2 pressed ( button up)
{
lcd_cmd(0x01);//clear screen
lcd_string("INC_MONTH");//increase day of the week (increment_day);
}
if(button_input==3) //if BUTTON3 pressed
{
lcd_cmd(0x01);//clear screen
lcd_string("MONTH_SAVED");
}
break;
case SET_YEAR:
lcd_cmd(0x01); //clear screen
lcd_string("SET_YEAR");
button_input = button_is_pressed();//read button
if (button_input==1)
{
state_var = SET_HOUR;
}
if (button_input==2) // // if button 2 pressed ( button up)
{
lcd_cmd(0x01);//clear screen
lcd_string("INC_YEAR");//increase day of the week (increment_day);
}
if(button_input==3) //if BUTTON3 pressed
{
lcd_cmd(0x01);//clear screen
lcd_string("YEAR_SAVED");
}
break;
case SET_HOUR:
lcd_cmd(0x01); //clear screen
lcd_string("SET_HOUR");
button_input = button_is_pressed();//read button
if (button_input==1)
{
state_var = SET_MINUTE;
}
if (button_input==2) // // if button 2 pressed ( button up)
{
lcd_cmd(0x01);//clear screen
lcd_string("INC_HOUR");//increase day of the week (increment_day);
}
if(button_input==3) //if BUTTON3 pressed
{
lcd_cmd(0x01);//clear screen
lcd_string("HOUR_SAVED");
}
break;
case SET_MINUTE:
lcd_cmd(0x01); //clear screen
lcd_string("SET_MINUTE");
button_input = button_is_pressed();//read button
if (button_input==1)
{
state_var = SET_SECOND;
}
if (button_input==2) // // if button 2 pressed ( button up)
{
lcd_cmd(0x01);//clear screen
lcd_string("INC_MINUTE");//increase day of the week (increment_day);
}
if(button_input==3) //if BUTTON3 pressed
{
lcd_cmd(0x01);//clear screen
lcd_string("MINUTE_SAVED");
}
break;
case SET_SECOND:
lcd_cmd(0x01); //clear screen
lcd_string("SET_SECOND");
button_input = button_is_pressed();//read button
if (button_input==1)
{
state_var = DISPLAY_TIME;
}
if (button_input==2) // // if button 2 pressed ( button up)
{
lcd_cmd(0x01);//clear screen
lcd_string("INC_SECOND");//increase day of the week (increment_day);
}
if(button_input==3) //if BUTTON3 pressed
{
lcd_cmd(0x01);//clear screen
lcd_string("SECOND_SAVED");
}
break;
default:
lcd_string("DEFAULT");
state_var=DISPLAY_TIME;
break; //default
}//end of switch
task_timers[0] = 1; //every 10ms
reset_task(0);
}
How can I avoid this :
Code:
if (button_input==2) // // if button 2 pressed ( button up)
{
//lcd_cmd(0x01);//clear screen
lcd_string("INC_WEEKDAY");//increase day of the week (increment_day);
//state_var = increase_weekday
state_var = INCREASE_WEEKDAY;
}
From blinking, if I eliminate "clear screen" the whole screen will be full.....
any ideas ?
thanks