You are on page 1of 17

ELEC254 Project Report Group 4

ELEC254 Microprocessor Experiments


Project Report

Project Title: EXStream

Year: Fall 2007

Group Number: 4

Group Members:

Guo Yuanfang (05710430) eg_gyx@stu.ust.hk

Lin Nan (05733729) eg_lnx@stu.ust.hk

ZHAO Siqi (06630716) eg_zsxad@stu.ust.hk

Page 1
ELEC254 Project Report Group 4

Table of Content
 Introduction

 Overall system Information

 Setup and operation instruction

 Limitation and further improvement

 Description of hardware

 LCD

 Implement motion sensor

 Play background music

 Description of software

 Data structure

 Game Algorithm

 Display movement of stream (snake)

 Display and Generate target

 Update score and level

 Control motion sensor

 Play background music

 Summary and Conclusion

 Appendix

 LCD screen

 Motion sensor

Page 2
ELEC254 Project Report Group 4

Introduction
EXstream is a re-implementation of Snake, which is a video game that gained
popularity in the 1990s since its inclusion on mobile phones. In the game, the
player controls a long, thin line, resembling the flow of water in streams (or a
snake in the game Snake), which roams around on a bordered plane, submerges
obstacles, trying to avoid overlapping its own route or the "dams" that surround
the playing area.

Traditionally, the control of Snake on different platforms is based on four buttons,


controlling four directions. However this conventional way of controlling has long
been a big headache to players. It is quite hard to handle the buttons once the
game gets more difficult, as people easily press the wrong button because of short
reaction time. To improve usability, we integrate the innovative motion sensitivity
into the control of game. The handy motion detection control system sets
EXstream apart from the traditional Snake game and adds an extreme immersion
to the EXstream gaming experience. Users don’t have to worry about pressing the
wrong button anymore, and all they have to do is to tilt the joystick in the
direction they want the stream to go. EXstream delivers remarkable fun and
innovative gameplay.

Page 3
ELEC254 Project Report Group 4

Overall system Information

Hardware components:
1. 8051 emulator
2. 128 x 64 dot matrix LCD display
3. Motion Sensor – ADXL311
4. Analog to digital converter – ADC0804
5. Speaker
6. Inverter – 74LS05

Software components:
1. Display on LCD
2. Move Stream
3. Generate target
4. Update score and level
5. Play background music

Page 4
ELEC254 Project Report Group 4

Setup and operation instructions


Setup instructions
1. Set up the emulator
2. Connect the circuit to a 5V supply
3. Make sure the motion sensor is initially parallel with ground
3. Run the program in Medwin

Operating Instructions
1. Welcome picture is shown on the LCD. Select a playing mode using left or right
button. And press start button to start game.
2. Press the direction buttons when the button mode is selected. Tilt the motion
sensor when the motion mode is selected.
3. Score and level will be displayed on the left side of screen.
4. When score satisfies the upgrade score, level increment and the moving speed
will be faster under button mode.
5. If game is over, it will return to the welcome picture and condition.
6. Repeat from step 1.

Page 5
ELEC254 Project Report Group 4

Limitation and Further improvement

 Because we use polling in checking the press-event, it is not sensitive so that


users may need to press the button a little bit longer.

It’s better to store the value in a variable before check it so that a new value can
be get during checking the previous value.

 There is no recording system to record the highest score and previous score which
is not user-friendly enough.

It’s better to store the previous score and highest simply use variables so that
users may want to challenge themselves again and againg.

 The motion sensor is not sensitive enough because the sensor is too small to
solder steadily. So the value given by motion sensor (via ADC) is not stable
which may cause undesirable manipulation.

A suitable socket is needed so that soldering can be omitted. The value given by
motion sensor will be more stable and contain less noise.

 The background music is a little bit simple.

More tones and coherent melody is desirable. Users may feel more comfortable
and relaxed when they are playing.

 The final product is lacking of decoration and looks not beautiful and shiny.

