You are on page 1of 9

DIGITAL CLOCK

Sushant Kumar Singh(EE-II) Md Shadab Azam(ECE-II) Vivek Vihar(ECE-II)

DIGITAL CLOCK
Project : To design a real time digital clock using microcontroller
Atmega 16 Components Used : 1) Atmega 16 2) Transistor TL187 3) Resistor 220 ohm & 1k 4) Red LED 5) Push Button Atmega 16 Digital Clock Operation : Our digital clocks operates as follows. When the circuit is powered up the clock starts at 00 : 00 for HH : MM. There are 3 push button switches used to set the time. Switch 1 is for pausing the time. Switch 2 is for setting the minutes when this button is pressed minutes increase until it reaches 59 then reset and start counting from 0. Switch 3 is for setting hours when this button is pressed hours increase until it reaches 23 then reset and start counting from 0. Hardware Description for the Atmega 16 Digital Clock : The figure below shows the circuit diagram for the Atmega 16 Digital Clock. One feature to note in that all displays are driven by the same port (PORT B). The microcontroller though controls from PORT C. Note that all these displays are Common Anode displays.

Software source code :


#include <avr/io.h> #include <avr/interrupt.h> #include <compat/deprecated.h> unsigned int timercount=0; unsigned int data= 0; unsigned int seconds= 0; unsigned int minute= 0; unsigned int hour= 0;

unsigned int anode= 0; unsigned int anodeflag= 0; unsigned int m2= 0; unsigned int m1= 0; unsigned int h1= 0; unsigned int h2= 0; unsigned int flag=0; unsigned int slowmin=0; unsigned int slowhour=0; unsigned int slowsec=0; void Port_init() { DDRB=0xF0; DDRC=0xFF; //PORT C as output PORT } //Time peirod 1 second ;prescale 64 void timer0_init() { TCCR0=0x00; TCNT0=0x00; TCCR0=0x03; TIMSK=0x01; } SIGNAL(SIG_OVERFLOW0) //timer interupt ISR { if(anode >2) //Stop //Load count //clkI/O/64 (From prescaler)

{ anodeflag++; anode=0; } if(timercount >900) { if(flag==0) { seconds++; slowsec=1; } timercount=0; } if(timercount > 500) { slowsec=0; } if(slowsec==1) { sbi(PORTC,7); } else { cbi(PORTC,7); } anode++;

timercount++; } ISR(INT2_vect) { flag=~flag; } void init_devices(void) { Port_init(); timer0_init(); GICR = 0x20; // interrupt enable register sei(); } void Display(int a) { switch (a) { case 0:PORTC=0x40; break; case 1:PORTC=0x79 ;break; case 2:PORTC=0x24 ;break; case 3:PORTC=0x30 ;break; case 4:PORTC=0x19 ;break; case 5:PORTC=0x12 ;break; case 6:PORTC=0x02 ;break; case 7:PORTC=0x78 ;break; case 8:PORTC=0x00 ;break;

case 9:PORTC=0x10 ;break; default: PORTC=0xFF; break; } } int main(void) { init_devices(); while(1) { if(seconds>59) { seconds=0; minute++; } if(minute>59) { minute=0; hour++; } if(hour>23) { hour=0; } switch (anodeflag) { case 0:

m1= minute%10; PORTB=0x10; Display(m1); break; case 1: m2=minute/10; PORTB=0x20; Display(m2); break; case 2: PORTB=0x40; h1= hour%10; Display(h1); break; case 3: PORTB=0x80; h2=hour/10; Display(h2); break; default: PORTC=0xff; anodeflag=0; break; } if(flag!=0) {

if(bit_is_set(PINB,0) && slowmin==1) { minute++; slowmin=0; } else if(bit_is_clear(PINB,0)) { slowmin=1; } if(bit_is_set(PINB,1) && slowhour==1) { hour++; slowhour=0; } else if(bit_is_clear(PINB,1)) { slowhour=1; } } } } ACKNOWLEDGMENT: This project is made under the sincere guidance of seniors. I would like to thanks them and Elecronics Section for helping us in this project. Without there help we wouldn't be able to make it. Thanks once again.

You might also like