/* demo80.c Install user's timer ISR. Use NewClock() to instead of clock(),because TC 2.0 BC++ 3.1 's clock() has bug. Operation: (1)5DigitLed will show the time. position 1 : day 2,3: hour (0-23) 4,5: minute(0-59) (2)Led will toggle ON/OFF every 0.5 second. (3)press 'q' to quit. */ #include #include #include #include #include"..\lib\7188.h" static unsigned long ClkTck=0L; void interrupt Isr1C(void) { ClkTck++; } unsigned long far *Vect=(unsigned long far *)0L; unsigned long Old1C; void install_1C(void) { Old1C=Vect[0x1c]; Vect[0x1c]=Isr1C; } void restore_1C(void) { Vect[0x1c]=Old1C; } unsigned long NewClock(void) { return ClkTck; } void main() { int sec=0,min=0,hour=0; int day=0,mon,year; int quit=0,c; unsigned start,end; int ledmode=1; unsigned count=0,d0=0; install_1C(); /* install new ISR */ InitLib(); start=NewClock(); /* read current TimeTicks */ LedOn(); Show5DigitLed(1,0); Show5DigitLed(2,0); Show5DigitLed(3,0); Show5DigitLed(4,0); Show5DigitLed(5,0); while(!quit) { Delay(500); ledmode=!ledmode; if(ledmode) LedOn(); else LedOff(); end=NewClock(); if((end-start)>=1092){ /* 18.2*60=1092 --> 1 minute */ start+=1092; min++; if(min==60) { min=0; hour++; if(hour==24){ hour=0; day++; Show5DigitLed(1,day%10); } Show5DigitLed(2,hour/10); Show5DigitLed(3,hour%10); } Show5DigitLed(4,min/10); Show5DigitLed(5,min%10); } if(kbhit4()) /* check user keyboard */ { c=getch4(); /* get user's key-in */ if ((c=='q')|| (c=='Q')) quit=1; /* return to ROM-DOS */ } } restore_1C(); /* restore ISR vector */ }