当前位置:天才代写 > 作业代写,留学生作业代写-北美、澳洲、英国等靠谱代写 > 游戏实验代写 微控制器嵌入式游戏代写

游戏实验代写 微控制器嵌入式游戏代写

2021-06-16 16:32 星期三 所属: 作业代写,留学生作业代写-北美、澳洲、英国等靠谱代写 浏览:610

游戏实验代写

Embedded Control Laboratory 2

A Microcontroller Embedded Game

 游戏实验代写 This laboratory consists of implementing a simple game consisting of a potentiometer (POT), two push￾buttons (PB1,PB2), and two lines of LEDs

SIMULATED LABORATORY 游戏实验代写

Readings

  • Lab Manual: Chapter 2 – LabEquipment
  • Lab Manual: Chapter 4 – The Silicon Labs C8051F020  and  the  EVB :  Sections  relating  to Timer 0/1 and A/D Conversion.

Laboratory Goals

  • Provide an introduction to analog-to-digital conversion through the implementation of an interactivegame using the microcontroller and utilizing various switches and LEDs for game I/O.
  • Furtherrefinement of programming skills, including bit/byte manipulation, more complex algorithm implementation, and debugging.
  • Adaptation and re-use of software modules developed in previous lab exercises.
  • Implementanalog-to-digital conversions in order to provide more flexible user input.
  • Modification of initialization routines.游戏实验代写

Motivation 

In the previous labs, the use of digital inputs and outputs was explored in addition to basic timer usage. While digital signals compose the dominant majority of any embedded system’s internal operation, most of the “real world” is analog. In this lab, you will explore how an embedded system can convert an analog signal into a digital value. The skills refined and developed in this lab exercise are applicable to embedded systems in general and will be applicable to the following labs.

General Lab Description

This laboratory consists of implementing a simple game consisting of a potentiometer (POT), two push- buttons (PB1,PB2), and two lines of LEDs: LEDA[0-7] and LEDB[0-7]. The objective of the game is to convert a hexadecimal number printed on the terminal into a binary number and enter it into the circuitry using the POT and pushbuttons. An entire game consists of 9 total rounds. A timer, Timer 0 in 16-bit mode with SYSCLK/12, is used to used to keep track of the entry time for each round, which is limited to 10 seconds. If the entry time expires, the round ends.游戏实验代写

游戏实验代写
游戏实验代写

Entry of the binary number is done through configuring the LEDB line to represent the converted number. In order to set the LEDB line, the POT is moved to light up LEDAn which corresponds to a desired bit, n, to modify. Upon pressing PB1, the LEDB LED/bit corresponding to the lit LED in the LEDA line is toggled. The user should repeat this process until LEDB is the correct representation of the binary number, at which point PB2 should be pressed to submit the answer. Pressing PB1 and then pressing PB2 while PB1 is still held will cause all bits in the players current answer to reset back to 0.游戏实验代写

Scoring for the game consists of adding the whole seconds remaining for each round to the player’s score for a correctly submitted answer.

If the answer was incorrect, the whole seconds should be subtracted fromthe score, thereby penalizing players who are trying to answer quickly and failing. If the round ends withouta submission, 1 second should be subtracted from the player’s score.

The 9 rounds of the game are broken into three separate difficulties: the first three rounds should have the player convert a number that contains only 4 bits, the next three rounds require 6-bit numbers, and the final three: 8-bit. rand() should be used to generate a number for each round, with that number reduced to the required size.游戏实验代写 There is no complexity requirement on the generated number, for example: 0x01 is a valid number for all three difficulties.

To start the game, the player must press and release PB2. Further, once a game has completed, pressing and releasing PB2 will cause another game to begin.

The schematic for the system is show in Figure 1. All of the LEDs and pushbuttons are connected and configured as in previous labs; further, the potentiometer is configured as discussed in Lecture 6, though with a different resistor value. The ADC gain should be selected to make the best use of the ADC given these values. The components that have fixed port and pin assignments have them specified in Figure 1.游戏实验代写 The components with unassigned values will be found in the simulation once the RIN has been applied. Within the simulator window, the LEDA line is the green (lower) line of LEDs and the LEDB line is the red (upper) line of LEDs.

See https://youtu.be/mw8OXrOqcmE for example operation of the game.

Laboratory Success Conditions 游戏实验代写

  • Gameis playable and mostly follows the gameplay as described
  • Timer0 is configured properly and uses the
  • ADCconversions and calculations from the POT input are consistent and
  • Thesubmitted source code is documented, indented, and modular1.

Pseudocode 游戏实验代写

The following is high-level pseudocode for implementing the game as described above. Some segments of the full pseudocode are missing or not completely described. Finally, some portions of the below would make more sense to be placed separate functions.

main function:

Initialize everything

Wait for keyboard press (to allow the simulator and code to sync) Print game instructions

Infinite Loop:

Wait for Press/Release of PB2 Loop Through Rounds:

Generate random number and print out (4-bit, 6-bit, or 8-bit) Clear player’s answer and turn off all LEDB

Start round timer

Loop until submitted or timeout: Read ADC value

From ADC value, light up proper LEDA LED Check for and act on pushbutton presses  游戏实验代写

PB1: Toggle LEDB location indicated by LEDA PB1(first)+PB2: Reset player answer

PB2: Submit answer

Make sure if any PBs pressed, they are released Update and print score depending on submission or timeout

Print out final score and instructions for restarting

1Modular code: [Simplified] Implementation of system is broken into functions that perform specific tasks; that is, all code cannot exist in the main() function.

Hints 游戏实验代写

  1. Note from Figure 1 that the LED lines are all part of a single port. Sometimes it’s more useful  to  usethe port value instead of individual sbits.
  2. Becausethe program uses 32-bit math, the operation ~0x00 is not equal to 0xFF. It is actually equal to 0xFFFFFFFF until it is saved back to a smaller  This may cause warnings to be generated if you are inverting values and assigning to Px.
  3. Likewise,remember that the logic for LEDs being lit is
  4. AnADC conversion from ADC1 results in a value of 0-255. This range needs to be converted into 8 equal parts to convert to a position on line  An easy way to do this is through a division and a bitshift of 0x01 or tediously as a set of if/elseif/else statements.

5.Simulator GUI control: Clicking the potentiometer (a linear potentiometer) will cause the poten- tiometer to follow the mouse.

Clicking the potentiometer again will release control. PB1 and PB2 may be controlled through keyboard buttons 1 and 2, respectively.

6.Whenchecking for pushbutton presses, it is fine to toggle values in LEDB when PB1 is pressed and then clear if PB2 is subsequently pressed.

7.Related:Make sure that a submission isn’t registered if PB1+PB2 are pressed then PB2 is subsequently pressed.

8.Youmay notice that through repeated runs, the random numbers generated are the same each  This is because rand() is pseudorandom, not random. A good way to make the numbers more random is to “seed” the random number generator using the function srand(uint16_t seed). A seed number is needed to produce the randomness, which could be generated from counting timer overflows when waiting for user input, e.g.:

counts = 0;

while(PB);

srand(counts);

  1. Do not do the above with getchar(). The way it is implemented in this environment may cause the communicationbetween the simulator and code to break.
  2. No template code is provided for this laboratory. Starting from Lab 1-2 is a good
  3. As always, don’t forgetSim_Update()!

 

游戏实验代写
游戏实验代写

其他代写:program代写 cs作业代写 app代写  Programming代写 homework代写  考试助攻 finance代写 代写CS finance代写 java代写 代写CS作业 course代写 lab代写

合作平台:essay代写 论文代写 写手招聘 英国留学生代写

 

天才代写-代写联系方式