The interrupt is a mechanism in which we can achieve a little multitasking and automation of microcontroller operation. The general digital input requires continuous polling of the pin. But in this method, the microcontroller is occupied in polling, thus wasting time.
This problem can be solved with interrupt. Here, the microcontroller performs is assigned task. When an interrupt occurs on a particular pin, the microcontroller stops its current operation, serves the interrupt by calling interrupt service routine, and again returns to its regular operation at a place where interrupt was called. This facilitates better use of microcontroller.
The Arduino Uno has two hardware interrupts - Pin 2 and Pin 3. We can program these pins for interrupt using the following function:
attachInterrupt(digitalPinToInterrupt(pinNumber), nameofISR, mode);
In this project, a seven-segment display is used. The seven-segment display is of common anode type. It is interfaced with Arduino via 74LS47 BCD-to-Seven Segment Display decoder IC. We can directly connect seven-segment display with Arduino, but it will use seven pins of Arduino. While using 74LS47 decoder IC requires only five pins of Arduino and it enables some facilities like blinking, which is hard to program without decoder.
The schematic diagram is as below.
Here, the power pins of IC and Arduino are not shown. But remember to connect pin-8 of 74LS47 to ground and pin-16 to +5V. Also connect Arduino's ground with IC's ground. The +5V to IC and seven-segment display can be applied from Arduino, but its better to use external power supply for overload protection of Arduino.
The circuit works as follows:
The Arduino continuously displays 0 to 9 counting on seven-segment display with 1 second delay and blinking of 500 ms off time. When the switch is pressed, it resets the count value to 0. After that, the counting continues as before. Every time the switch is pressed, it resets the count.
Now, the 74LS47 decoder works as follows. It is a 16-pin IC. It has 4-bit BCD (Binary Coded Decimal) input - A, B, C and D (A is LSB and D is MSB), connected to Arduino's four digital pins; and 7 digital outputs (a to f), which are connected to 7 inputs (a to f) of seven-segment display via 180 ohm resistors. It has three more inputs, the detailed description of which can be found in its datasheet. Here we have used one input, RBI, to blink the display. When a low signal (logic 0, GND) is applied to RBI pin, all seven outputs will become inactive, thus turning off the seven-segment display. This can also be used to blink the display.
The seven-segment display used here is of common anode type, because the outputs of 74LS47 decoder are active low. If you use common cathode type display, the 74LS47 cannot be used. The solution is HEF4543B decoder which has active high output which are compatible with common cathode display.
Now the following video shows the working of the circuit.
The code of this circuit is attached. The code is explained in comments. Study it with the working description of the circuit.
Comments
Please log in or sign up to comment.