Skip to content

Instantly share code, notes, and snippets.

@michaellin
Created December 1, 2015 04:57
Show Gist options
  • Save michaellin/83517cdd0a5a5e0e29db to your computer and use it in GitHub Desktop.
Save michaellin/83517cdd0a5a5e0e29db to your computer and use it in GitHub Desktop.
/***Service Module to debounce start button***/
define All_BITS offset variable
initialize module level variables
/**************************************************************
Function: InitStartButtonDB
Takes: 8 bit integer (priority number)
Returns: true or false
Purpose: Passes in priority number, initializes Tiva pins, and moves into state machine.
/*************************************************************/
InitStartButtonDB
Store priority value as static variable
Initialize port A
Initialize bit 2
Sample the button port pin
Set CurrentState to be Debouncing
Start debounce timer
return true
end
/**************************************************************
Function: PostStartButtonDB
Takes: ES_Event
Returns: true or false
Purpose: Posts events to this service's queue.
/*************************************************************/
PostStartButton
call ES_PostToService with the priority number of this service
end
/**************************************************************
Function: CheckStartButtonEvents
Takes: nothing
Returns: true or false
Purpose: Checks the state of the start button and reports it to this service.
/*************************************************************/
CheckStartButtonEvents
Sample port pin, store value to CurrentButtonState
if CurrentButtonState is not LastButtonState
if CurrentButtonState is high
Tell this service the start button is down
else
Tell this service the start button is up
endif
endif
Update LastButtonState to CurrentButtonState
return true
endif
/**************************************************************
Function: RunStartButtonDB
Takes: ES_Event
Returns: ES_Event (ES_NO_EVENT)
Purpose: Runs the start button debounce state machine.
/*************************************************************/
RunStartButtonDB
if CurrentState is Debouncing
if event is a debounce timer timeout
Move into Ready2Sample state
endif
else if CurrentState is Ready2Sample
if event is start button up
Start debounce timer
Move into debouncing state
}
else if event is start button down
Start debounce timer
Move into debouncing state
Post DBButtonDown to main state machine
endif
endif
Return ES_NO_EVENT
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment