hai all, I want a to implement timer concept for 10sec. I want to start timer in one state and want to stop it another state.Is it possible?
//states are INIT,POWERON,GATEOPEN,GATECLOSE. //set active state as INIT while(1) { process(); } void process() { switch(activestate) { case INIT: starttimer(2minutes);//here i want to start the timer and proceed to next state ie parallel timer for 2minutes. change_active_state=poweron; case poweron: if(timernotover) //remain in same state else //proceed. case open: if(gateopentogateclose) { start timer(10sec); //watch the input status if(gate close detected) stoptimer; change state to closed; } case closed: if( close detected) { stoptimer; } . . . . . . } }
my problem is if i start timer then it remains in same state till the timer completes. I want to start timer and proceed to next state and kill the timer there.... in the above scenario the timer waits in INIT state for 2minutes but it should wait in poweron state.
timer routine starttimer(int noofsec) { TMOD=TMOD&0xF0; TMOD=TMOD|00x01; for(i=0;i<noofsec*20;i++) { //50 milli sec timer TH0=0x3C; TL0=0xB0; TF0=0; TR0=1; while(TF0==1); TR0=0; } }
without for loop is there any way to maintain the timer parallely........ with thanks, Ram