Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to stop it from blinking ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Visit site
Activity points
9,442
Guys I have a state machine like this :
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
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
unsigned char cleardispflag = 0;
 
 
if (button_input==2) // //  if button 2 pressed ( button up) 
             {
                cleardisplay();
                 
                 lcd_string("INC_WEEKDAY");//increase day of the week (increment_day);
                 //state_var = increase_weekday
                 state_var = INCREASE_WEEKDAY;
             }
 
 
void cleardisplay(){
 
    if(cleardispflag == 0){
        lcd_cmd(0x01);//clear screen
        cleardispflag = 1;      
    }
 
 
}
 
 
//set cleardispflag to 1 whenever you want to update the screen
//replace all clear lcd commands with cleardisplay() function call

 

Ok, thanks for the idea my friend,

I have another question,
How can I increase DS1307 value ?

This is the variable :
Day : ds1307_addr[3]
char ds1307_addr[7];
char *weekday[]={"Sun","Mon","Tue","Wed","Thr","Fri","Sat"};

this is how it is displayed
Code:
lcd_string(weekday[ds1307_addr[3]]);

Thanks

- - - Updated - - -

is it possible doing like this ?
Code:
 if(button_input==2) //if BUTTON2 pressed, increase value on ds1307_addr[3]
			              {
							  weekday_increase = weekday[ds1307_addr[3] +1];  
				              lcd_xy(0,0);//put on 0,0
				              lcd_string("INCREASE_WEEKDAY");
				              lcd_cmd(0xC0);
				              lcd_string(weekday_increase);
				              lcd_string("             ");				              
				              //write weekday to DS1307
				              state_var = INCREASE_WEEKDAY; //goto INCREASE_WEEKDAY
				              
			              }
 

When incrementing or decrementing just write the new value to DS1307 and then it will output the current value. Then after getting the data in string format display it on LCD.
any ideas of the code ?
I've done like this :
Code:
case SET_WEEK_DAY:  //set date
		      //state_var = SET_WEEK_DAY; //set the state for editing weekday
		  
		  	 //lcd_cmd(0x01);//clear screen
			 lcd_xy(0,0);//put on 0,0  
			 lcd_string("SET_WEEKDAY     ");
			 lcd_cmd(0xC0);
			 lcd_string("                ");
			 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_xy(0,0);//put on 0,0

				 lcd_string("INC_WEEKDAY     ");//increase day of the week (increment_day);
       			 lcd_cmd(0xC0);
       			 lcd_string("                ");
				 //state_var = increase_weekday
				 state_var = INCREASE_WEEKDAY;
			 }
			 
			 if(button_input==3) //if BUTTON3 pressed
			 {
				 //lcd_cmd(0x01);//clear screen
				 lcd_xy(0,0);//put on 0,0
				 lcd_string("CANCEL         ");
				 lcd_cmd(0xC0);
				 lcd_string("                ");

				 state_var = DISPLAY_TIME;
				 
				 
			 }
			
	     break;
		 
		 case INCREASE_WEEKDAY :
		   
		  // lcd_cmd(0x01);//clear screen
		   lcd_xy(0,0);//put on 0,0
		   lcd_string("INCREASE_WEEKDAY");
		   lcd_cmd(0xC0);
		   lcd_string(weekday[ds1307_addr[3]]);
		   lcd_string("             ");
		   
			 button_input = button_is_pressed();//read button
			              if(button_input==2) //if BUTTON2 pressed, increase value on ds1307_addr[3]
			              {
							  weekday_increase = weekday[ds1307_addr[3] +1];  
				              lcd_xy(0,0);//put on 0,0
				              lcd_string("INCREASE_WEEKDAY");
				              lcd_cmd(0xC0);
				              lcd_string(weekday_increase);
				              lcd_string("             ");				              
				              //write weekday to DS1307
				              state_var = INCREASE_WEEKDAY; //goto INCREASE_WEEKDAY
				              
			              }
	         			 if(button_input==3) //if BUTTON3 pressed
	         			 {
         			 		 lcd_xy(0,0);//put on 0,0
							 lcd_string("WEEKDAY_SAVED  ");
							 lcd_cmd(0xC0);
							 lcd_string("                ");
 
							  //write weekday to DS1307 
		         			 state_var = SET_MONTH; //goto SET_MONTH
		         			 
	         			 }
	   
		   break;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top