If some decoration, such as blinking LED etc, can be added, users can enjoy the
game and love it more.

Page 6
ELEC254 Project Report Group 4

Description of Hardware

Page 7
ELEC254 Project Report Group 4

 LCD
The LCD we use in the experiment is a standard 128 x 64 dot matrix display.

Page 8
ELEC254 Project Report Group 4

 Motion Sensor
ADXL311

Page 9
ELEC254 Project Report Group 4

 Background music

Page 10
ELEC254 Project Report Group 4

Description of Software

 Data structure
There is a 14x14 matrix to represent the grids that stream (snake) can reach. Each
grid has an unique coordinate value from (0, 0) to (13, 13), (0, 0) to (D, D) in Hex.
There is an array in the internal memory starting from the location 30H to represent
the coordinates that the stream (snake) occupies sequentially. The memory location

Page 11
ELEC254 Project Report Group 4

30H will always store the head position of this stream (snake). The variable
LENGTH will store the length of the stream (snake) which is initially 4 and
increased by 1 when the stream (snake) hits the target. The memory location (30H +
LENGTH) will store the tail position.
The higher 4 bits of a memory location will store the x coordinate value and the
lower 4 bits stores the y coordinate value.

 Game Algorithm

Page 12
ELEC254 Project Report Group 4

i) Select a playing mode (CHECK_START)

The Game has two playing mode. One is button mode and the other is motion mode.
Users can choose the playing mode when the welcome picture shown on the screen.
Choosing the button mode will enter the conventional Snake playing mode which is
to control the movement of the snake by buttons. Choosing the motion mode will
enter the innovative ExStream playing mode which is to control the movement by
motion sensor.
An arrow will point to the chose mode.

ii) Movement of the Stream


The detection of moving direction is realized by polling. The program will repeat
check the press-event (CHECK_LEFT etc.) for a certain number of times.

When the movement direction is decided, new head position will be computed.
Up – subtract 01h on current head value
Down - add 01h on current head value
Left – subtract 10h
Right – add 10h
Store the new head value in variable NEW_HEAD.

In button mode if no press-event occurs the stream (snake) will move to the
previous direction. There is a variable PREV_DIR indicating the current direction.
The default moving direction is right. The opposite direction button will be disabled
by software.

Check if the stream (snake) hit itself using function VALID_MOVE. Compare the
new head value with the value stored in memory location from 30H to 30H +
LENGTH. If there exists a value in this array which is equal to new head value,
game is over and jump to the welcome picture to start a new game.
Check if the stream (snake) hit the wall using function VALID_MOVE. Do the
logic operation AND between new head value and 11110000B, 00001111B. If the
value out of the range of (0, D), game is over and jump to the welcome picture to
start a new game.
If the movement is valid, call the function DISPLAY_UNIT.

Shift all the previous value stored from 30H to 30H + LENGTH backward and
insert the new head value at memory location 30H.

Check if the head value is the same as the target value. If they are equal, the
LENGTH will be increment and finish the movement function. If they are not equal,
clear the memory location at 30H + LENGTH + 1 and call the function
CLEAR_UNIT.

Page 13
ELEC254 Project Report Group 4

 Display movement of stream (snake)

Function DISPLAY_UNIT is used to display a unit (4*4 pixels) on the particular


position indicated by variable NEW_HEAD.
Check the upper 4 bits to decide if the position is on the left side or right side of the
screen. Apply two methods to get the Y address value. Multiply 4 to the value of

Page 14
ELEC254 Project Report Group 4

