/****************************************************************************** * * project name: TICT Tutorial Series 1 - PART II * file name: timer1.c * initial date: 31/10/2000 * author: thomas.nussbaumer@gmx.net * description: simple counter example using an own interrupt handling routine * * build this program by typing: tigcc -O2 timer1.c * * * $Id: timer1.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; //------------------------------------------------------------- // NOTE that variable counter is defined "volatile" !!! // // "volatile" means that the compiler shouldn't touch it in any // way for optimization reasons. // // if this variable is not defined "volatile" the compiler // may completely remove it, because it thinks it will change // during routine (the compiler doesn't know anything about // interrupts, so this may fool it). //------------------------------------------------------------- volatile int counter = 0; DEFINE_INT_HANDLER (myint5handler) { counter++; //----------------------------------------------------- // we don't want to replace the old interrupt handler // completely, but want that it will be executed at the // end of our own handler //----------------------------------------------------- ExecuteHandler(oldint5); } void _main(void) { //------------------------------------------------------- // clear screen and set counter variable to 0, otherwise // the counter would start at its last value if you start // the program again and the program is not archived! //------------------------------------------------------- ClrScr(); counter = 0; //--------------------------------------------------- // get the address of the default interrupt 5 handler // and store it in the global variable oldint5. // this is necessary so we can call this handler within // our own handler and that we can restore it at the // end of our program //--------------------------------------------------- oldint5 = GetIntVec(AUTO_INT_5); //-------------------------------------- // install now our own handler .... //-------------------------------------- SetIntVec(AUTO_INT_5, myint5handler); //------------------------------------------------------------------ // ... loop and print the counter value until a key gets pressed ... //------------------------------------------------------------------ while (!kbhit()) { if (TI89) printf_xy(50, 50, "Counter=%d ", counter); else printf_xy(70, 64, "Counter=%d ", counter); } //---------------------------------------------------------- // install the previous handler again (removing our own one) //---------------------------------------------------------- SetIntVec(AUTO_INT_5, oldint5); //------------------------------------------------------- // empty the keyboard buffer and return. // its a really good idea to empty the keyboard buffer // and this point. otherwise the pressed key will remain // in the buffer and will be handed over to the AMS. // if the pressed key is the [ENTER] key you program // would get started immediately again. //------------------------------------------------------- GKeyFlush(); } //============================================================================= // Revision History //============================================================================= // // $Log: timer1.c,v $ // Revision 1.1 2000/11/01 10:44:46 Thomas Nussbaumer // initial version // // //