Previous Next

Keyboard Task:

This task has 4 different states: No Push, Maybe Push, Pushed, and Debounce Press. Because Keypads are extremely sensitive, such state machine is required to reduce the noise effect. In fact, since each state runs at about 30ms, this scheme required the user to push a button for at least 90ms (which is valid for a normal human being) for the task to registered as a valid push. Once the state machine reaches the Debounce Press state, it will remain in there until an acknowledgement is sent from the display task.

char KbdTask(void) //debounce state machine
   begin 
   char pong[]="pong";
   if(OSGetState()==NoPush)
   { // OSUARTTransmitBytes(pong,4); 
   if(~PIND==0x01)
   {
   OSSendMess(0, StillPressed);
   OSSetState(MaybePush); 
   
   }
   else OSSetState(NoPush);
   
   } 
   if(OSGetState()==MaybePush) { 
   
   if(~PIND==0x01 && OSGetMess(0)==StillPressed)
   OSSetState(MaybePush); 
   else 
   {
   OSSendMess(0,error);
   OSSetState(NoPush); 
   
   }
   }
   if(OSGetState()==Pushed)
   {
   if(~PIND==0x01 && OSGetMess(0)==StillPressed)
   OSSetState(Pushed);
   else 
   OSSetState(DebouncePress);
   
   }
   if(OSGetState()==DebouncePress)
   {
   OSSendMess(1,1); 
   
   OSSetState(Waiting);
   OSSendMess(0,error);
   } 
   if(OSGetState()==Waiting && OSGetAck()==0x04)
   {
   OSSetState(NoPush); 
   //OSSetState(Done);
   } 
   
   return 0; 
   end 


Previous Next