Software Design
The software design for this project was pretty straightforward. The laser
guns did not need any software since they did not require a microcontroller.
The microcontroller on the detector setup was used for several functions: detect
hits to the players own detector, listen for transmissions of hits to
the opponents detector, broadcast hits to the players detector, keep score,
provide messages and the score on an LCD, and produce a noise when the player
is hit.
To accomplish these tasks we used two timers, all four ports of the 8515, and
several polling loops. We set timer 0 to interrupt every one millisecond, which
provided us with a task scheduler. Several tasks to check for hits, transmit
hits, etc where scheduled at different millisecond intervals. One function checked
for a hit to the player by looking for a zero on pin 0 of port B every 2 milliseconds.
The internal pull-up resistors where activated on port B, but not port D. Another
function checked for checked for at least 10 consecutive ones on pin 0 of port
D every 1 millisecond. Since the receiver connected to port D, already pulled
the pins high or low, no pull-up or pull-down resistors where necessary. If
either of these functions detected a hit, it incremented the appropriate counter,
and output this new score and a message to the LCD on port C. After one of the
players was hit eleven times, the game was over and a game over
message was output to the LCD. The controller then waited for a reset button
push on pin 1 of port D. If the player was hit, the corresponding function also
set flags for the hit transmit and noise functions. Timer 1 was used to toggle
pin 0 of port A at different frequencies, thereby producing a sound wave for
the speaker.
Communication between the players microcontroller and the opponents
microcontroller was necessary to synchronize the scores. Due to the nature of
the receivers we were using, they always needed to receive a signal regardless
of whether a message needed to be sent or not. To handle this issue, we had
one of the controllers output a constant 1 kHz square wave on port A, which
was connected to the transmitter. When the hit transmit flag was set, this square
was momentarily disabled and port A was set to all ones for 80 milliseconds.
After this hit message, the square wave was restarted. To prevent
the player from effectively shooting himself, the receiver function
was disabled during the hit transmission. A more robust handshaking algorithm
could have been used, but we didnt deem the additional complexity necessary
since really only one message was being broadcast.