![](../images/horizontal_rule.jpg)
Code
Pseudo Code: Source Code (zip): |
Diagrams: Support Code (zip): |
Helm Pseudo Code: State Machine
;include "p16f690.inc"
;include "CommonDefines.inc"
;name global variables
;name incoming variables
;define global and local variables
;BEGIN CODE
;********************************************************************************
;DO EVERY TIME!!! Check for ping and hard reset messages from the Admiral
;********************************************************************************
;Check to see if the lid is closed
;if the lid is open skip to hSTATE_LidOpen
;if closed set initialize bit
;clear key ignition bit
;Check for Admiral header (byte 0)
;Check if it was a ping message from the Admiral (byte 2)
;Save sender address
;set sender address
;set header
;set data to send
;set flag to send message (ping response)
;Clear header
;Check if it was a hard reset message from the Admiral (byte 2)
;Clear header
;set initialize state bit
;Check if it was a Blue goal message from the Admiral (byte 2)
;save correct values into shift register variables
;send shift register variables out to ports
;Clear header
;Check if it was a Red goal message from the Admiral (byte 2)
;save correct values into shift register variables
;send shift register variables out to ports
;Clear header
;********************************************************************************
;STATE HELM INITIALIZE
;********************************************************************************
;Check the state bit
;Call all config .asm files
;change the PWM output for the Volt meter display
;reset ibutton
;reset Boat address
;Update ping value
;Update all control registers
;send shift register variables out to ports
;clear key ignition values PORT RC2
;clear key ignition values PORT RB4
;save correct values into shift register variables
;clear State test byte
;Change state to key ignition
;********************************************************************************
;STATE HELM KEY OFF
;********************************************************************************
;Check the key state
;change the PWM output for the Volt meter display
;update shift register
;check to make sure key switches are in "off" position
;set the next state
;clear the ignition test byte
;********************************************************************************
;STATE HELM KEY IGNITION
;********************************************************************************
;Check the key state
;change the PWM output for the Volt meter display
;update shift register
;Key Switch check
;save new port values PORT RC2
;save new port values PORT RB4
;Check transition on PORT RC2
;reset TMR
;Check transition on PORT RB4
;reset TMR
;check if both key switches made a transition from LO to HI
;save correct values into shift register variables
;send shift register variables out to ports
;clear the ignition test byte
;set the next state
;save new to old port values PORT RC2
;save new to old port values PORT RB4
;********************************************************************************
;********************************************************************************
;********************************************************************************
;STATE HELM iButtonWait
;********************************************************************************
;********************************************************************************
;********************************************************************************
;Check the state bit
;change the PWM output for the Volt meter display
;reset ibutton
;Update ping value
;Call iButton function
;Check if Serial Numbers are still 0
;if not still 0, continue, else RETURN
;reset ibutton
;Call iButton function
;Check if Serial Numbers are still 0
;if not still 0, continue, else RETURN
;Call all config .asm files
;save correct values into shift register variables
;Change state to iButtonTx
;********************************************************************************
;STATE HELM iButtonTx
;********************************************************************************
;check the state
;change the PWM output for the Volt meter display
;update shfit register
;Update ping value
;check if the "send msg flag" is set; if it's set do not attempt to send another msg
;Broadcast iButton serial number
;set sender address
;Set header
;Set data to send
;Send iButton data to boat
;Check Craft to Helm header
;Parse Craft to Helm packet
;Save boat address
;save correct values into shift register variables
;send shift register variables out to ports
;change state to StartGame
;Clear header
;********************************************************************************
;STATE HELM StartGame
;********************************************************************************
;check the state
;change the PWM output for the Volt meter display
;Update ping value
;Check Admiral header
;Check if it was a start game message from the Admiral (byte 2)
;Save sender address
;save sent message and set data to send
;set sender address
;set header
;send ack msg
;Clear header
;change state to game on
;Check if it was an end game message from the Admiral (byte 2)
;Save sender address
;save sent message and set data to send
;set sender address
;set header
;send ack msg
;Clear header
;save correct values into shift register variables
;send shift register variables out to ports
;change state to end game
;********************************************************************************
;STATE BOAT GameOn
;********************************************************************************
;check the state
;change the PWM output for the Volt meter display
;Update ping value
;check if the "send msg flag" is set; if it's set do not attempt to send another msg
;check a second "send msg flag" is set; if it's set do not attempt to send another msg
;Send data out to craft
;set sender address
;set header
;set data to send
;send nav packet
;Check Admiral header
;Check if it was an end game message from the Admiral (byte 2)
;Save sender address
;save sent message and set data to send
;set sender address
;set header
;send ack msg
;Clear header
;change state to end game
;Check Craft to Helm header
;Parse Craft to Helm packet
;clear 10sec TMR
;Save sender address
;save sent message and set data to send
;set sender address
;set header
;send ack msg
;Clear header
;save correct values into shift register variables
;change state to stand down
;********************************************************************************
;STATE BOAT StandDown
;********************************************************************************
;check the state
;change the PWM output for the Volt meter display
;update shift register
;Update ping value
;check if the "send msg flag" is set; if it's set do not attempt to send another msg
;Send data out to craft
;set sender address
;set header
;set data to send
;Check Admiral header
;Check if it was an end game message from the Admiral (byte 2)
;Save sender address
;save sent message and set data to send
;set sender address
;set header
;send ack msg
;Clear header
;save correct values into shift register variables
;send shift register variables out to ports
;change state to end game
;Clear header
;********************************************************************************
;STATE HELM ENDGAME
;********************************************************************************
;check the state
;change the PWM output for the Volt meter display
;Update ping value
;check if the "send msg flag" is set; if it's set do not attempt to send another msg
;check if a second "send msg flag" is set; if it's set do not attempt to send another msg
;Send data out to craft
;set sender address
;set header
;set data to send
;send nav packet
;Check Admiral header (skip next line if header matches)
;Check if it was a start game message from the Admiral (byte 2)
;Save sender address
;save sent message and set data to send
;set sender address
;set header
;send ack msg
;Clear header
;change state
;********************************************************************************