You are on page 1of 6

CoE 115 2s1819 Machine Exercise 2 [50 points]

Word Guessing Game


Objectives
 To demonstrate a working I 2C communication
 To demonstrate how to use multiple peripherals at a time in a complex program
 To be able to use an external EEPROM in an embedded system

Schedule and Scoring

Milestone Score Deadline (Lab Class)


Startup, Write Mode, Read Modes 15 November 21/22, 2018
Parse Mode + Game Mode (Word Select and Timer) 10 November 28/29, 2018
Game Mode (Others) + Special Case 25 December 5/6, 2018
TOTAL 50

Scoring Details
Milestone Score Week
Startup 1 1
Write EEPROM 5 1
Write done display 1 1
Read EEPROM 8 1
Word Select (for Game mode) 1 2
Parsing 5 2
Time Remaining (in Game mode) 4 2
Scrolling Letters 6 3
Incorrect Letters 6 3
Correct Letters 6 3
LED blink 3 3
Game End 1 3
No EEPROM 3 3

Hardware and Peripherals

Hardware Required Peripherals


LCD ADC (2)
Keypad I2 C
Push Button Output Compare
Potentiometer (2) Timer
24LC32 EEPROM
Red LED
SPECIFICATIONS

You are to create a “Word Guessing Game” whose words to be used are stored in an external EEPROM. Each
word should be 4 to 10 letters long. Each word should start at every 16 th byte place in memory while each
letter should occupy one byte of memory. Letters A to Z should be encoded as 0x01 to 0x1A. Unoccupied
memory locations should contain 0x00. Refer to the example below (all addresses and data are in
hexadecimal).

Address LSB 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
Data 05 18 01 0D 10 0C 05 00 00 00 00 00 00 00 00 00
Letter E X A M P L E - - - - - - - - -

Address LSB 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
Data 12 05 0E 04 05 1A 16 0F 15 13 00 00 00 00 00 00
Letter R E N D E Z V O U S - - - - - -

(always 00)
Startup
At startup, your program should prompt the user which mode to use. At this state, your system should only
be responsive to the reset button and keypad (1-4). Pressing the corresponding keypad buttons changes the
state into the following modes: (W) Write Mode, (R) Read Mode, (P) Parse Mode, and (G) Game mode. The
number on the right hand side will be explained on the Game Mode portion of this document. [1 point]

Write Mode
Your PIC24 microcontroller should write 64 unique words to the lowest memory addresses in the EEPROM.
While the write is processing, your LCD should display the message below and the red LED should light up.
Your system should only be responsive to the reset button while in this mode. [5 points but prerequisite is
read mode]

Restrictions: See table on the next page regarding the number of unique letter per word.

After the writing is done, turn off the LED and then display the message below. Pressing the push button
should put your system back to the Startup state. [1 point]

Read Mode
The read mode should display the contents of the EEEPROM through the LCD. The display should include the
word number based on the address at which the word is saved. Two words should be displayed at a time.
Moving the first potentiometer should scroll the display from the first and second words, up to the second to
the last and last words. Each state of the display should be properly distributed over the full potentiometer
range. [8 points]
Parse Mode
[5 points] The parse mode should display how the words in the EEPROM will be initially displayed during the
game. Similar to the one shown below:

There will be a set of rules to be followed when determining which letters to be displayed. First, the number
of given free uncovered unique letters must follow the table below. Let N be the length of the word and let
X, Y, and Z be the values for the first second and third letters. Uncover the letter at the n 1th place, and all
places with the same letter, where n 1 = mod(X, N)+1. Then, uncover the letter at the n 2 th place, and all places
with the same letter, where n 2 = mod(Y, N)+1. If the letter at the n 2th place is already uncovered, then update
n2 as n2 = mod(n2, N)+1. If a third letter needs to be uncovered, then follow the same rules for n2 but use Z in
as the basis instead of Y.

Word Minimum Number of Free Uncovered


Length Unique Letters Letters
4 3 2
5 3 2
6 4 2
7 4 3
8 4 3
9 5 3
10 5 3

