Character Display
In order to allow for flexibility, the LCD software was a mix of C and assembly. Sending instructions to the LCD were accomplished in assembly by writing the data to memory mapped I/O. Because of the game and the increased number of messages to print to the LCD, we created C-based wrapper functions that would take in a string and call the assembly functions on each character. This allowed for interactions with the LCD to be more versatile, and simplified the writing of the game, since it was C-based. Since we did not implement reading of the LCD’s busy signal, the assembly functions contained wait states that looped for a set time to ensure that the LCD would be available whenever instructions were being sent to it. Since the latency of the clear display instruction was much longer than those of the other instructions, we created a longer wait state when clear display was being executed, and a standard wait state for the remainder of the instructions.
Servos
The servo motors were all handled in Assembly in our ISR via Level 4 interrupts fired from the GPT. We used two timers: one for the trigger servo, the other for the two directional servos. This required us to make use of the CIPR for detecting which timer was the source of the interrupt. Depending on what buttons were being pressed on the NS8 controller, we would alter the TMRRs and turn the motor signals on and off to control the pulse width and therefore the servo positions. While we could have handled some of this in hardware, we chose a software interrupt based approach to learn more about interrupts and timers. Our main issues were in figuring out how to use the CIPR, CISR, CIVR so that we were successful in choosing which interrupt to handle and clearing the proper bits in the proper registers when done with the interrupt.
Game Design
We created a simple game in order to demonstrate the functionality. This game starts with a menu that allows the user to select a number of players and start a new game. In this game, players alternate between firing at a target for a fixed number of rounds. At the end of the game, the user who struck the most targets is the winner.