Saw this question today on the MCHP forum so I thought I would post a short example.
My first advice to anybody who has this kind of problem is to generate the code with MCC and study what it is doing in terms of order of initialization and also what it is setting in the configuration bits for the device. Even if you are planning on using ASM, do that first with your settings so you can have a working example to start with!
Here is a minimal example on the PIC16F18344 for TMR1
#pragma config WDTE = OFF // Watchdog Timer Enable bits (WDT disabled; SWDTEN is ignored)#include<xc.h>void main(void){INTCONbits.PEIE =1;// Enable peripheral interrupts
TMR1IE =1;// Enable TMR1 peripheral interrupt
T1CON =0x01;// Set the timer to prescaler 1:1 (fastest), clock source instruction clock// and pick timer2 clock in as source (not Secondary Oscillator)// we also select synchronization, no effect as we run of FOSC here.
TMR1H =0x00;
TMR1L =0x00;INTCONbits.GIE =1;// Enable GIE last, or interrupts can happen while we are setting up!while(1);// Wait forever for interruptsreturn;}void __interrupt() myISR(void){
NOP();
TMR1IF =0;// Remember to clear the IF here or we will just end up in the ISR all of the time!}
Question
Orunmila
Saw this question today on the MCHP forum so I thought I would post a short example.
My first advice to anybody who has this kind of problem is to generate the code with MCC and study what it is doing in terms of order of initialization and also what it is setting in the configuration bits for the device. Even if you are planning on using ASM, do that first with your settings so you can have a working example to start with!
Here is a minimal example on the PIC16F18344 for TMR1
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.