' ' eBASIC interrupt example ' ' This program illustrates how to code a user interrupt ' handler. In this example, we are capturing the TMR0 ' overflow interrupt. TMR0 is set to overflow every 1 ms ' in the eBASIC startup code. We captuer the interrupt ' and increment our tick counter to implement a crude ' real-time clock. Meanwhile, we are incrementing a ' foreground counter and displaying it's results, just for fun. ' ' Note that both the foreground and background routines use the ' 16-bit math operations. The math library is reentrant. ' ' See the PIC 16F877 data sheet for more info ' ' Copyright(c) 2004, Compubotics LLC ' Use freely for non-commercial purposes. ' www.compubotics.com #include "rc40.inc" #interrupt intHandler rtcCounter var word forecounter var word ' define some handy bit variables that we need #bit T0IF,INTCON,2 #bit T0IE,INTCON,5 #bit GIE,INTCON,7 Main: ' enable timer 0 interrupt T0IE = 1 ' global interrupt enable GIE = 1 ' loop here forever while (1) ' increment the foreground counter forecounter = forecounter + 1 ' display the counters every 100th tick of the foreground counter if (forecounter // 100) = 0 then debug dec forecounter,":", DEC rtcCounter, cr endif wend end ' ------------------------- ' interrupt handler routine ' ------------------------- intHandler: ' handle TMR0 interrupt if (T0IF) then ' increment our RTC rtcCounter = rtcCounter + 1 ' MUST RESET TMR0 INTERRUPT FLAG!!! T0IF = 0 endif return