In this tutorial we are going to design a 0-99 counter by interfacing two seven segment displays to ATMEGA32A Microcontroller. Here we count events based on number of times button is pressed.
Before moving ahead, let’s understand what is a seven segment display. A seven segment display got its name from the very fact that it has seven illuminating segments. Each of these segments has an LED (Light Emitting Diode). You can see the pin diagram of a seven segment display in below image.
The LEDs are fabricated in a manner that lighting of each LED is contained to its own segment. The important thing to notice here, the LEDs in any seven segment display are arranged in common anode mode (common positive) or common cathode mode (common negative).
The circuit connection of LEDs in common cathode and common anode is shown in above figure. Here one can observe that, in Common Cathode, the negative terminals of every LED is connected together and brought out as GND. In Common Anode, the positive of every LED is connected together and brought out as VCC. These Common Cathode and Common Anode displays come in very handy while multiplexing several cells together.
Now let’s understand multiplexing. It’s simple a technique used to connect more units in parallel to lessen the pins required, by taking advantage of visual effect. Consider an LED is turning ON and OFF continuously at a rate of 2HZ per second, i.e. it ON two times and OFF two times a second. Now at this rate a human eye can see both ON cycle and OFF cycle. But if frequency is increased to 50HZ, that is 50 ON times and 50 OFF times for the LED in a second. At this rate a human eye cannot see turning OFF cycles at all. This is an effect of vision. At this rate the eye pictures the LED with less brightness and that is all.
Hardware: ATMEGA32, Power supply (5v), AVR-ISP PROGRAMMER, HDSP5503, Seven segment displays (two pieces) (any common cathode will do ), 47uF capacitor (connected across power supply), button(three pieces), 10KΩ resistor (two pieces), 1KΩ resistor, 220Ω resistor (two pieces), 100nF capacitor (three pieces), 2N2222 transistors (two pieces).
Software: Atmel studio 6.1, progisp or flash magic.
Circuit Diagram and Working Explanation
The connections which are done for 7 segment display are as follows:
PIN1 or e to PIN (A, 4)
PIN2 or d to PIN (A, 3)
PIN4 or c to PIN (A, 2)
PIN5 or h or DP to PIN (A, 7) /// Not needed as we are not using decimal point
PIN6 or b to PIN (A, 1)
PIN7 or a to PIN (A, 0)
PIN9 or f to PIN (A, 5)
PIN10 or g to PIN (A, 6)
PIN3 or PIN8 or CC to transistor collector
The important thing here is although both segments share same data port to ATMEGA, the Common Cathodes of both displays are connected to two different transistor collectors. Now as of multiplexing, as explained in introduction we are going to turn ON and OFF displays instead of LED.
Here we have two transistors each driving current from each display. What we are doing is, we are going to trigger one transistor for 10ms and another display for an another 10ms, so the display one will be ON for 10ms and then it turns OFF, during this time other display will be ON. Then again display one and so on. This ON and OFF periods are small for the eye to pick so we see both displays ON continuously, which is not the case in real.
There are two buttons present here, one button is for incrementing the display count and another is for decreasing the display count. The capacitors present here is for nullifying the bouncing effect of buttons. If they are removed the controller might count more than one each time the button is pressed.
The resistors connected for pins are for limiting the current, when the button is pressed to pull down the pin to the ground. Whenever a button is pressed, the corresponding pin of controller gets pulled down to ground and thus the controller recognizes that certain button is pressed and corresponding action to be taken – it may be incrementing or decrementing the count depending on button pressed.
The count is displayed in two segments by multiplexing as explained before. The working of this 0-99 counter is explained in step by step of C code given below. You can also read this tutorial if you are working with 8051 microcontroller: 7 Segment Display Interfacing with 8051.
Read more: 0-99 Counter using AVR Microcontroller