im required to make a digital clock , i made several codes using
iteration for delay which give not perfect delay. So i want to have
suggestion about how to use timer interrupts to have perfect 1 sec
delay each time. ive written code please see am i using interrupts
correctly..

#include <reg51.h> #include <stdio.h> unsigned char LED[10]=; unsigned char AMPM[2]=; long int x,sec=0,min=0,hour=0,lmin=0,hmin=0,c=0;hhour=0,lhour=0,le=0,am=0; sbit a=P3^0; sbit b=P3^1; sbit d=P3^4; sbit e=P3^7; sbit f=P3^6; void init_timer() { ET1=1; TMOD=0x20; TH1=0x6; EA=1; TR1=1; }

timer1() interrupt 3 { hmin=min/10; lmin=min%10; hhour=hour/10; lhour=hour%10; while(c<@00) { le++; c++; switch(le) { case 1: a=0; b=1; d=1; e=1; f=1; P0=~LED[hhour]; break;

case 2: a=1; b=0; d=1; e=1; f=1; P0=~LED[lhour]; break;

case 3: a=1; b=1; d=0; e=1; f=1; P0=~LED[hmin]; break;

case 4: a=1; b=1; d=1; e=0; f=1; P0=~LED[lmin]; break; case 5: a=1; b=1; d=1; e=1; f=0; P0=~AMPM[am]; le=0; break; } }c=0; sec++; if(sec=`) {sec=0; min++; } if(min=`) {min=0; hour++; }

} main() {

EA=1; am=0; le=0; sec = 0; min = 0; hour= 0; c=0; init_timer(); for(;;) {} }

#include <reg51.h> #include <stdio.h> unsigned char LED[10]=; unsigned char AMPM[2]=; long int x,sec=0,min=0,hour=0,lmin=0,hmin=0,c=0;hhour=0,lhour=0,le=0,am=0; sbit a=P3^0; sbit b=P3^1; sbit d=P3^4; sbit e=P3^7; sbit f=P3^6; void init_timer() { ET1=1; TMOD=0x20; TH1=0x6; EA=1; TR1=1; }

timer1() interrupt 3 { hmin=min/10; lmin=min%10; hhour=hour/10; lhour=hour%10; while(c<@00) { le++; c++; switch(le) { case 1: a=0; b=1; d=1; e=1; f=1; P0=~LED[hhour]; break;

case 2: a=1; b=0; d=1; e=1; f=1; P0=~LED[lhour]; break;

case 3: a=1; b=1; d=0; e=1; f=1; P0=~LED[hmin]; break;

case 4: a=1; b=1; d=1; e=0; f=1; P0=~LED[lmin]; break; case 5: a=1; b=1; d=1; e=1; f=0; P0=~AMPM[am]; le=0; break; } }c=0; sec++; if(sec=`) {sec=0; min++; } if(min=`) {min=0; hour++; }

} main() {

EA=1; am=0; le=0; sec = 0; min = 0; hour= 0; c=0; init_timer(); for(;;) {} }