Overall Software Design
To successfully play a game, our software design had to accomplish several key tasks:
- Obtain an ASCII RFID key when swiping an RFID card (must be coded in Assembly).
- Convert that ASCII key to a HEX serial number. If necessary, get a corresponding security key from the security controller.
- Send and receive XBee radio messages on both the boat and bike.
The RFID PIC (16F690) did task 1. The security PIC (16F690) did task 2. The Main PIC (16F777) and the E128 did task 3. We interfaced our three PICs using SPI. For simplicity, we made the Security PIC a master - it would retrieve an RFID key and send out a serial number and security key to the Main PIC. The RFID PIC signaled that it had a new key by lowering an I/O line tied to the Security PIC.
Process Flow Diagrams
The state machines for the RFID and security PICs were straighforward and always followed the same state progression. Instead we've attached the process flow diagrams, which quickly communicate the basic software design:
Our RFID PIC originally had timeouts built in in case we didn't get a full RFID message, but this never occurred throughout the project and we had problems with using Timer0, so we took them out.
Note that every RFID scan proceeds through the above process diagrams. To avoid putting in lookup tables in our Security PIC, we try to get a security key for all card swipes, even color card swipes. On the Main PIC, once we determine that we've received a color swipe serial number, we just ignore the security key that was sent with it.
Note that every RFID scan proceeds through the above process diagrams. To avoid putting in lookup tables in our Security PIC, we try to get a security key for all card swipes, even color card swipes. On the Main PIC, once we determine that we've received a color swipe serial number, we just ignore the security key that was sent with it.
Communication State Machines
There are two communications state machines that are used in tandem to receive and transmit a message. Both of these state machines are implemented in the same form on the E128 and the PIC. The only differences are with reference to the specific differences in registers between these microcontrollers.
The receive message state machine shown below reads a packet of variable length sent by the XBee radio to the microcontroller and stores each byte of the message into an array. As the state machine transitions from one state to another, a byte is stored into the array. Additionally, the state machine calculates the Checksum from the XBee and ensures that the message is not corrupted. If it is, the state machine will flag a Checksum error flag.
The receive message state machine shown below reads a packet of variable length sent by the XBee radio to the microcontroller and stores each byte of the message into an array. As the state machine transitions from one state to another, a byte is stored into the array. Additionally, the state machine calculates the Checksum from the XBee and ensures that the message is not corrupted. If it is, the state machine will flag a Checksum error flag.
The following state machine is the transmit message state machine which will take a message stored into an array and send it out to the XBee radio.
Main PIC State Machine
After a Team Broadcast exceeds 255 transmissions, we chose to raise our team color flag halfway to signal that there was a timeout when trying to find a teammate. The state diagram shows that when this occurs there is a transition from the BROADCAST TEAM COLOR state to the GAME IDLE state. We prevented the user from actually playing the game and capturing atolls as a design choice in the software.
Within the GAME ON state, there is an event checker that responds to messages received by the XBee radio. The event checker can be viewed in the code listings and pseudocode below.
Within the GAME ON state, there is an event checker that responds to messages received by the XBee radio. The event checker can be viewed in the code listings and pseudocode below.
Code Listings
CVC: E128 Code Listings
|
ACV: PIC Code Listings
RFID PIC:
RFIDMain.asm / Pseudocode Security PIC: SecurityPIC.c / Pseudocode Main PIC: MainPIC.c / Pseudocode SCIMessage.c / SCIMessage.h / Pseudocode MainIO.c / MainIO.h / Pseudocode TimerPIC.c / TimerPIC.h / Pseudocode Communication.h Messages.h TimerNumber.h |