''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This code example was written for the Proton Compiler'
' from Crownhill and Associates. It shows an example of'
' of Timer 0 being used in an Software Interupt routine'
' using the settings that you have made in the Pic     '
' Timer Calculator Tool.                               '
' Every time Timer 0 "rolls over" or sets its flag, the'
' program jumps to the Interrupt Service Routine and   '
' does what is required there, and then returns back to'
' the main code. This is just one of many examples of  '
' what timer 0 can be used for ! Cut and paste this    '
' example into Proton if you wish.                     '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Device 16F628A

'---------------------------------------------
'Below is the oscillator setting you chose....

XTAL =  4.0                                                                                                                                       

'--------------------------------------------- 	

ALL_DIGITAL true

'DECLARE SYMBOLS
Symbol T0IF = INTCON.2          ' TMR0 Overflow Interrupt Flag
Symbol T0IE = INTCON.5          ' TMR0 Overflow Interrupt Enable
Symbol GIE  = INTCON.7          ' Global Interrupt Enable
Symbol PS0  = OPTION_REG.0      ' Prescaler Rate Select
Symbol PS1  = OPTION_REG.1      ' Prescaler Rate Select
Symbol PS2  = OPTION_REG.2      ' Prescaler Rate Select
Symbol PSA  = OPTION_REG.3      ' Prescaler Assignment
Symbol TOCS = OPTION_REG.5

'SET REGISTERS

'Below is the prescaler setting you chose....
'---------------------------------------------------------

PS0 =  0                                                                       
PS1 =  0                                                                       
PS2 =  0                                                                       
PSA =  1                                                                       

'---------------------------------------------------------

TOCS = 0			'set the clock source for internal oscillator
T0IF = 0                        'clear the interrupt flag
T0IE = 1                        'enable tmr0 interrupt
GIE  = 1                        'enable Global interrupts

'Below is the offset setting you chose....
'----------------------------------------------------------

TMR0 = 0                                                                       

'-----------------------------------------------------------

'START PROGRAM

On Interrupt goto InterruptServiceRoutine 
'---------------------------------------------------------
'On intterupt goto ISR. 
'This occurs every  3921.56                                                    
'seconds from the settings you chose in the pic timer tool
'---------------------------------------------------------

GoTo Main                       'start of program, jumps straight to main



Disable                         'disable interrupts
InterruptServiceRoutine:

T0IF = 0                        'clear the interrupt flag

'Below is the offset setting you chose....
'----------------------------------------------------------

TMR0 = 0                                                                       

,--------------------------------------
'*************************************
'YOUR INTERUPT ROUTINE HERE I.E.
'INCREMENT A VARIABLE OR COUNTER,
'TURN ON AN OUTPUT, FLASH A LED, CHECK
'INPUTS, DO SOMETHING, ETC ETC
'*************************************

Resume                          'return back to where the main code was running
                                'before the interrupt
Enable                          're enanble interupts
          

Main:
'********************************************
'MAIN CODE - WHAT THE PROGRAM WOULD BE DOING
'NORMALLY WITHOUT BEING INTERRUPTED
'********************************************
GoTo Main