每次在第一次“.(1)”循环之后打开代码(pic12f1572)时,我都会遇到一个奇怪的问题,代码会自动重置并重新开始。这是代码:如果有人遇到过这样的问题,请AdveBrr,丹尼尔
以上来自于百度翻译
以下为原文
i have a strange problem every
time i turn on the code (pic12f1572) after the first "while (1)" loop the code reset itself and starts all over again. this is the code :
void main(void) {
// initialize the device
SYSTEM_Initialize();
int first_delay;
// When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
// Use the following macros to:
// Enable the Global Interrupts
INTERRUPT_GlobalInterruptEnable();
// Enable the Peripheral Interrupts
INTERRUPT_PeripheralInterruptEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
PI_DAT_SetHigh();
__delay_ms(100);
PI_DAT_SetLow();
__delay_ms(100);
do{
while (1){
PIR2bits.C1IF = 0;
INTCONbits.IOCIE = 0;
//first start delay
first_delay = 0;
TMR1_Initialize();
SD_SetHigh();
while (first_delay <= 5){
if (TMR1IF){
first_delay++;
TMR1_Initialize();
}
}
//watch dog
INTCONbits.IOCIF = 0;
IOCAF3 = 0;
INTCONbits.IOCIE = 1;
tictimer = 0;
TMR1_Initialize();
//start of WD
for (int w=0;w<3;w++){
PI_DAT_SetHigh();
__delay_ms(100);
PI_DAT_SetLow();
__delay_ms(100);
}
while (tictimer < 10){
//volt_sampling();
if (TMR1IF){
tictimer++;
TMR1_Initialize();
}
if (WD>=10){
INTCONbits.IOCIE = 0;
WD=0;
//test
volt_sampling();
INTCONbits.IOCIE = 1;
}
}
SD_SetLow();
__delay_ms (4000);
SD_SetHigh();
}
} while (1);
}
if any one have encountered this kind of problem please advice
BR,
daniel