程序在MPlab中的Pic C上意外返回其主要点 [英] Program returns to its main point unexpectedly at Pic C in MPlab

查看:118
本文介绍了程序在MPlab中的Pic C上意外返回其主要点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用MPlab IDE中的PIC16F84对步进电机进行编程.在我将其称为delay方法之后,程序将其返回为起点.更具体的说,这里有一些代码片段.

I'm programming a stepper motor with PIC16F84 in MPlab IDE. My program returns it's starting point after I call it's delay method. To be more spesific, some of code snippets here.

驱动程序的主要方法

int main(int argc, char** argv) {
TRISB = 0; // PORT B as output port
PORTB = 0x0F;

stepForward(25);
activateRelay();
waitForSeconds(3000);
deActivateRelay();
stepBackward(50);
//Since step forward method steps for 100, this will return to initial state
stepForward(25);

return (EXIT_SUCCESS);
}

前进方法

void stepForward(unsigned int stepCount){
while(0 < stepCount) {
    PORTB = 0b00000001;
    waitForSeconds(500);
    PORTB = 0b00000010;
    waitForSeconds(500);
    PORTB = 0b00000100;
    waitForSeconds(500);
    PORTB = 0b00001000;
    waitForSeconds(500);
    stepCount--;
    }
}

以及延迟系统的方法

void waitForSeconds(unsigned int miliSeconds){
    //DelayUs(miliSeconds);
    for(;miliSeconds > 0; miliSeconds--)
         for(unsigned short x = 333; x > 0 ; x--){
         }
}

在从stepForward方法调用的第二个waitFor方法之后,程序返回到main方法的TRISB = 0;部分.

After the second waitFor method called from stepForward method, program returns into TRISB = 0; part of the main method.

我是图片编程的新手,所以我的错很容易.我正在寻求帮助. 谢谢.

I'm new at pic programming, so my fault would be very easy one. I'm looking for help. Thanks.

推荐答案

如果程序计数器意外跳回0,则PIC正在复位.复位的原因很多,具体取决于PIC.一种常见的情况是看门狗超时,您似乎并没有踢看门狗,因此您是否在配置位中将其禁用?状态寄存器的第4位将告诉您看门狗是否发生超时.

If the program counter jumps back to 0 unexpectedly, the PIC is resetting. There are many causes of reset, depending on the PIC. A common one is watchdog timeout, and you don't seem to be kicking the watchdog, so have you disabled it in the config bits? Status register bit 4 will tell you if a watchdog timeout occurred.

这篇关于程序在MPlab中的Pic C上意外返回其主要点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