【问题标题】:Processor has been reset by watch dog timer (PIC16F72, XC8 compiler)处理器已被看门狗定时器复位(PIC16F72,XC8 编译器)
【发布时间】:2017-05-10 09:02:59
【问题描述】:

我已经开始通过MPLAB X IDE和XC8编译器对PIC16F72单片机进行PIC编程。下面是我的代码,编译成功。

#define _XTAL_FREQ 4000000
#include<xc.h>
#pragma config FOSC = RC // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)

char pattern[] = {0b10000001,0b11000011,0b11100111,0b11111111,0b11100111,0b11000011,0b10000001};

void write(char tab)
{
    char check;
    for(int a=0;a<8;a++)
    {
        check = ((tab >> a) & 1);
        if(check)
        {
            PORTBbits.RB7=1;
            PORTBbits.RB6=0;PORTBbits.RB6=1;
        }
        else
        {
            PORTBbits.RB7=0;
            PORTBbits.RB6=0;PORTBbits.RB6=1;
        }           
    }
}
void main(void) {

    TRISB=0x00; //Initialize as output
    PORTBbits.RB6=0;
    PORTBbits.RB5=0;
    PORTBbits.RB5=1;
    while(1)
    {
        for(int i=0;i<7;i++)
        {
            write(pattern[i]);
           __delay_ms(1000);
        }
    }

    return;
}

当我在 Proteus 中模拟我的代码时,它显示以下错误 每 2.3 秒后,处理器已被在 xxxxx 到期的看门狗定时器重置

我已经搜索过这个问题,但没有成功。我无法解决问题

【问题讨论】:

    标签: pic microchip mplab watchdog xc8


    【解决方案1】:

    你忘记了一封信。你有...

    #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
    

    应该是

    #pragma config WDTEN = OFF
    

    查看datasheet的第60页

    【讨论】:

    • 在使用 #pragma config WDTEN = OFF 编译器正在生成错误'未知配置设置/使用的寄存器'
    【解决方案2】:

    试试

    __CONFIG(_WDT_OFF & _PWRTE_ON)

    而不是使用#pragma config

    【讨论】:

    • 我使用了你所说的__CONFIG,它给出了一个错误Unknown macro (_WDT_OFF) used in __CONFIG()
    • 检查您的编译器数据表以了解他们使用了哪些宏。
    【解决方案3】:

    您可以尝试使用 MPLAB X 为您生成配置位。

    在 MPLAB X 中,单击 Window -> PIC Memory Views -> Configuration Bits。将显示新窗口,您可以在其中配置 PIC 并禁用看门狗。如果单击“Generate Source Code to Output”按钮,MPLAB 将为您在项目中使用的 PIC 生成具有正确配置位的源代码。这是官方的Microchip教程,详细描述了它-http://microchipdeveloper.com/mplabx:view-and-set-configuration-bits

    【讨论】:

      【解决方案4】:

      模拟工具Proteus不是由microchip(芯片制造商)官方提供的,有时盗版软件也会产生问题,您可以尝试的一件事是在Proteus中双击微控制器并将配置字更改为你真的想要。我建议你在物理微控制器上测试代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-18
        • 2023-03-17
        相关资源
        最近更新 更多