<strong>PIC16C55X</strong>7.5.1 RB0/INT INTERRUPTAn external interrupt on RB0/INT pin is edge triggered:either rising if INTEDG bit (OPTION) is set, or fallingif INTEDG bit is clear. When a valid edge appearson the RB0/INT pin, the INTF bit (INTCON) is set.This interrupt can be disabled by clearing the INTEcontrol bit (INTCON). The INTF bit must be clearedin software in the interrupt service routine beforere-enabling this interrupt. The RB0/INT interrupt canwake-up the processor from SLEEP, if the INTE bit wasset prior to going into SLEEP. The status of the GIE bitdecides whether or not the processor branches to theinterrupt vector following wake-up. See Section 7.8 fordetails on SLEEP and Figure 7-16 for timing ofwake-up from SLEEP through RB0/INT interrupt.7.5.2 TMR0 INTERRUPTAn overflow (FFh → 00h) in the TMR0 register willset the T0IF (INTCON) bit. The interrupt canbe enabled/disabled by setting/clearing T0IE(INTCON) bit. For operation of the Timer0 module,see Section 6.0.7.5.3 PORTB INTERRUPTAn input change on PORTB sets the RBIF(INTCON) bit. The interrupt can be enabled/disabledby setting/clearing the RBIE (INTCON) bit.For operation of PORTB (Section 5.2).Note:If a change on the I/O pin should occurwhen the read operation is being executed(start of the Q2 cycle), then the RBIF interruptflag may get set.FIGURE 7-13:INT PIN INTERRUPT TIMINGQ1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4OSC1CLKOUT 34INT pinINTF flag(INTCON)151Interrupt Latency2GIE bit(INTCON)INSTRUCTION FLOWPCInstructionfetchedPC PC+1 PC+1 0004h 0005hInst (PC)Inst (PC+1)—Inst (0004h)Inst (0005h)InstructionexecutedInst (PC-1)Inst (PC)Dummy CycleDummy CycleInst (0004h)Note1: INTF flag is sampled here (every Q1).2: Interrupt latency = 3-4 Tcy where Tcy = instruction cycle time.Latency is the same whether Inst (PC) is a single cycle or a 2-cycle instruction.3: CLKOUT is available only in RC oscillator mode.4: For minimum width of INT pulse, refer to AC specs.5: INTF is enabled to be set anytime during the Q4-Q1 cycles.DS40143C-page 46 Preliminary © 1998 Microchip Technology Inc.
<strong>PIC16C55X</strong>7.6 Context Saving During InterruptsDuring an interrupt, only the return PC value is savedon the stack. Typically, users may wish to save key registersduring an interrupt, e.g. W register and STATUSregister. This will have to be implemented in software.Example 7-1 stores and restores the STATUS and Wregisters. The user register, W_TEMP, must be definedin both banks and must be defined at the same offsetfrom the bank base address (i.e., W_TEMP is definedat 0x20 in Bank 0 and it must also be defined at 0xA0in Bank 1). The user register, STATUS_TEMP, must bedefined in Bank 0. The Example 7-1:• Stores the W register• Stores the STATUS register in Bank 0• Executes the ISR code• Restores the STATUS (and bank select bitregister)• Restores the W registerEXAMPLE 7-1:SAVING THE STATUS ANDW REGISTERS IN RAMMOVWF W_TEMP ;copy W to temp register,;could be in either bankSWAPF STATUS,W ;swap status to be saved into WBCF STATUS,RP0 ;change to bank 0 regardless;of current bankMOVWF STATUS_TEMP ;save status to bank 0;register:: (ISR):SWAPF STATUS_TEMP,W ;swap STATUS_TEMP register;into W, sets bank to original;stateMOVWF STATUS ;move W into STATUS registerSWAPF W_TEMP,F ;swap W_TEMPSWAPF W_TEMP,W ;swap W_TEMP into W7.7 Watchdog Timer (WDT)The watchdog timer is a free running on-chip RC oscillatorwhich does not require any external components.This RC oscillator is separate from the RC oscillator ofthe CLKIN pin. That means that the WDT will run, evenif the clock on the OSC1 and OSC2 pins of the devicehas been stopped, for example, by execution of aSLEEP instruction. During normal operation, a WDTtime-out generates a device RESET. If the device is inSLEEP mode, a WDT time-out causes the device towake-up and continue with normal operation. The WDTcan be permanently disabled by programming the configurationbit WDTE as clear (Section 7.1).7.7.1 WDT PERIODThe WDT has a nominal time-out period of 18 ms, (withno prescaler). The time-out periods vary with temperature,VDD and process variations from part to part (seeDC specs). If longer time-out periods are desired, aprescaler with a division ratio of up to 1:128 can beassigned to the WDT under software control by writingto the OPTION register. Thus, time-out periods up to2.3 seconds can be realized.The CLRWDT and SLEEP instructions clear the WDTand the postscaler, if assigned to the WDT, and preventit from timing out and generating a device RESET.The TO bit in the STATUS register will be cleared upona Watchdog Timer time-out.7.7.2 WDT PROGRAMMING CONSIDERATIONSIt should also be taken in account that under worst caseconditions (VDD = Min., Temperature = Max., max.WDT prescaler) it may take several seconds before aWDT time-out occurs.© 1998 Microchip Technology Inc. Preliminary DS40143C-page 47