All numbers in the discussion to follow is in decimal. For example, if the word is ELLIPSES, the N = 8, X = 5
(from E), Y = 12 (from L), and Z = 12 (from L). Since N = 8, there should be 3 uncovered letters. From X, we
get n1 = mod(5,8)+1 = 6 and therefore we should uncover the letter at the 6 th place which is S. From Y, we
get n2 = mod(12,8)+1 = 5 and therefore we should uncover the letter at the 5 th place which is P. From Z, we
get n3 = mod(12,8)+1 = 5 and therefore we should uncover the letter at the 5 th place. However, P is already
uncovered and we update n 3 to 6. However the letter at the 6th place is already uncovered. Therefore, we
update again n3 to 7 and uncover the letter at the 7th place which is E.

Similar how the Read mode worked, the first potentiometer should also be able to control which word is
displayed in Parse mode.
Game Mode
In Game mode, the LCD displays follows the format below. The word to be guessed at its current state, with
all the correctly guessed letters already uncovered, must occupy the upper left side of the display. This
portion of the display will be referred as the “word state” display. The upper right portion of the display
should display the “scrolling letters” with the cursor at the middle letter. The portion at the lower right
should contain the “incorrect letters.” The portion on the lower left should contain the “time remaining.”

Scrolling Letters Display


[6 points] The scrolling letter spans five columns including the “?:” and displays three letters at a time.
Exceptions are when the selected letter is either is A and Z where the display should be “?:-AB” and “?:YZ-“
respectively. The selected letter is the one at the middle or the cursor. The LCD cursor should be always be
seen at the selected letter. The selected letter must be controlled by the potentiometer position. All letters
already chosen by the user, whether correct or not, should be replaced by a “-“ on the scrolling letters
portion. For example, if the letter F is already chosen, the scrolling display should look like “?: -GH” when the
letter G is selected. Also, all letters already displayed by default should be replaced by “-“. The initial state of
the scrolling letters depend on the potentiometer position and does not necessarily have to start with “-AB”.

Incorrect Letters Display


[6 points] The incorrectly guessed letters should be put in displayed on this part. The incorrect letter must
appear from left to the right. For example, if the letters M, N, and O are chosen in order and all of them are
incorrect, then the incorrect letters display should go from “X:M ” to “X:MN ” to “X:MNO”.

(Note that in the second example, the P is already replaced by a dash line since it is a given or is already
“guessed” by default.)

Gameplay
Before the start of game, at startup mode, a second potentiometer must be used to control which word
(word address) should be used for the game. The full range of the potentiometer must correspond to the
maximum number of words in the EEPROM and be displayed on the lower right portion of the display at
startup. Once the game has started any changes on this potentiometer should not affect the currently
running game. The potentiometer stated must only be used for word select. [1 point]

The player guesses that a letter is part of the word by selecting the lette r using the potentiometer and then
pressing the button. If the guess is correct, then all occurrences of the letter should appear on the “word
state” [6 points]. If the guess is incorrect, then the letter should be displayed on the “incorrect letter”
portion. The letter should then appear as “-“ in the scrolling letters display.

Pressing the button while the selected “letter” is a “-“ should do nothing.
The display should look like the one below if
 the word is “ELLIPSES” and
 the letters L, F, and J have been entered as guesses
 the current selected letter is K

The player is only allowed up to three incorrect guesses. Depending on the number of incorrect guesses, the
LED should toggle between ON and OFF. The toggling of the LED should continue as long as the game is not
finished. [3 points]

Incorrect Guesses LED Toggle Interval


0 infinity (always OFF)
1 0.8 seconds
2 0.4 seconds
3 0.2 seconds

If the player makes 4 incorrect guesses, then for 3 seconds, the LED must be turned and remain ON while the
LCD displays “YOU LOSE!” at the middle of the LCD. At this state, the system should not respond to any input
other than the reset button. After three seconds, the LED turns off the system goes back to Startup mode.
[0.5 point]

If the player guesses correctly all the letters of the word, then the LED is turned off and for three seconds,
the LCD should display “YOU WIN!” at the middle. At this state, the system should not respond to any input
other than the reset button. After three seconds, the system goes back to Startup mode. [0.5 point]

Time Remaining Display


[4 points] The player is also given 10*N seconds (40, 30, … , 100 seconds for 4, 3, … , 10 letter words) to
guess the whole word. While the game is proceeding, the remaining time should be displayed on the lower
left portion of the display. If the time given expires, then the player also loses.

Special Case
When any mode from startup is chosen and the EEPROM is not connected, the LCD should display “EEPROM
not detected!” and lights up the LED. Pressing the push button returns the state to startup. [3 points]

You might also like