by David Tow and Emily Cheng

Our software design can be divided into two different components. 

Keypad Side

On the keypad side, we need to be able to detect whether the push buttons are pressed or not, and which one is pressed.  These are taken care of in our "check_button" function by our state machine.  The state diagram can be found in the Appendix page.  Additionally, we need to find the direction that the drawing pointer is moving.  Below is a table that shows how each key press gets mapped into up, down, left, and right. This encoding scheme is done in our "encode_direct" function, which takes in four directions from the keypad. Our "get_direct" function determines which keypad directions are pressed. This state machine's state diagram can also be found in the appendix page. 

Key Press Up Down Right Left
1 1 0 0 1
2 1 0 0 0
3 1 0 1 0
4 0 0 0 1
5 0 0 0 0
6 0 0 1 0
7 0 1 0 1
8 0 1 0 0
9 0 1 1 0

We use timer1 for the directional movement and timer2 for checking button presses. Both timers are run at 2ms.

Like we described on the High level design page, we use UART to transmit signals. We set the UART control register to Transmit Enable by setting UCRSB = 0x08. We also need to set the baud rate to 4800 by making UBR = 103. And we set UDR = data_to_be_transferred when we want to transmit data.

TV Side

On the TV side, we need to take care of the actual drawing. On reset or when the board first initializes, the television screen draws four lines, one on each edge of the screen, to signify the borders of the screen's drawing region. It also places the drawing pointer at the center of the drawing region. Using some code that we had implemented in laboratory three for the TV drawing, we got our television to display images. We want our drawing device to draw anywhere within the four border lines.  We only use timer1 and run it at full speed on the TV side. Timer1 is interrupted after 509 timer ticks to make each frame exactly 1/60 of a second.

We use the "video_line" function to draw the border lines, "video_pt" function to draw any other images, and "video_set" function to determine whether a pixel is drawn on the screen or not. Each of these functions can be found in the laboratory three code and on the Video Generation with AVR microcontroller page.

During the vertical blanking (from line 231 to 262), We need to decode the received signal to determine what we want and where we want to draw on the television. We need to decode the drawing pointer direction and button presses for draw, erase, and clear screen. One can draw on the TV when the left button is pressed and erase when the right button is pressed. Pressing the middle button will clear the screen.

As described in the High level design page, we also use UART to receive signals. On the reception side, we set the UART control register to Receive Enable by setting UCRSB = 0x10. We also need to set the baud rate to 4800 by making UBR = 103.  We set the received_data = UDR.