Sie sind auf Seite 1von 3

Microcontrollers

LAB # 2. 7-segment display


I. OBJECTIVES By the end of this laboratory assignment, you should be able to: Use switches to read digital inputs. Display numerical values using 7-segment displays.

II. LAB PREPARATION Read sections 5.1, 5.3, 7.10 and 7.11 of the textbook Arduino Cookbook. III. MATERIALS 1 Arduino UNO board 1 USB cable 1 Protoboard 1 Pushbutton 1 2-digit 7-segment display 1 10K resistor 14 470 resistors 2 1K resistors 2 2N3904 transistors Wires

IV. PROCEDURE The purpose of the lab is to design an application to count how many times a switch is pressed, and show the value in a 2-digit 7-segment display. The system should be able to count up to 99 and start again. Part 1. Pushbutton 1. Connect the pushbutton to a digital pin using a 10K resistor, as seen in Fig 1. Note that when the pushbutton is not pressed, the input reads HIGH, and when the pushbutton is pressed, the circuit is closed and the input reads LOW. This connection is known as pull-up, and it is less affected by noise than the pull-down connection (Shown in Fig 5.3 of Arduino Cookbook).

Page 1 of 3

Microcontrollers

Fig 1. Pushbutton connected using a pull-up resistor.

Fig 2. Connecting a 2-digit 7-segment display to the Arduino board. 2. Type the example in section 5.3 of Arduino Cookbook. It turns ON the LED on the board when the pushbutton is pressed. It uses a function called debounce. When the pushbutton is pressed, the debounce function reads the status of the input pin every 1ms to check if the signal is stable. The function ends when the signal has been stable for 10ms, and outputs the value in the input pin. This function is designed for a pulldown connection, so the value in the input pin is expected to be HIGH when pressed and stable. 3. Modify the program for the pull-up connection. Save the file with a different name.

Page 2 of 3

Microcontrollers 4. Compile the sketch and program the microcontroller. 5. Verify that the program works well and demonstrate the application to the professor.

Part 2. Counter. 6. The section 7.11 of the Arduino Cookbook shows how to use time-multiplexing to drive multiple 7-segment displays. The segment pins of the displays are connected together, and the common pin is used to select and drive one of the displays at a time. 7. Connect the 2-digit 7-segment display to the Arduino board as seen in Fig 2. Reassign the input pins to include the pushbutton. 8. Use the program in section 7.11 of Arduino Cookbook to display the numbers from 0 to 99 in the displays. Include the code from Part 1 to design a system that counts how many times the switch is pressed and displays the result on the 7-segment display. 9. Compile the sketch and program the microcontroller. 10. Verify that the program works well and demonstrate the application to the professor.

V. WRITTEN REPORT Include the following sections: Description of the application. Flowchart of the program. Code Circuit Discussion and conclusions

Page 3 of 3

Das könnte Ihnen auch gefallen