This is an old revision of the document!


Exercises

The goal is to make a program witch is able to perform specified task.

Warm up exercise

  • If pressing S1 it one LED is lighted, pressing S2 two LED-s and S3 three LED-s.

For beginners

  1. It simulates traffic light when the button is pressed. Until no button is pressed the yellow light is blinking (traffic light in night mode). After pressing a random button the traffic light starts working in everyday mode, lighting yellow, then red and before continuing again yellow
  2. Counts how many times the button is pressed. The pressing is considered as ended after the button is released. The result is displayed is binary code on LED-s. Maximum result when using three LED-s is 7(23-1). Green is 1. bit, yellow 2. bit and red 3. bit.
  3. By pressing switch S1, LED1 and LED3 are lighted, pressing S2 yellow LED is lighted, pressing S3 all LED-s are switched off. This operation must be done by changing directly values of corresponding registers (without using the library of the home lab).
  4. Counts how many times the button is pressed. The result is displayed by blinking LED-s. After every press the number of blinking is raised by one. Random button may be selected. Blinking the LED sub function witch’s parameter is the number of blinks must be used.
  5. When pushing button S1, red LED will blink “SOS” in Morse. By pressing S2, yellow LED blinks “CQD” and by pressing S3, green will blink “OK”.

For advanced

  1. For each button of three corresponds one LED witch lights when the button is pressed. To turn on or turn off registers must be used and only one assigning operation (hint: use bit shifts).
  2. When pressing the buttons in following sequence: S3-S2-S1, green LED is lighted. If other combinations are used only yellow will blink confirming that the button is pressed.
  3. There is one button for each LED. The controller blinks LED-s randomly and the user has to repeat that sequence. The sequence of blinks is longer each time – one random LED is added. After the user has had his turn his turn is controlled whether it was correct. The time gap between each entry is two seconds. In case of incorrect entry all LED-s are blinked three times. (The number of correct entries by the user may be displayed on a LCD).
  4. The program measures time for reaction. When a random LED is lighted, the user has to press the corresponding button. The time when the LED is lighted is random, but at least 100 ms. The result is displayed on a LCD in milliseconds. The value of the buttons can not be read with the function that filters flickering because it results an extra delay.

Questions

  1. What is different between operations ”=” and ”==” ? Give two examples to prove that
  2. What is different between operations “|” and “||”? Give two examples to prove that.
  3. Write an expression in witch you use equation “x = x + 1” twelve times.
  4. How an endless loop is written in C programming language?
  5. What type of a variable do you choose is C – language to present positive numbers between 7 and 154?
  6. Witch register determines the direction of a port? Give an example of a port setting input and output.
  7. What methods can be used to prevent flickering? Give examples of methods using hardware and software.
  8. What is bit shift? Give a practical example with an explanation.
  9. For what are pull-up-resistors used by switches? How is their resistance determined?
  10. Calculate the resistance for regulating LED current, the voltage is 5 V, forward voltage of the LED is 2,7 V and the current is 30 mA.
en/exercises/digi.1265537305.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0