upper 4 bits if the value is larger than 5, on the right side. Multiply 4 to the value of
upper 4 bits and then subtracted from 03FH if the value is smaller than 6, on the left
side.
Check the lower 4 bits to decide the position is in which X page. Divide the lower 4
bits value by 2 in order to get the X page number. Check the value in register B, if
the position is in odd line, it should be displayed on the upper half page (4*4 pixels)
otherwise it should be displayed on the lower half page (4*4 pixels). Then compare
the other half page coordinate with the stream (snake) body array and the target
position to decide whether the whole page is occupied. If it is nether occupied by
the body of stream (snake) nor the target, check whether it’s occupied by the
boundary. If not, just display a unit (4*4 pixels) on half page at the computed page
number and Y address. If the full page is occupied, display 2 units (4*8 pixels) at
the computed page and Y address. Repeat displaying 4 times and increment the Y
address simultaneously.

Function CLEAR_UNIT is used to clear the unit which is not valid any more. The
address calculation is the same as function DISPLAY_UNIT. The difference here is
to display a blank unit (4*4 pixels). That also need to check the other half page is
being occupied or not in order to decide to write 2 blank units (4*8 pixels) or 1
blank unit (4*4 pixels).

 Display and generate target


A function RAND8 is used to generate an 8 bits random number and both upper and
lower 4 bits are in the range (00H, 0DH). Then store the random number in variable
RAND8NUM. Firstly use the previous random number as base to generate 2 new 4
bits number. Secondly, check the 4 bits numbers. If either one is out of range,
generate new 4 bits to replace current one. When the 2 numbers are both within the
range merge them to an 8 bits number which is the position of next target. At last,
call function DISPLAY_UNIT to display it on the screen.

 Update score and level


A function UPDATE_SCORE is used to update the score. The score is stored in
variable SCORE which increment when the stream (snake) gets the target. To
display the score, the value will be divided by 10 and the digits of score can be
decided. If there is only one digit, jump to ONE_DIGIT to display the
correspondent number at the specific position on screen. If there are two digits,
jump TWO_DIGITS to display the higher digit at the specific position, then
continue the ONE_DIGIT to display the lower digit.
Every time when the score increment, compare the value with a set value to decide
whether the score satisfies the higher level. If the score is high enough to upgrade,
increment the level value stored in variable LEVEL and shrink the delay time.

Page 15
ELEC254 Project Report Group 4

 Control motion sensor


Theoretically, the value given by motion sensor (via ADC) should be 127±5 when
the sensor is parallel with ground. So boundary values are needed to
detect 4 directions. After receiving a value, program will compare the
value with a range from boundary value to 32 values further. When the
value given by motion sensor (via ADC) is within the range the moving
direction can be decided. This detection is merged in function
CHECK_LEFT etc.

 Play background music


A function SOUND is used to play the background music. The speaker actually
needs analog signals. To play the background music without a DAC, delay is
frequently used to generate a pitch frequency.

Refer to wikipedia: http://en.wikipedia.org/wiki/Piano_key_frequencies

Page 16
ELEC254 Project Report Group 4

Summary and Conclusion

From doing this project, we learned many things.


Innovation
This task is chose by ourselves. In order to get a innovative product we have brain
storm and inspire each other. Besides, the plan should be feasible to ensure that we
can finish it within 6 weeks.
Find out the problems
A large number of problems will come out when we do the project. The hardware’s
bug is difficult to be found because there isn’t support from software. The connection
should be checked line by line. The software’s bug is a little bit easier to be found
because of the powerful software. However, numerous bugs may come out at the
same time, we have to find out the key point and solve them one by one.
Solve the problems
Solving hardware problem should be very careful otherwise some component will be
damaged accidentally. Software debugging is not an easy task. One problem may be
caused by many reasons. Find out the key point and solve it is difficult especially the
program becomes longer and longer.
Communication and co-operation
This is a group task and the task is divided into 3 parts. So the communication and
co-operation becomes important.
Conclusion
The experience of doing such a project is useful for us to connect the knowledge with
practical. From doing the project, we made a great progress in hardware and software
interface. Also we saw the weak aspect of our studying.

Appendix
 12864 dot matrix LCD
 ADXL311 motion sensor

Page 17

You might also like