As soon as the Vcc supply is provided to this circuit, the clock starts from 00:00. The time is displayed on four seven segments (in common anode configuration) by using the concept of multiplexing. This is achieved by using timer interrupt (Timer0) of AT89C51 which is configured to refresh seven segments. The segments are refreshed many times in a second for simultaneous display. The clock runs with a delay of exactly one second. Timer1 has been used to produce a time delay of one second. The data pins (a–h) of all the segments are interconnected and receive signal from port P2 of the microcontroller. The control or enable pins (common anode) are connected to pins 1-4 of port P1 (P1^0 – P1^3).
The number on 4th segment (displaying the unit digit of second) is incremented once in a second as it goes from 0 to 9. The number on 3rd segment is incremented after every 10 seconds from 0 to 5. Thus seconds are displayed varying from 00 to 59. The digit on the 2nd segment changes after every 60 seconds (a minute) from 0 to 9 and so on. Thus the clock runs for an hour and after that it resets to zero again
sbit dig_ctrl_4=P1^0; //Declaring control pins of the seven segments
unsigned char dig_disp=0;
void delay() //Function to provide a time delay of approx. 1 second. using Timer 1.
void display() interrupt 1 //Function to display the number using seven segmnet multiplexing. For more details refer seven segment multiplexing.
TL0=0x36; //Reloading Timer0
dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_2 = dig_ctrl_4 = 0;
dig_ctrl_1 = 1;
dig_ctrl_2 = 1;
dig_ctrl_3 = 1;
dig_ctrl_4 = 1;
TMOD=0x11; //Intialize Timer 0
IE=0x82; // Enable Timer 0 interrupt
TR0=1; //Start Timer 0
while(1) //Start clock