WHAT'S NEW?
Loading...

Digital clock using Atmega 168 and 7 segment display


The digital clock that we are going to make operates at frequency 4MHz and is programmed using interrupt. It has two buttons as in wrist watches. One of toggling between the hour minute and second value and the other for changing those values.
The PORTC pins have been used as control pins which is used to select which segment will display which data. The PORTD pins have been used as segment data pins which instructs the segment which data to display.





Circuit diagram for digital clock is given below:








Code :

C code for digital clock written in WINAVR 


 

Explanation:
  • The program has been written making use of interrupt. The MCU is clocked at 1Mhz.
  • sei() enables global interrupt.
  • Pulling cs10,cs11  high sets prescaler to 64. This means that the clock counts 1Mhz/64 times ie.
  • 15625  times in 1second.
  • Pulling wgm 12 high sets CTC mode (clear timer on compare). It sets the count to 0 as the set count OCR1A is reached.
  • As OCR1A  value is reached, ISR(interrupt service routine) is called.
The program is written such that it updates the value of a global array(which contains value of hour min and seconds) every second by calling ISR. The while loop is an infinite loop which keeps on updating the value on the segment at a very high frequency(1Mhz). The while loop also contains the condition for checking for the condition of button press which takes it to two different function. One for toggling between the elements of array and the other for changing them.
Video Link:

2 comments: Leave Your Comments

  1. sir which is the 7 segment display using here??
    common anode or common cathode??

    ReplyDelete

Suggestions and Comments are welcome!