Project: Colors
By: James Roberts and Joseph Oh


Description of Project:

A device demonstrating another classic psychology experiment.
A two person game where each player has a green card and a red card.
If both players play the green card then both players will get 5 points each.
If both players play the red card then they lose 5 points each.
If one players plays the green card and the other plays the red card,
then the player with the red card gets 10 points and the player with
the green card gets no points. The first player to break 50 points wins the game.
A tie game is possible. There is no negative scoring so there
exists a minimum score of 0.


User Manual:

NOTE: The LCD is fundamental to the game. It serves a myriad of functions. It tells each
player when to make their choice. After both have made their choices it shows Player 1's and
Player 2's choices to both parties. It also displays each player's score after both have made their
choices (in conjunction with the Seven-Segment displays). Upon the end of the game it displays the
final scores and the appropiate winner.


Upon initial power up the system will begin a new game.

The LCD will then ask Player 1 to pick a color. When Player 1 has chosen a color the
corresponding LED will light and the LCD will then ask Player 2 to choose. As soon as Player 2
has choosen a color the LCD will reveal to both players their opponent's color choice. It will also
tell the current scores of both players in conjunction with the Seven-segment displays. At this point
if no player has a score of 50 points or greater the above process will repeat. If one or both players
scores 50 points or more the LCD will inform the players whom has won the game and will then cycle in
an end of game sequence. This sequence consists of a Game Over message, which player won the game and
a scrolling message informing potential players to press the reset button to begin a new game.


Implementation:

The project was initially broken down into two sections: input and output.
Input consisted of 4 buttons, 2 buttons per player. These were deligated to Port 0. The
buttons were configured in such a manner that the port floated high. This corresponded to
no button being pressed. When a button was pressed the port bit would go low. As Port 0 is
somewhat tempermental a pull up resistor was added.

There is also a reset button. Pressing this button at any time will initialize the chip
and start a new game.

Output consisted of 4 Seven-Segment LEDs, 4 LEDs, and a LCD.

The output was subdivided into 3 sections: Seven-Segment, LED and LCD.



Seven-Segment:


The seven-segment LEDS provided an instant and direct display of each players score.
As a player's score is a maximum of 50 pts or minimum of 0 pts, two seven segment displays per
player was sufficient.

The output for these LEDs was deligated to Port 1. In order to handle all four seven-segment
displays through a single port on the 8051, the displays were mutliplexed. A timer interrupt
was employed to flash each of the displays in sequence. As only one of the displays is lit at a time,
it was necessary to determine a flash rate that produced no visible flickering. It was determined
that a rate of 5ms was more than sufficient. The upper 4 bits of Port 1 determined the
number to be displayed. The lower four bits determined which of the four seven-segment LEDs
received the number.

The integers to be displayed were in the range of 0 - 9. This required
a four bit number which of course was fed into the 4 upper bits of Port 1. These four bits were
inturn passed into a Seven-Segment decoder which decodes the four bit number into a standard
seven-segment diplay format.

Actual output to the displays was configured by first getting the score values for
each of the two players. These values were then further subdivided into the integers representing
the ten's place value and one's place value of each players score. For example if Player 1's
score was 10 and Player 2's score was 35 the following values would be passed into the array:

dispdigits[3] = 1
dispdigits[2] = 0
dispdigits[1] = 3
dispdigits[0] = 5


Then these values were shifted four bits to the left corresponding to the upper four bits of Port 1.
They in turn were added to a four bit number corresponding to the lower four bits of Port 1.
In essence the digit to be displayed was shifted four bits to the left and combined with the drive
information for the digit to be illuminated on a seven-segment display. The drive information
is contained in a table. This table consisted of the following values: 0x0e, 0x0d,0x0b, and 0x07.
A single counter (dispcounter) was used to point to each array. This counter was incremented by
one for every timer interrupt call and reset to zero upon reaching the value of 4.

For example if dipcounter is at zero. The one's value of Player 2's score would be shifted
four bits to the left and added to a value of 0x0e. This 8 bit value would then be passed into Port 1.

Careful examination of the drive table would reveal the following:

0x0e == 1110
0x0d == 1101
0x0b == 1011
0x07 == 0111

A value of 0 turns a seven-segment display ON, while a value of 1 turns a segment OFF.
This would turn on only one seven-segment display at a time.


4 Leds:

The LEDS were used to confirm a players choice. The LEDs were physically layed out
to a button corresponding to a color choice. If a player choose the button corresponding to a red
card than the red led would light. The same for a choice of green.


LCD:

The LCD display is fundamental to the game as described in the user manual. The driver
for this display is included as file "io.c" which was provided for us.


Click Here for the "Colors.c" source code.
Click Here for the "io.c" source code.
Click Here for a schematic.