home   |  video   |  gallery   |  circuitry   |  code   |  construction   |  bom   |  gems of wisdom  


Code

Pseudo Code:
[Helm SM] [Ship SM] [Helm Keypad]

Source Code (zip):
[Helm & Ship PIC] [Ship SSP Slave] [Helm Keypad]

Diagrams:
[State Machine] [Pinout]

Support Code (zip):
[PIC Serial Communicator]

Ship 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 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

 

;********************************************************************************

;STATE BOAT INITIALIZE

;********************************************************************************

            ;Check the state bit

 

            ;Call all config .asm files

 

            ;Update all control registers

 

            ;reset ibutton

 

            ;reset Helm address

 

            ;Update ping value

 

            ;Change state to bSTATE_iButtonWait

 

;********************************************************************************

;STATE BOAT iButtonWait

;********************************************************************************

            ;Check the state bit

 

            ;Update all control registers

 

            ;Update ping value

 

            ;reset ibutton

 

            ;Call iButton function

           

;Check if Serial Numbers are still 0

                        ;reset ibutton

                        ;if not still 0, RETURN

 

            ;Call iButton function

 

            ;Check if Serial Numbers are still 0

                        ;if not still 0, RETURN

 

            ;Call all config .asm files

 

            ;Output team color

 

            ;Change state to iButtonRx

 

;********************************************************************************

;STATE BOAT iButtonRx

;********************************************************************************

            ;check the state

 

            ;Update all controll registers

 

            ;Update ping value

 

            ;Check iButton header

                        ;check byte Hi of iButton

                        ;check byte Lo of iButton

                                    ;if there’s a match continue, else RETURN

                        ;Clear header

                        ;Save sender address

                        ;set sender address

                        ;Set header

                        ;Set data to send

                        ;set flag to send message (match message)

 

            ;clear test byte and set GameOn bit

 

            ;Clear 3 sec TMR

 

;********************************************************************************

;STATE BOAT GameOn

;********************************************************************************

            ;check the state

 

            ;Update ping value

 

            ;Check Navigation header

                        ;Clear 3 sec TMR

                        ;Parse Nav Packet

;call servo motor counter setup

                        ;Clear header

 

            ;Check Admiral header

                        ;Check if it was a stand down message from the Admiral (byte 2)

                                    ;Save sender address

                                    ;save sent message and set data to send

                                    ;set sender address

                                    ;set header

                                    ;set flag to send message (ack msg)

                                    ;Clear header

                                    ;Change state to stand down

                        ;Check if it was a soft reset message from the Admiral (byte 2)

                                    ;Save sender address

                                    ;save sent message and set data to send

                                    ;set sender address

                                    ;set header

                                    ;set flag to send message (ack msg)

                                    ;Clear header

                                    ;change state to GameOn

 

;********************************************************************************

;STATE BOAT StandDown

;********************************************************************************

            ;check the state

 

            ;Update ping value

 

            ;Update all controll registers

 

            ;check if the "send msg flag" is set; if it's set do not attempt to send another msg

 

            ;Forward stand down msg to helm

                        ;set sender address

                        ;set header

                        ;set data to send

                        ;send stand down received

 

            ;Check Admiral header

                        ;Check if it was a soft reset message from the Admiral (byte 2)

                                    ;Save sender address

                                    ;save sent message and set data to send

                                    ;set sender address

                                    ;set header

                                    ;set flag to send msg (ack msg)

                                    ;Clear header

                                    ;clears State and sets GameOn bit

 

            ;Check Ack header

                        ;Clear header

                        ;clears State and sets GameOn bit

 

;********************************************************************************

;STATE BOAT Lost

;********************************************************************************

            ;check the state

 

            ;Update ping value

 

            ;Update all control registers

 

            ;Check Navigation header

                        ;Clear header

                        ;change state to GameOn

 

            ;Check Admiral header

                        ;Check if it was a stand down message from the Admiral (byte 2)

                                    ;Save sender address

                                    ;save sent message and set data to send

                                    ;set sender address

                                    ;set header

                                    ;set flag to send msg (ack msg)

                                    ;Clear header

                                    ;Change state to stand down

                        ;Check if it was a soft reset message from the Admiral (byte 2)

                                    ;Save sender address

                                    ;save sent message and set data to send

                                    ;set sender address

                                    ;set header

                                    ;set flag to send msg (ack msg)

                                    ;Clear header

                                    ;change state to GameOn

 

;********************************************************************************