Henrik and Tabsoft, thanks a lot for your helpful comments and suggestions.
I had tried the codes for both TMR0 and TMR1 as given by Darrel. But none of them worked as expected when I used 16F88. The mistake I made is that I assumed the default oscillator frequency of 16F88 to be 4MHz; it's actually 31.25KHz. I have solved my problem by merely adding the line shown below in the beginning of the code for 16F88.
OSCCON = %01101110 'Bits 6,5,4: 110 = Internal osc is set to 4MHz.
I have merely copied the code from Darrel's test program for DT_INTS-14 Version 1.1 and there is nothing wrong with the Option_Reg settings for TMR0. What I have added are a few lines specific to the PIC used. With both TMR0 and TMR1, the LED blinks at about 1Hz. The links are given below.
http://www.dt-ints.com/DT_INTS-14/blinky.html
http://www.dt-ints.com/DT_INTS-14/combine.html
Tabsoft, special thanks to you for taking the time for doing all the calculations and suggesting changes in the code. I made the changes as suggested by you for TMR0 (1:32 Prescaler and Toggle the LED if the count >= 61). The LED blinks but at 0.5Hz (1 second On, 1 second Off). So I changed the prescaler to 1:16 and now the LED blinks at 1Hz.
The updated code that uses TMR0 in 16F88 is shown below.
Regards,
Bala
'************************************************* ***************
' DT_Ints-14-16F88-TMR0 Int Test.pbp Date: 24-Mar-15 No. of words: 278
'
' This code is a demo of Instant Interrupts by Darrel Taylor.
' An LED is connected to PortB.2 through a 1K resistor. Using TMR0 interrupt,
' the LED is made to blink at a constant rate, irrespective of what the main
' code is executing.
'
'Result: Works perfectly.
'************************************************* ***************
'PIC Used: 16F88
;---------------------------------------------------------------------------
;wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
wsave VAR BYTE $70 SYSTEM ' alternate save location for W
' if using $70, comment wsave1-3
' --- IF any of these three lines cause an error ?? ------------------------
' Comment them out to fix the problem ----
' -- Which variables are needed, depends on the Chip you are using --
;wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
;wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
;wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
' --------------------------------------------------------------------------
LED2 VAR PORTB.2
DEFINE OSC 4
OSCCON = %01101110 'Bits 6,5,4: 110 = Internal osc is set to 4MHz.
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
asm
__CONFIG _CONFIG1, _FOSC_INTOSCIO & _MCLRE_ON & _WDTE_ON & _PWRTE_ON & _LVP_OFF & _CPD_OFF & _BODEN_ON & _CCPMX_RB0 & _FCMEN_ON & _IESO_ON & _DEBUG_OFF & _WRT_OFF
endasm
TRISA = 0
TRISB = 0
CMCON = 7 'Disable comparator
ANSEL = 0 'All I/O pins are digital
ADCON0.0 = 0 'Switch off ADC
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR0_INT, _ToggleLED2, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone
@ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
Main:
PAUSE 1
GOTO Main
'---[TMR0 - interrupt handler]--------------------------------------------------
T0Count VAR WORD
ToggleLED2:
T0Count = T0Count + 1
IF T0Count = 512 THEN T0Count = 0 : TOGGLE LED2
@ INT_RETURN
Bookmarks