/****************************************************************************** * * project name: TICT Tutorial Series 1 - PART II * file name: timer2.c * initial date: 31/10/2000 * author: thomas.nussbaumer@gmx.net * description: simple clock example using an own interrupt handling routine * * build this program by typing: tigcc -O2 timer2.c * * * $Id: timer2.c,v 1.1 2000/11/01 10:44:46 Thomas Nussbaumer Exp $ * ******************************************************************************/ #define SAVE_SCREEN #include int _ti89, _ti92plus; // produce code for TI89 and TI92plus INT_HANDLER oldint5 = NULL; volatile int mseconds50 = 0; // counts in 50ms steps (not exact 50ms, but 1000/19 ms) volatile int seconds = 0; // counts seconds volatile int minutes = 0; // counts minutes volatile int hours = 0; // counts hours volatile int resettime = 1; DEFINE_INT_HANDLER (myint5handler) { //---------------------------------------------- // if resettime is not 0 all clock variables are // reset to 0 //---------------------------------------------- if (resettime) { mseconds50=seconds=minutes=hours=resettime=0; } else { mseconds50++; if (mseconds50 == 19) { mseconds50 = 0; seconds++; if (seconds == 60) { seconds = 0; minutes++; if (minutes == 60) { minutes = 0; hours++; if (hours == 24) hours = 0; } } } } ExecuteHandler(oldint5); } void _main(void) { ClrScr(); resettime = 1; oldint5 = GetIntVec(AUTO_INT_5); SetIntVec(AUTO_INT_5, myint5handler); while (!kbhit()) { if (TI89) printf_xy(50, 50, "%02d:%02d:%02d.%03d",hours,minutes,seconds,mseconds50*50); else printf_xy(70, 64, "%02d:%02d:%02d.%03d",hours,minutes,seconds,mseconds50*50); } SetIntVec(AUTO_INT_5, oldint5); GKeyFlush(); } //============================================================================= // Revision History //============================================================================= // // $Log: timer2.c,v $ // Revision 1.1 2000/11/01 10:44:46 Thomas Nussbaumer // initial version // // //