3
\$\begingroup\$

IDE= MPLABx

Toolchain = HiTech PICC Lite

Target = PIC16f876

Burner = PICkit2

This is a new one for me. I have three leds connected to the chip, RC0, RC2 and RC3. RC2 pulses on at the beginning of the program (never again), RC3 pulses continuously through the infinite loop, and RC0 pulses during the interrupt. The program functions properly, as in the interrupt is executed and what not.

However, the chip is being reset. I've determined its the watchdog timer restarting the chip. I've determined this by changing the watchdog prescaler and this extends the time before the chip is reset. I thought the __option WDTE_OFF option would disable the WDT, but this does not seem to be the case.

I am also unsure as to why the WDT is triggering in the first place.

has anyone had this problem or can point me in the right direction?

My code;

#include"pic16f876.h"
#include "pic.h"
#include "htc.h"
#define XTAL_FREQ 20000000
__CONFIG (FOSC_XT, WDTE_OFF, PWRTE_ON, BOREN_OFF,
       LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF);

void setup(void);

int main(void) {
    int counter;
    int timer;
    TRISC=0x00;
    for(counter=0;counter<6000;counter++)
    RC2=1;
    setup();
    T0IF=0;
    di();
    RC2=0;
    for(;;){
       for(counter=0;counter<6000;counter++)
            RC3=0;
       for(counter=0;counter<6000;counter++)
            RC3=1;
    } 
}

void setup(void){
 //turn off all interrupts
    INTCON=0x00;
        //for TRISx, 1=input, 0=output
//setup Timer0 as real time interrupt
T0CS=0; //Timer0 set to internal clock cycle
PSA=0; //assign prescale to Timer0
OPTION_REGbits.PS=0b111; //prescale set to 1:256
T0IE=1; //allow RTI
};

void interrupt int_handler(void)
{
    int int_counter;

    if(T0IF==1){
        GIE=0;
        T0IE=0;
        RC0=1;
        for(int_counter=0;int_counter<30000;int_counter++)
        RC0=1;
        for(int_counter=0;int_counter<30000;int_counter++)
        TMR0=0x00;
        T0IE=0;
       //T0IF=0;
        return;
    }
}
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

The config commands have changed a bit over various releases of PICC.
Try your config like this:

__CONFIG (FOSC_XT & WDTE_OFF & PWRTE_ON & BOREN_OFF,
   LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);

Also, there is no need for these 3 includes:

#include"pic16f876.h"
#include "pic.h"
#include "htc.h"

Just one like this:

#include <htc.h>

will include the other 2 (look in htc.h and pic.h in to see how it works. They should be in something like: C:\Program Files\HI-TECH Software\PICC\9.83\include)
Note angle brackets, not quotes in the above include - this uses the default toolsuite include path where all these files are stored.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.