Question: ECE 375: Computer Organization and Assembly Language Programming Lab 7 Remotely communicated Rock Paper Scissors SECTION OVERVIEW Complete the following objectives: Write an assembly program
ECE 375: Computer Organization and Assembly Language Programming Lab 7 Remotely communicated Rock Paper Scissors
SECTION OVERVIEW
Complete the following objectives: Write an assembly program (for two separate mega32u4 boards) and have them interact.
Learn how to configure and use the Universal Synchronous/Asynchronous Receiver/Transmitter (USART) module on the ATmega32U4 microcontroller.
Learn how to configure and use the 16-bit Timer/Counter1 module to generate a 1.5-sec delay.
BACKGROUND
As previous labs have demonstrated, microcontrollers are well-suited for tasks such as: receiving user input and generating output via general-purpose I/O (GPIO) ports, performing arithmetic and logic computations, and accurately measuring intervals of time. However, microcontrollers are also frequently used for tasks that require communication with the outside world, which for our purposes means anything that exists outside of the mega32U4 board.
When using a microcontroller to interact with the outside world, it is very convenient to have a structured, standardized way of exchanging information, as opposed to manually implementing data transfer using the GPIO ports. For this reason, microcontrollers often implement a variety of communication protocols. Communication protocols come in two varieties: parallel and serial. Parallel communication protocols are typically used for internal microcontroller communication, such as a shared data bus. Serial communication protocols are more commonly used for external interactions. Some common examples of serial protocols are Serial Peripheral Interface (SPI) and Two-wire Serial Interface (TWI). The ATmega32U4 microcontroller, in addition to providing built-in modules for both SPI and TWI, also comes with Universal Synchronous/Asynchronous Receiver/Transmitter (USART) modules. USART is not a communication protocol; instead, it is a highly-configurable hardware module that can be setup to implement point-to-point serial communication (with various parity, data rate, and frame format settings). If two microcontrollers each have a USART module, then they can perform full-duplex serial communication as long as their respective USART modules are configured with the same settings, and as long as there is a physical interface (wired) that links their respective TX/RX pins. Specifically, TX and RX pins in a board need to be wired with RX and TX pins in the other board, respectively. GND pins in both boards also need to be connected.
Board 1 Board 2
PD2 - PD3
PD3 -PD2
PD.gnd - PD.gnd
IMPLEMENTATION In this lab, there is a challenge part to earn extra credits. For students who have decided to implement the challenge part, you can just submit the challenge code to Canvas. Challenge code will replace the requirement of the source code. In this project you will be designing a system to battle of rock paper scissors between two ECE375 boards. We will use the LCD screen on our board to prompt messages (i.e., ready, start, result, etc.) and choices of your hands (i.e., rock, paper and scissors). For a smooth process, we will use the 4 LEDs, which are connected to PB4-7, as a countdown timer
Functionality When the CPU firsts boots, the LCD screen should show the following content to the user: Welcome! Please press PD7 This content will remain indefinitely until the user presses the button which is connected to Port D, pin 7. After the button is pressed, the users board should transmit a ready signal to the opponent so that it knows the user is ready. Additionally, this information will be displayed on the users screen: Ready. Waiting for the opponent This content will remain indefinitely until the opponent player presses the PD7 on their board and sends a ready signal to the users board. When the users board transmits/receives the ready signal to/from the opponent, both the user and the opponents 4 LEDs are on and start counting down by turning off one by one at each 1.5-second. Simultaneously, their screens will also display: Game start The second line of the LCD is where the user is able to select the choice among three gestures (i.e., rock, paper, and scissors) that they want to send. First pressing PD4 selects the Rock gesture. Pressing PD4 changes the current gesture and iterates through the thee gestures in order. For example, Rock Paper Scissor Rock ... Pressing PD4 immediately displays the choice on the users LCD. (Challenge part should meet all of the above features as well.) For example, if the display currently shows: Game start then pressing PD4 will immediately update the screen to display: Game start Rock pressing PD4 again will display: Game start Paper At this point, the opponents play should not appear in the users board even if it receives the opponents signals. After 4 LEDs are off, which means 6 seconds timer is done, the final choice of the opponents gesture and the users will be displayed in the first line and the second line of the LCD respectively. For example, if the opponents gesture is scissor and the users one is paper, the users LCD will display: Scissor Paper Meanwhile, the opponents LCD will display: Paper Scissor Simultaneously, 4 LEDs on both boards will turn on in order to start counting down for the 6 seconds delay. After timeout, the outcome will be displayed on the first line of the screens and start a new timer. For example, the users LCD will display: You lost Paper On the other hand, the opponents LCD will display:
You won! Scissor if both players have chosen the same gesture, the first line should be updated with a draw message. After the new timer is done, the code will return to the prompt as shown: Welcome! Please press PD7 The user can now enter another game round, exactly as before. Specifications You will need to configure the USART1 module on the boards. Also, although the ATmega32U4s USART modules can communicate at rates as high as 2 106 bits per second (2 Mbps), you will use the (relatively) slow baud rate of 2400 bits per second with double data rate. Packets, which consist of 8-bit data frame with 2-stop bits and no parity bit, will be sent back-to-back by the USART modules. One of packets will be a send ready byte, which indicates the sender is ready to start a game. The others include a choice of their gestures. The LCD display needs to be updated immediately whenever the user provides input. Single button press must result in a single action. You must use the Timer/Counter1 module with NORMAL mode to manage the countdown unit timing. You may design your code to use polling or you may use interrupts (either approach is fine). You may not utilize any busy loop for the code delay, although it is allowed to loop if you are monitoring an interrupt flag. Do not include switch debouncing delays of more than 150ms. A busy loop for debouncing is okay. The LCD screen must never display symbols, gibberish, or other undesired output. Hints Students often ask about the behavior of the LEDs which are connected to PB1-PB3. In some cases the LCD library will illuminate one or more of those
LEDs (even if you dont want them to be enabled). You do not need to worry about this. The project guidelines do not dictate the behavior of any LEDs which arent mentioned in the project instructions. However, overwriting values to PB1-PB3 (e.g., during 4 LEDs countdown implementation) can result in the failure of using the LCD. You will need to avoid overwriting unused bits (PB0-PB3)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
