Both sides previous revisionPrevious revisionNext revision | Previous revision |
en:exercises:digi [2010/02/07 09:50] – priitj | en:exercises:digi [2020/07/20 09:00] (current) – external edit 127.0.0.1 |
---|
====== Exercises ====== | ====== Exercises ====== |
| |
The goal is to make a program witch is able to perform specified task. | The goal is to write a program which is able to perform tasks described below. |
| |
===== Warm up exercise ===== | ===== Warm up exercise ===== |
| |
*If pressing S1 it one LED is lighted, pressing S2 two LED-s and S3 three LED-s. | *By pressing S1 one LED is lit, pressing S2 two LEDs and S3 three LEDs lit. |
| |
===== For beginners ===== | ===== For beginners ===== |
| |
- 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 | - This simulates manually operated traffic light at pedestrian crossing. Until no button is pressed a green LED is lit for the cars. After pressing a random button the green LED will start to blink for 3 seconds, this is followed by lighting the yellow LED for 3 seconds and red for 10 seconds, after this sequence a green LED is lit again. |
- 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. | - This counts how many times the button is pressed. Only the full release of the button will complete the pressing. The result is displayed in binary code on LEDs. Maximum result for three LEDs is 7(23-1). Green marks 1. bit, yellow 2. bit and red 3. bit. |
- 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). | - By pressing switch S1, LED1 and LED3 are lit; pressing S2 yellow LED is lit, pressing S3 all LEDs are switched off. This operation must be done by directly changing the values of corresponding registers (without using the library of the HomeLab). |
- 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. | - This counts how many times the button is pressed. The result is displayed by blinking of the LEDs. After each pressing the number of blinking is increased by one. A random button can be selected. In order for the LED to blink a sub function must be used, with parameters set on the number of blinks. |
- 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”. | - 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 ===== | ===== For advanced ===== |
| |
- 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). | - For each of the three buttons corresponds one LED which lights up when the button is pressed. For turning on or off, registers must be used and only one assigning operation (hint: use bit shifts). |
- 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. | - For each of the three buttons corresponds one LED which lights up when the button is pressed. For turning on or off, registers must be used and only one assigning operation (hint: use bit shifts). |
- 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). | - There is one button for each LED. The controller blinks LEDs randomly and the user has to repeat the same sequence. The sequence of blinks gets longer – one random LED is added with a new round. The sequence is controlled after each user. The time gap between each entry is two seconds. In case of an incorrect entry all LEDs blink three times. (The number of correct entries by the user may be displayed on a LCD screen). |
- 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. | - The program measures time for reaction. A random LED is lit and the user has to press the corresponding button as fast as possible. The time when the LED is lit is random, but not less than 100 ms. the result is displayed on a LCD screen in milliseconds. The value of the buttons cannot be read with filtering function for the flickering, since this will cause an extra delay. |
| |
===== Questions ===== | ===== Questions ===== |
| |
- Mis on tehete "=" ja "==" erinevus? Esitage selle erinevuse tõestuseks kaks näidet. | - What is the difference between operations”=” and”==” ? Give two examples to verify the statement. |
- Mis on tehete "|" ja "||" erinevus? Esitage selle erinevuse tõestuseks kaks näidet. | - What is the difference between operations “|” and “||”? Give two examples to verify the statement. |
- Kirjutage avaldis, milles kasutate võrrandit "x = x + 1" kaksteist korda. | - Write an expression using the equation “x = x + 1” twelve times. |
- Kuidas kirjutate C-keeles lõputu tsükli? | - How an endless loop is written in C-programming language? Provide two different examples. |
- Millist tüüpi muutuja valite C-keeles, et esitada positiivseid arve vahemikus 7 kuni 154? | - What type of a variable do you choose in C–language to present positive values between 7 and 154? |
- Milline register määrab ära pordi suuna? Tooge pordi näide sisendi ja väljundi seadistamise kohta. | - Witch register determines the direction of a port? Provide an example of configuring settings of ports’ input and output. |
- Milliste meetoditega saab elimineerida nupu värelust? Tooge näiteid riistvaralise ja tarkvaralise lahenduse kohta. | - What are the methods for eliminating the bouncing of the contacts and the false connections caused by flickering? Provide examples of solutions using both hardware and software. |
- Mida tähendab termin bitinihutus? Tooge praktiline näide koos seletusega. | - What is bit shift? Give a practical example with an explanation. |
- Miks kasutatakse lülitite juures //pull-up//-takistit? Mille järgi määratakse selle takistus? | - Why are pull-up resistors used in switches? How is their resistance determined? |
- Arvutage LED voolu piirava takisti väärtus, kui toitepinge on 5 V, LED päripinge 2,7 V ja vool 30 mA. | - 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. |