Fig 1. Four-digit seven-segment display
1. FOUR-DIGIT SEVEN-SEGMENT DISPLAYS
As we recall, we need 8 microcontroller pins to drive a single-digit 7-segment display (7 to control LEDs and 1 to power source or ground). This means that using 4 single-digit displays would require a total of 32 microcontroller pins.
A 4-digit display works in a similar way, but is designed to be controlled by only 11 pins (or more if the display has periods, colons, etc). To achieve this, we still use 7 pins to control the 7 LEDs in each of the digits at the same time and the other 4 pins control which of the digits will be on or off. Obviously, the easiest way of understanding this circuit is by looking at the circuit diagram in figure 2.
To display all numbers at the same time, the microcontroller continuously turns on each of the digits for a fraction of a second. When this is done fast enough, our eyes see only one image. This is the same concept used by movies, where a series of pictures alternated at high speed give us the illusion that they are moving.
NOTE: A better explanation of how common-anode 7-segment displays work can be found in this guide.
Fig 2. Pin layout and circuit diagram of common-anode 4-digit 7-segment display 5641BH
2. TESTING 4-DIGIT 7-SEGMENT DISPLAY WITH TIVA C LAUNCHPAD
2.1 DESCRIPTION
We will use the Tiva C Launchpad to design a button-press counter which will be displayed in the 4-digit 7-segment display.
2.2 MATERIALS
- Tiva C Launchpad
- Breadboard
- 4 x 2N3904 NPN Transistors
- 1 x 5641BH 4-digit 7-segment common-anode display
- 4 x 1KΩ resistors
- 7 x 47Ω resistors
2.3 HARDWARE
The system will use 11 output pins from the Launchpad to control the LED display. We will connect 7 of the pins directly to the display for LED selection (A through G), and the other 4 pins will be connected to the NPN transistors to provide power to each of the digits from the +3V3 power rail.
For the button-press counter we will also be using the on-board switch SW2 included in the Launchpad.
The datasheet for the 5641BH 7-segment display can be found in this link.
The circuit diagram is shown below (figure 3). Notice the push-button isn't included in the diagram since it is already a mounted in the Launchpad.
Fig 3. Circuit diagram for our test system
2.4 SOFTWARE
Visit my Github repository and download or copy the code in the file SevenSegment2.c. An explanation of how the code works can be found in the comments within the code and the flowchard in figure 4.
Instructions on how to create a project using Keil uVision 4 can be found in my previous 7-segment display guide.
Fig 4. Flowchart of microcontroller code
No comments:
Post a Comment