One of the basic usage of the TIMER peripheral on every microcontroller is to provide the accurate timing mechanism. Using the TIMER peripheral as the basic timing, we could easily develop a stopwatch and display it to the 8-Digit seven segment numeric LED display. Thanks to the Maxim MAX7219 chip which enable us to interface this 8-Digit seven segment LED display much easier using just three wires of the SPI (serial peripheral interface) to display the hour, minute, second, and hundredth of seconds to the 8-Digit seven segments LED display.
On this tutorial we will learn to utilize the Atmel AVR ATMega328P microcontroller SPI peripheral to communicate with the Maxim MAX7219 chip. The AVR ATmega328P SPI peripheral will be configured as a master and Maxim MAX7219 as the SPI device slave; you could read more about the SPI in Using Serial Peripheral Interface (SPI) Master and Slave with Atmel AVR Microcontroller project on this blog. A simplified electronic schematic of this project is shown in this following picture.
The following is the list of hardware, software, and references used to build this project:
1. One Maxim MAX7219: Serially Interfaced, 8-Digit LED Display Drivers
2. Two common cathode 4-Digits seven segment LED display
3. One Resistor: 10K Ohm
4. One Capacitors 0.1uF
5. AVRJazz 28PIN development board from ermicro which is based on the AVR ATmega328P microcontroller.
6. Atmel AVR Studio 6.0 for coding and debugging environment
7. STK500 programmer from AVR Studio 6.0, using the AVRJazz 28PIN board STK500 v2.0 bootloader
8. Atmel AVR ATmega328 and Maxim MAX7219 Datasheet
The stopwatch project that we are going to build has these following features:
- Stopwatch counting up to hundredth of second when the SW1 is pressed
- Pressing the SW1 once will freeze the counting display while continuing counting in the background, pressing the SW1 again will continue to display the stopwatch counting
- Adjust the intensity of the 8-Digits seven segment LED display using the trimmer potentiometer (TP).
- Reset the stopwatch counting by pressing the SW0.
In order to accomplish this project, we will use the AVR ATmega328P 16-bit TIMER2 peripheral in compare match mode as the heart beat of the counting mechanism, the pin change interrupt is used to detect the SW1 switch, and the ADC peripheral is used to adjust the 8-Digit seven segment LED display brightness. This project also serves as a good example of how we use many of the powerful AVR ATmega328P microcontroller features at the same time. The following is the complete C code for this project:
The Maxim MAX7219
The MAX7219 chip from maxim is a powerful serial input/output common-cathode display driver that interfaces microcontroller to 7-segment numeric LED displays of up to 8 digits. It has a build-in BCD (binary code decimal) decoder and a brightness control. Although the main function is to drive the 8-Digits seven segment LED display but because it also capable to drive an individual LED segment i.e. segment A to segment G and DP (decimal point), therefore you could also use this chip to drive the individual LED, the LED bar-graph, or the 8×8 LED matrix display. The MAX7219 could easily be daisy-chained (cascaded) to another MAX7219 chip using the DOUT pin which is useful when you want to drive 16-Digits LED display or several LED matrix display.
Read more: Build your own stopwatch using Maxim MAX7219 Serially Interfaced, 8-Digit LED Display Drivers