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.

routine to set time using three push buttons in C

Status
Not open for further replies.

winnie mong

Junior Member level 3
Joined
Sep 8, 2013
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
366
hey friends...
i am doing a programmable timer switch and i am stuck at producing a routine that do the setting of time.
i have three buttons to use,initially the display will be showing current time and the SELECT button is used to toggle between setting minutes and setting hours states where at each of the states two zeros will be displayed and the user will be allowed to press the SET button to increment to where they want to set the digits.
the mode button is then used to save the settings.
I am asking for help in constructing this routine in c language.thanks in advance..

i have this following part that toggles between minutes and hours, i dont know how include the part that does the incrementing.

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
void toggling()
{
 int prev_press ;
 prev_press =1;
 
 if (prev_press)
        { 
         prev_press=0;
         for(i=0;i<5;++i) {
         display("00  ");
         delay(Delay5000ms);
         display("    ");
         delay(Delay5000ms); }
        }
   else{prev_press=1;
         for(i=0;i<5;++i) {
          display("  00");
          delay(Delay5000ms);
          display("    ");
          delay(Delay5000ms); }
       } 
}

 

change prev_press to prev_SELECT_press to make it clear which button was pressed

use one function for both hours and minutes

replace your code with this..............of course, I just using pseudo code, not actual C code

Code:
if ( prev_select_press ) 
  { prev_select_press = 0; rc = Set_time(1);}  // set_TIME hours 
else  
  { prev_select_press = 1; rc = Set_time(0);}  // set_TIME minutes

if ( rc < 0 )   
  { ..............}  // mode changed, no change in time
else
  { ...................}   // time changed, set the time variable, rc is the new time

// call function to re display time

return;
}


Code:
//                                                       now you need the function set_time

int Set_time(int hour_min_mode)
{
int new_time = 0;

while (1)
{
   Display_change_time(hour_min_mode, new_time);  // blink the time being changed with the new time
   if ( Set_button_pressed() )  return new_time; 
   if ( Incr_button_pressed() ) { ++new_time; if ( new_time > 59 ) new_time = 0; }
   if ( Select_button_pressed() ) return -1;
  
 }
return 0;
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top