Skip to content

Instantly share code, notes, and snippets.

@michaellin
Created December 1, 2015 04:53
Show Gist options
  • Save michaellin/28a334c0298593e046a7 to your computer and use it in GitHub Desktop.
Save michaellin/28a334c0298593e046a7 to your computer and use it in GitHub Desktop.
/***Service module that implements a state machine for writing individual characters and commands to LCD***/
initialize module level variables
/**************************************************************
Function: InitLCDService
Takes: 8 bit integer (priority number)
Returns: true or false
Purpose: Stores priority number of this service inside the module and puts state machine into initial pseudo-state.
/*************************************************************/
InitLCDService
Store priority number in a statis variable
Put us into the initial pseudo-state to set up for the initial transition
Set up the short timer for inter-command timings
Post the initial transition event
end
/**************************************************************
Function: PostLCDService
Takes: ES_Event
Returns: true or false
Purpose: Posts ES_Event to LCDService queue.
/*************************************************************/
PostLCDService
call ES_PostToService with stored priority number
end
/**************************************************************
Function: RunLCDService
Takes: ES_Event
Returns: ES_Event (ES_NO_EVENT)
Purpose: Runs the LCDService state machine.
/*************************************************************/
RunLCDService
use a switch case to change between states
case InitPState :
if event type is ES_INIT
Initialize the necessary Tiva pins
Increment initialization counter
Start the timer for max short timer delay
move to the Initializing state
endif
break;
case Initializing :
if event type is a short timeout
Take appropriate initialization step, then set short timer to delay
Increment initialization counter
break;
case Waiting2Write :
if event type is ES_LCD_PUTCHAR
Write character to LCD
Start the inter-character timer (Inter char delay = 53 us)
Move to the PausingBetweenWrites state
else if event type is ES_LCD_COMMAND
Write command to LCD
Start the inter-command timer
Move to the PausingBetweenWrites state
else if event type is LCD_RESET
Move to initializing state
Reset initialization counter to 1
Delay 4500 us before taking first initialization step
break;
case PausingBetweenWrites :
if event type is a short timeout
Move to Waiting2Write state
else if event type is LCD_RESET
Move to initializing state
Reset initialization counter to 1
Delay 4500 us before taking first initialization step
break;
end switch case
// Return ES_NO_EVENT
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment