Why isn't Timer2 Interrupt firing up? - timer

I am trying to enable timer2 interrupt to use it for PWM purposes. In this case, I just turn on an LED and when timer 2 interrupt occurs I turn it off but the timer interrupt never occurs. Everything looks good to me so I don't understand why Timer2 is not firing up. I am using PIC18F87J11, here is the datasheet.
/*
File: main.c
Date: 2011-SEP-4
Target: PIC18F87J11
IDE: MPLAB 8.76
Compiler: C18 3.40
*/
#include <p18cxxx.h>
#include<usart.h>
#include <pwm.h>
#include <delays.h>
#pragma config FOSC = INTOSC, WDTEN = OFF, XINST = OFF
#pragma interrupt HighISR
void main(void) {
unsigned int i;
/* set FOSC clock to 8MHZ */
OSCCON = 0b01110000;
/* turn off 4x PLL */
OSCTUNE = 0x00;
/* make all ADC inputs digital I/O */
ANCON0 = 0xFF;
ANCON1 = 0xFF;
PR2 = 124; // Period
TMR2=0;
// 1/16 prescalar
T2CONbits.T2CKPS0 = 1;
T2CONbits.T2CKPS1 = 0;
PIE1bits.TMR2IE == 1; // Enables the TMR2 to PR2 match interrupt
// Enable Timer 2
T2CONbits.TMR2ON = 1;
INTCONbits.PEIE = 1; // Enable Perpherial Interrupt
INTCONbits.GIE = 1; // Enable Global Interrupt
TRISDbits.TRISD6 = 0; // Turn on LED
LATDbits.LATD6 = 1;
while (1);
}
#pragma code highVector=0x08
void HighVector(void) {
_asm goto HighISR _endasm
}
#pragma code /* return to default code section */
// Timer Interrupt
void HighISR(void) {
if (PIR1bits.TMR2IF == 1) {
LATDbits.LATD6 = 0; // Turn off LED to indicate it came thru
PIR1bits.TMR2IF = 0;
}
}
Thanks!

Found my mistake
PIE1bits.TMR2IE == 1;
It should be PIE1bits.TMR2IE = 1;

Related

PIC16F1829 UART RX Interrupt not working using MPLABX and XC8 compiler

I am new to writing firmware for 8-bit PICs and could use some help with my code. I am using a PIC16F1829 for an LED module which gets RX commands. I am just trying to get the basics setup like turn on LEDs when a certain value is received on RX pin, but can't even get that.
Would like to get UART working via interrupts but can't even get it working with polling in main loop. My interrupt vector is commented out in the code below.
RX pin: RC5
TX pin: RB7
Pin to toggle LEDs on and off: RA5
Pin RA5 works fine to toggle LEDs on and off. TX pin is working, though I have not confirmed if interrupt TXIF is also not working like RCIF is not working.
I have tried reading RCIF and PIR1bits.RCIF. Both of them compiled. Neither one worked. I have tried this on two different PICs on 2 different LED modules. They turn on, but reading RX pin didn't work on either.
Variable RXIN is initially defined as 3 and thus due to the RXIN-- loop within the main loop the lights flash 3 times at startup so I know it is entering the main loop. But as far as I can tell the RCIF interrupt is not firing upon reception at RX pin.
I have confirmed on oscilloscope that the signal into RX and out of TX pins using same baud, so I think baud rate is configured correctly (300 baud, 8N1.) I have also confirmed on oscilloscope RX pin receiving strong and clean 5V signal. Neither polling RCIF or using an interrupt service routing has worked thus far. If anyone can see the issues with my code that I am not seeing, your help would be greatly appreciated.
My code:
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
// This is for 300 baud rate
#define _BAUD_PRESCALER_LOW_ 0x2A
#define _BAUD_PRESCALER_HIGH_ 0x68
#define _XTAL_FREQ 32000000
#pragma config FOSC = INTOSC // Oscillator Selection->INTOSC oscillator: I/O function on CLKIN pin
#pragma config WDTE = OFF // Watchdog Timer Enable->WDT enabled
#pragma config PWRTE = OFF // Power-up Timer Enable->PWRT disabled
#pragma config MCLRE = OFF // MCLR Pin Function Select->MCLR/VPP pin function is digital input
#pragma config CP = OFF // Flash Program Memory Code Protection->Program memory code protection is disabled
#pragma config CPD = OFF // Data Memory Code Protection->Data memory code protection is disabled
#pragma config BOREN = ON // Brown-out Reset Enable->Brown-out Reset enabled
#pragma config CLKOUTEN = OFF // Clock Out Enable->CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
#pragma config IESO = OFF // Internal/External Switchover->Internal/External Switchover mode is disabled
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor is disabled
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection->Write protection off
#pragma config PLLEN = ON // PLL Enable->4x PLL enabled
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable->Stack Overflow or Underflow will cause a Reset
#pragma config BORV = LO // Brown-out Reset Voltage Selection->Brown-out Reset Voltage (Vbor), low trip point selected.
#pragma config LVP = OFF
int flagRXFramingError = 0;
int flagRXOverrunError = 0;
volatile unsigned char RXIN = 3;
unsigned char UARTRead(){
return RCREG;
}
void writeRXIN(unsigned char a){
RXIN = a;
}
void TX(unsigned char a){
while(!TXIF){}
TXREG = a;
}
int main(int argc, char** argv) {
// SCS FOSC; SPLLEN disabled; IRCF 8MHz_HF;
OSCCON = 0xF0;
// TUN 0;
OSCTUNE = 0x00;
// Set the secondary oscillator
// Wait for PLL to stabilize
while(PLLR == 0)
{
}
// WDTPS 1:65536; SWDTEN OFF;
WDTCON = 0x16;
__delay_ms(5);
GIE = 1; // Global interrupts enabled
__delay_ms(5);
PEIE = 1; // Active peripheral interrupts enabled
__delay_ms(5);
RCIE = 1; // Enable USART Receive interrupt
__delay_ms(5);
TXIE = 1; // Enable USART Transmitter interrupt
__delay_ms(5);
ADIE = 1; // Enable ADC interrupts
__delay_ms(5);
RXDTSEL = 0; // RX is on RC5 pin
__delay_ms(5);
TXCKSEL = 0; // TX is on RB7 pin
__delay_ms(5);
TRISC5 = 1; // RX pin set as input
__delay_ms(5);
SPEN = 1; // Serial Port Enabled
__delay_ms(5);
SYNC = 0; // Asynchronous mode
__delay_ms(5);
RX9 = 0; // 8 bit reception
__delay_ms(5);
TX9 = 0; // 8-bit transmission
__delay_ms(5);
CREN = 1; // Receiver enabled
__delay_ms(5);
TXEN = 1; // Transmitter enabled
__delay_ms(5);
BRG16 = 1; // 16-bit baud generation
__delay_ms(5);
BRGH = 1; // High baud rate enabled
__delay_ms(5);
ABDEN = 0; // Auto baud detect disabled
__delay_ms(5);
// Baud prescaler n = [Fosc/(D*BR)] - 1
SPBRGH = _BAUD_PRESCALER_HIGH_;
__delay_ms(5);
SPBRGL = _BAUD_PRESCALER_LOW_;
__delay_ms(5);
TRISC6 = 0; // IadjPWM pin configured as output
__delay_ms(5);
ANSC6 = 0; // IadjPWM pin not analog input
__delay_ms(5);
TRISA5 = 0; // DimPWM pin configured as output
__delay_ms(5);
LATC6 = 1; // Max current for now until PWM written
__delay_ms(5);
while(1){
// Inline assembly code to clear watchdog timer
//asm("CLRWDT");
/*if(RXIN == 5){
RA5 = 1;
}
else{
RA5 = 0;
}*/
if(PIR1bits.RCIF){
writeRXIN(UARTRead());
//RA5 = 0;
TX(RXIN);
} // end if RCIF
while(RXIN > 0){
RA5 = 1;
__delay_ms(100);
RA5 = 0;
__delay_ms(100);
RXIN--;
}
}
// infinite loop
// never leave this loop
RA5 = 1;
return (EXIT_SUCCESS);
} // end main
/*void interrupt ISR(void){
if(RCIF){// if USART Receive interrupt flag
RA5 = 1;
if(FERR){
flagRXFramingError = 1;
SPEN = 0;
SPEN = 1;
}
if(OERR){
flagRXOverrunError = 1;
CREN = 0;
CREN = 1;
}
while(RCIF){ // RCIF high as long as there is data in FIFO register. Read RCREG to clear RCIF flag
writeRXIN(UARTRead());
}
RA5 = 0;
}
if (TXIF){// if USART Transmit interrupt
TXIF = 0; // Clear interrupt flag
}
} // end ISRs*/
Some microcontrollers stop receiving bytes if there was some kind of error. Be sure to clear those errors. Usually by clearing some UART control register bits.
SOLVED THE PROBLEM
I am not sure what exactly solved the problem but I will share the major changes I made and the new code.
I had TXIE enabled. TXIF is almost always high, so it generates
continuous interrupts. I don't see a reason to enable TX interrupts,
though there may be a good one. If you want to TX wait until TXIF is
not zero and transmit, otherwise why use the flag?
I had the interrupts enabling in the wrong order. I should have
enabled the peripherals, then their individual interrupts if
necessary, then PEIE, and finally GIE.
I wasn't handling FERR and OERR in my interrupt, though they may
be firing and causing interrupts.
Also I had RXDTSEL set wrong in my original code. Here is the new, working code. Right now all it does is echo the RX signal and blink the LEDs the number of times that is transmitted.
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
// This is for 300 baud rate
#define _BAUD_PRESCALER_LOW_ 0x2A
#define _BAUD_PRESCALER_HIGH_ 0x68
#define _XTAL_FREQ 32000000
#define _PIN_DIMPWMPIN_ RA5
#pragma config FOSC = INTOSC // Oscillator Selection->INTOSC oscillator: I/O function on CLKIN pin
#pragma config WDTE = OFF // Watchdog Timer Enable->WDT enabled
#pragma config PWRTE = OFF // Power-up Timer Enable->PWRT disabled
#pragma config MCLRE = OFF // MCLR Pin Function Select->MCLR/VPP pin function is digital input
#pragma config CP = OFF // Flash Program Memory Code Protection->Program memory code protection is disabled
#pragma config CPD = OFF // Data Memory Code Protection->Data memory code protection is disabled
#pragma config BOREN = ON // Brown-out Reset Enable->Brown-out Reset enabled
#pragma config CLKOUTEN = OFF // Clock Out Enable->CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
#pragma config IESO = OFF // Internal/External Switchover->Internal/External Switchover mode is disabled
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor is disabled
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection->Write protection off
#pragma config PLLEN = ON // PLL Enable->4x PLL enabled
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable->Stack Overflow or Underflow will cause a Reset
#pragma config BORV = LO // Brown-out Reset Voltage Selection->Brown-out Reset Voltage (Vbor), low trip point selected.
#pragma config LVP = OFF
int flagRXFramingError = 0;
int flagRXOverrunError = 0;
volatile unsigned char RXIN = 3;
unsigned char RX(){
return RCREG;
}
void writeRXIN(volatile unsigned char a){
RXIN = a;
}
void TX(unsigned char a){
while(!PIR1bits.TXIF); // TXIF is usually 1, only 0 when busy transmitting
TXREG = a;
}
int main(int argc, char** argv) {
// SCS FOSC; SPLLEN disabled; IRCF 8MHz_HF;
OSCCON = 0xF0;
// TUN 0;
OSCTUNE = 0x00;
// Set the secondary oscillator
// Wait for PLL to stabilize
while(OSCSTATbits.PLLR == 0){}
ADCON0bits.ADON = 0;
ANSELA = 0x00;
ANSELB = 0x00;
ANSELC = 0x00;
PIE1bits.ADIE = 0; // Disable ADC interrupts
TRISCbits.TRISC5 = 1; // RX pin set to input
TRISCbits.TRISC6 = 0; // IadjPWM pin configured as output
TRISAbits.TRISA5 = 0; // DimPWM pin configured as output
LATCbits.LATC6 = 1; // Max current for now until PWM written
//UART Init
BAUDCONbits.BRG16 = 1; // 16-bit baud generation
TXSTAbits.BRGH = 1; // High baud rate enabled
BAUDCONbits.ABDEN = 0; // Auto baud detect disabled
// Baud prescaler n = [Fosc/(D*BR)] - 1
SPBRGH = _BAUD_PRESCALER_HIGH_;
__delay_ms(1);
SPBRGL = _BAUD_PRESCALER_LOW_;
__delay_ms(1);
APFCON0bits.RXDTSEL = 1; // RX is on RC5 pin
APFCON0bits.TXCKSEL = 0; // TX is on RB7 pin
TXSTAbits.SYNC = 0; // Asynchronous mode
RCSTAbits.SPEN = 1; // Serial Port Enabled
RCSTAbits.RX9 = 0; // 8 bit reception
TXSTAbits.TX9 = 0; // 8-bit transmission
RCSTAbits.CREN = 1; // Receiver enabled
TXSTAbits.TXEN = 1; // Transmitter enabled
PIE1bits.TXIE = 0; // Enable USART Transmitter interrupt
PIE1bits.RCIE = 1; // Enable USART Receive interrupt
while(PIR1bits.RCIF){
writeRXIN(RX());
}
INTCONbits.PEIE = 1; // Enable peripheral interrupts
INTCONbits.GIE = 1; // Enable global interrupts
while(1){
while(RXIN > 0){
TX(RXIN);
_PIN_DIMPWMPIN_ = 1;
__delay_ms(100);
_PIN_DIMPWMPIN_ = 0;
__delay_ms(100);
RXIN--;
}
}
// infinite loop
// never leave this loop
return (EXIT_SUCCESS);
} // end main
void interrupt ISR(void){
if(PIE1bits.RCIE && PIR1bits.RCIF){ // handle RX pin interrupts
while(PIR1bits.RCIF){
writeRXIN(RX());
}
if(RCSTAbits.FERR){
flagRXFramingError = 1;
SPEN = 0;
SPEN = 1;
}
if(RCSTAbits.OERR){
flagRXOverrunError = 1;
CREN = 0;
CREN = 1;
}
} // end RX pin interrupt handlers
} // end ISRs*/

Understanding code for LED light for stm32f334R8?

#include "stm32f30x_conf.h"
uint16_t read_pos(void);
void PC_Conf(void);
uint8_t get_bit(uint8_t, uint8_t);
// PROCESSORTACT = 64 MHz
// AHB Prescaler = 1
// APB1 Prescaler = 2
// APB2 Prescaler = 1
long pin = 1;
long dir = 1;
char recvd;
int main(void){
/*
*/
//Definitions
GPIO_InitTypeDef GPIO_Initstructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_NVICInitStructure;
//ENABLE CLOCK
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
//GPIO
GPIO_Initstructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_Initstructure.GPIO_OType=GPIO_OType_PP;
GPIO_Initstructure.GPIO_Pin=GPIO_Pin_All;
GPIO_Initstructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_Initstructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_Initstructure);
//TIMER
TIM_TimeBaseInitStructure.TIM_Prescaler = (64000-1); //TIM2 cycle to 1kHz
TIM_TimeBaseInitStructure.TIM_Period = 500; //Every 500ms
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);
//NVIC
NVIC_NVICInitStructure.NVIC_IRQChannel=TIM2_IRQn;
NVIC_NVICInitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_NVICInitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_NVICInitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_Init(&NVIC_NVICInitStructure);
//Enable everything
TIM_Cmd(TIM2, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
/* Infinite loop */
while (1)
{
}
}
void TIM2_IRQHandler(void)
{
GPIOB->ODR &= 0;
GPIOB->ODR ^=1<<pin;
//Pin to new value
if(dir == 1)
{
if(pin == 5)
pin=11;
else if(pin == 15)
{ pin-=1;
dir = 0;
}
else
pin+=1;
}
else
{
if(pin == 11)
pin = 5;
else if(pin == 1)
{
pin+=1;
dir = 1;
}
else
pin-=1;
}
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
}
I have trouble understanding this code. First part is okay, but I don't understand the last function.
Can someone explain me simply what is going on in the last part of this code in TIM2_IRQHandler(void)?
I am new in this, any help would be welcome.
In many interrupts you need to clear the interrupt pending flag. If you don't when you exit from the handler, the interrupt will be called again. Every interrupt is described in the Reference manual of your micro. For example SPI interrupt pending flag is cleared by writing or reading from the DR register. Another one requires that bit to be cleared by the programmer.
The rule of thumb: clear the flag as soon as you enter the interrupt.
If the interrupt can be triggered by more than one event, the programmer should check which one was the source of the exception.

with KEIL4 where the lpc2148 Interrupts or IRQs wont execute

When the timer match MR0, run the interrupt service routine At the end of the interrupt service routine. I don't return from service routine to main program. Why does my program not return from service routine?
See answer below for complete code
the code is /* Timer.h */
#include "LPC214x.h"
#include "main.h"
#define VIC_EN 5
#define VIC_TIMER0 4
#define MR0 0
void timer_init(void);
void timer_isr(void);
/* Timer.c */
volatile uint8_t flag;
void timer_init()
{
//disable and reset timer counters
T0TCR = BV(1);
//use T0 as TIMER:
T0CTCR = 0x00;
//set prescalar
T0PR = 15000000-1;
//setup MR0 for 5 sec
T0MR0 = 4; //4+1
//enable intr on MR0, reset
T0MCR |= BV(0) | BV(1);
//enable T0 intr in VIC
VICVectAddr1 = (uint32_t)timer_isr;
VICVectCntl1 = BV(VIC_TIMER0) | VIC_EN;
VICIntSelect &= ~BV(VIC_TIMER0);
VICIntEnable |= BV(VIC_TIMER0);
//enable timer counter
T0TCR = BV(0);
}
void timer_isr()
{
flag=1;
//clear intr in TIMER regrs
T0IR |= BV(0);
//clear intr in VIC
VICVectAddr = 0x00000000;
}
/* Main.c*/
int main (void)
{
int cnt=0;
char str[32];
timer_init();
lcd_init();
lcd_putstring(LCD_LINE1," *TIMER* ");
_delay_ms(1000);
str_printf(str,"Count:%d",cnt);
//lcd_putstring(LCD_LINE2,str);
while(1)
{
while(flag==0);
flag = 0;
cnt++;
str_printf(str,"Count:%d",cnt);
lcd_putstring(LCD_LINE2,str);
}
return 0;
}

Interrupt handling with 8051 C using Keil uVision

I've been doing a project about home automation in which I have to use timer interrupts with 8051 microcontroller. I've constructed the following code, however I couldn't manage to get interrupt working. It seems that the program does not go into timer ISR at all. I use a buton to simulate PIR input, therefore lampControl is triggered, no worries there. I use as a library.
Any ideas or help will be greately appreciated:
void timer0_isr(void) interrupt 1 //Timer 0 Interrupt
{
TH0 = 0xDC;
TL0 = 0x00;
TR0 = 1;
if (++lamp_interrupt_count == 6000)
{
sendCharacterShowAsHex(0x8F);
lamp_interrupt_count = 0;
TR0 = 0;
}
}
void main()
{
unsigned char chr;
IE = 0x93;
while(1)
{
serialInput();
if (getPIRInput() == 0x00)
{
lampControl(0x80);
}
....
....
....
}
void lampControl(unsigned char serial_data_in)
{
if (serial_data_in == 0x80)
{
sendCharacterShowAsHex(0x80);
//enable interrupts
IE = 0x93;
device_interrupt = 2; //Lamp
TMOD = 0x21; // Timer0 Gate=0, Mode 1, 16bit timer
TH0 = 0xDC;
TL0 = 0x00;
TR0 = 1;
}
else if(serial_data_in == 0x8F)
{
sendCharacterShowAsHex(0x8F);
}
}
You need to configure the timer and interrupts before you can use them.
In main() you need at least the following configuration bits set in order to be able to turn
the timer on with "TR0 = 1;" :
Set those bits first thing in main() and this should do the trick:
TMOD = 0x01; // 16-bit no auto reload
TH0 = 0xDC; //Set high and low bits to count 0xFFFF - 0xDC00 = 0x23FF counts
TL0 = 0x00;
ET0 = 1; // Enable timer0 interrupt
EA = 1; // Enable all interrupts
//TR0 = 1; //Enable Timer0 immediately
The rest of your code should run fine.
Note: you could change your interrupt function definition to:
"void timer0_isr(void) interrupt 1 using 1" to force it to use register bank 1 for the interrupt function operation.

How to simulate Interrupts in debug mode with PIC18?

I tried to debug timer 1 interrupt with MPLAB Simulator, but it seems like the debugger never goes to the interrupt service routine.
The settings for timer 1 seem correct to me , not sure if I missed something else. Here is the datasheet
/*
File: main.c
Date: 2011-SEP-4
Target: PIC18F87J11
IDE: MPLAB 8.76
Compiler: C18 3.40
*/
#include <p18cxxx.h>
#pragma config FOSC = INTOSC, WDTEN = OFF, XINST = OFF
#pragma code HighISR = 0x08 // high priority 0x18
#pragma interrupt HighISR
int time = 0;
void main(void) {
/* set FOSC clock to 8MHZ */
OSCCON = 0b01110000;
/* turn off 4x PLL */
OSCTUNE = 0x00;
/* make all ADC inputs digital I/O */
ANCON0 = 0xFF;
ANCON1 = 0xFF;
// 1/1 prescalar
T1CONbits.T1CKPS1 = 0;
T1CONbits.T1CKPS0 = 0;
// Use Internal Clock
T1CONbits.TMR1CS = 0;
// Timer1 overflow interrupt
PIE1bits.TMR1IE = 1;
// Enable Timer 1
T1CONbits.TMR1ON = 1;
INTCONbits.PEIE = 1; // Enable Perpherial Interrupt
INTCONbits.GIE = 1; // Enable Global Interrupt
while (1);
}
// Timer Interrupt
void HighISR(void) {
if (PIR1bits.TMR1IF == 1) {
time++;
PIR1bits.TMR1IF = 0;
}
}
Just found out what I was missing ...
#pragma code highVector=0x08
void HighVector (void)
{
_asm goto HighISR _endasm
}
#pragma code /* return to default code section */
Now the whole program looks like this
/*
File: main.c
Date: 2011-SEP-4
Target: PIC18F87J11
IDE: MPLAB 8.76
Compiler: C18 3.40
*/
#include <p18cxxx.h>
#pragma config FOSC = INTOSC, WDTEN = OFF, XINST = OFF
#pragma interrupt HighISR
int time = 0;
void main(void) {
/* set FOSC clock to 8MHZ */
OSCCON = 0b01110000;
/* turn off 4x PLL */
OSCTUNE = 0x00;
/* make all ADC inputs digital I/O */
ANCON0 = 0xFF;
ANCON1 = 0xFF;
// 1/1 prescalar
T1CONbits.T1CKPS1 = 0;
T1CONbits.T1CKPS0 = 0;
// Use Internal Clock
T1CONbits.TMR1CS = 0;
// Timer1 overflow interrupt
PIE1bits.TMR1IE = 1;
// Enable Timer 1
T1CONbits.TMR1ON = 1;
INTCONbits.PEIE = 1; // Enable Perpherial Interrupt
INTCONbits.GIE = 1; // Enable Global Interrupt
while (1);
}
#pragma code highVector=0x08
void HighVector (void)
{
_asm goto HighISR _endasm
}
#pragma code /* return to default code section */
// Timer Interrupt
void HighISR(void) {
if (PIR1bits.TMR1IF == 1) {
time++;
PIR1bits.TMR1IF = 0;
}
}

Resources