0

我已经通过 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 到期。

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

4

4 回答 4

1

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

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

它应该是

#pragma config WDTEN = OFF

查看数据表的第 60 页

于 2017-05-16T16:52:46.767 回答
0

Proteus这个仿真工具不是microchip(芯片制造商)官方提供的,有时候盗版软件也会出问题,你可以试试双击Proteus中的微控制器,把配置字改成你真正想要的. 我建议你在物理微控制器上测试代码。

于 2021-06-30T05:07:01.730 回答
0

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

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

于 2017-06-07T20:26:45.437 回答
0

尝试

__CONFIG(_WDT_OFF & _PWRTE_ON)

而不是使用#pragma config

于 2017-05-11T07:15:03.437 回答