当前位置:天才代写 > course代写,Online course代写代做-品原创拿高分! > Laboratory代写 game代写 programming代写 source code代写

Laboratory代写 game代写 programming代写 source code代写

2021-05-16 11:01 星期日 所属: course代写,Online course代写代做-品原创拿高分! 浏览:642

Laboratory代写

Embedded Control Laboratory 2

Laboratory代写 Provide an introduction to analog-to-digital conversion through the implementation of an interactive game using the microcontroller

A Microcontroller Embedded Game

SIMULATED LABORATORY

Readings Laboratory代写

  • 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

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
  • Adaptation and re-use of software modules developed in previous lab
  • Implementanalog-to-digital conversions in order to provide more flexible user
  • Modification of initialization

Motivation Laboratory代写

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, mostof the “real world” is analog. In this lab, you will explore how an embedded system can convert an analogsignal 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.

Laboratory代写
Laboratory代写

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.Laboratory代写

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.Laboratory代写

The 9 rounds of the game are broken into three separate difficulties: the first three rounds should havethe 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.Laboratory代写

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.Laboratory代写

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.Laboratory代写 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 Laboratory代写

  • 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.Laboratory代写

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.Laboratory代写

main function:

Initialize everything

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

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 Laboratory代写

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 Laboratory代写

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 0255. 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 anda bitshift of 0x01 or tediously as a set of if/elseif/else statements.Laboratory代写

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,

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

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

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); Laboratory代写

  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
  2. No template code is provided for this laboratory. Starting from Lab 1-2 is a good
  3. As always, don’t forgetSim_Update()!

Laboratory代写
Laboratory代写

其他代写:web代写 program代写 cs作业代写 analysis代写 app代写 essay代写 assembly代写 Haskell代写 homework代写 source code代写 考试助攻 web代写 finance代写 Exercise代写 物理代写 数学代写

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

 

天才代写-代写联系方式