ATMega16 AVR Microcontroller Seven Segment Digital Clock

The ATMega16 Seven Segment Digital Clock

In this ATMega16 AVR project we will be designing and implementing a digital clock with the aid of a Atmel AVR ATMega16 microcontroller and Seven Segment Displays. As such before going through this digital clock AVR project it is recommended to complete the tutorial on Interfacing a Seven Segment Display with the AVR Microcontroller.
Note: Although this AVR project was designed around the ATMega16 the project could have utilized another microcontroller such as an ATMega32, ATMega8515, etc.
ATMega16 Digital Clock Operation
Our digital clock operates as follows. When the circuit is powered up the clock starts at “00:00:00” for “HH:MM:SS”. There are two push-button switches used to set the time. Switch SW1 is for setting the minutes, when this button is pressed the minutes in increase until it reaches 59 then reset and start counting from 0. Switch SW2 is for setting the hours.

ATMega16 Digital Clock Hardware Description

The figure below gives the circuit diagram for the ATmega16 Seven Segment Display Digital Clock. One feature to note in that all seven segment displays are driven by the same port (PortB). The microcontroller through controls from PortC indicate which seven segment display each digit is displayed on. Note that these Seven Segment Displays are common cathode display.
ATMega16 AVR Microcontroller Seven Segment Digital Clock
Important Note: In order for our digital clock to work correctly the internal oscillator of the ATMega16 AVR microcontroller must be enabled and set to 4MHz.

ATMega16 Digital Clock Software

Below is the AVR C implementation of the entire code for the ATMega16 based digital clock. The code was implemented and built using AVR Studio 5. Be reminded that the internal clock of the ATMega16 microcontroller should be enabled and programmed to operate at 4MHz for the AVR C code to operate correctly. A video of the digital clock in operation is presented at the end of this page.
Please see the Interfacing a Seven Segment Display with the AVR Microcontroller tutorial for more information on the seven segment display.

Below is the AVR C code for the ATMega16 Based Digital Clock. This code was written
in AVR Studio 5.
/* * DigitalClock.c * Written in AVR Studio 5 * Compiler: AVR GNU C Compiler (GCC) * * Created: 12/10/2011 1:17:19 PM * Author: AVR Tutorials * Website: */ #define F_CPU 4000000UL #include #include #include #define SegDataPort #define SegDataPin #define SegDataDDR #define SegCntrlPort #define SegCntrlPin #define SegCntrlDDR /*Global unsigned unsigned unsigned


Variables Declarations*/ char hours = 0; char minutes = 0; char seconds = 0;

/*Function Declarations*/ /********************************************************************* ********/ /*Decimal Digit (0-9) to Seven Segment Values Encoder*/ unsigned char DigitTo7SegEncoder(unsigned char digit, unsigned char common); /*Timer Counter 1 Compare Match A Interrupt Service Routine/Interrupt Handler*/ ISR(TIMER1_COMPA_vect); /*Main Program*/ /********************************************************************* ********/ int main(void) { SegDataDDR = 0xFF; SegCntrlDDR = 0x3F; SegCntrlPort = 0xFF; TCCR1B = (1

For more detail: ATMega16 AVR Microcontroller Seven Segment Digital Clock

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top