jlyuan 发表于 2022-8-7 12:13

PIC16F1933在MPLAB X IDE的调试问题

本帖最后由 pzsh 于 2022-8-15 16:46 编辑

每次在进入debug模式时,都会弹出提示框,提示需要打开看门狗,点击YSE后就可以进入debug,点击NO就退出了,这是为什么?

jlyuan 发表于 2022-8-7 12:16


zhaoxqi 发表于 2022-8-7 12:16


还有什么现象?能再详细描述下吗?

jlyuan 发表于 2022-8-7 12:19

写了一个简单的IO口翻转功能,高低电平的持续时间是一样的,但是运行结果出现了非常大的差异:
在debug模式下运行,IO的波形高低时间一样,波形如下图:

jlyuan 发表于 2022-8-7 12:36


jlyuan 发表于 2022-8-7 12:39

当把程序通过烧录器下载后,再运行时,IO的波形高低电平时间不一样了,波形如下图:

dengdc 发表于 2022-8-7 12:42


楼主程序可以公开吗?贴程序看下吧,这么说看不出什么原因

jlyuan 发表于 2022-8-7 12:44

附上代码:
#include "pic.h"
__CONFIG(0x3FE4);
__CONFIG(0x0FFF);

void System_Init(void)//系统初始化
{
      PORTA = 0x00;//A口清零
      PORTB = 0x00;//B口清零
      TRISA = 0x00;//A口设置输出
      ANSELA = 0x00;//数字
      TRISB = 0x00;//B口设置输出
      ANSELB = 0x00;//数字
      WPUB = 0x00;//禁止弱上拉
       PORTC = 0x00;//C口清零
      TRISC = 0x00;//C口数字
      INTE = 0;//禁止INT外部中断
      IOCIE = 0;//禁止电平变化中断
}
void Delay_1ms(unsigned int t)
{
      unsigned int i,j;
      for(i = 0;i < t;i ++)
                for(j = 0;j < 11;j ++);
}
main()
{
      System_Init();//系统初始化
      while(1)
      {
                RC1 = 0;
                Delay_1ms(1000);
                RC1 = 1;
                Delay_1ms(1000);      
      }
}

问题:为什么一样的代码,在debug运行和下载运行结果差异那么大?

jlyuan 发表于 2022-8-7 12:46

配置字的配置有没有问题?

supernan 发表于 2022-8-7 12:50

你理解错误,其实是调试模式不允许使能WDT

jlyuan 发表于 2022-8-7 12:54

可是配置字里已经关闭了看门狗呀

jlyuan 发表于 2022-8-7 12:56

非常感谢你的提醒,让我突然想到配置字的问题。各种尝试之后,我发现配置字的写法好像有影响:
1.直接在程序中写配置字寄存器
__CONFIG(0x3FE4);
__CONFIG(0x0FFF);
2.通过IDE的Configuration Bits配置生成的配置代码:
//CONFIG1
#pragma config FOSC = INTOSC    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = ON       // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON       // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF      // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF       // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)

// CONFIG2
#pragma config WRT = OFF      // Flash Memory Self-Write Protection (Write protection off)
#pragma config VCAPEN = OFF   // Voltage Regulator Capacitor Enable (All VCAP pin functionality is disabled)
#pragma config PLLEN = ON       // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO      // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF      // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)

这两种的运行结果不一样,感觉好像第一种的写法没有写进去,这种写法是正确的吗?

heweibig 发表于 2022-8-7 13:00

第一种写法,是PICC用的,XC8是用第二种。

jlyuan 发表于 2022-8-7 13:02

你的两种写法配置是不一样的。

llljh 发表于 2022-8-7 13:04

第二种写法它的配置字的值是 0FFC和3FFF.

dengdc 发表于 2022-8-7 13:07

你仔细看看你第二种配置写法,看门狗分明是打开的

jlyuan 发表于 2022-8-7 13:09

找到问题是,是因为我用的XC8编译器,第一种写法是PICC下的写法,所以没写进去

jlyuan 发表于 2022-8-7 13:12


嗯,预料中的结果,多谢大家啦

ynwa 发表于 2022-8-8 11:17

你理解反了,是你设置了看门狗使能,调试要求关闭看门狗。你点了YES,是帮你把看门狗给关了。

jiekou001 发表于 2022-8-8 22:43

不是提示你了吗,看门狗使能了,没法实现这部分功能的调试。
页: [1] 2
查看完整版本: PIC16F1933在MPLAB X IDE的调试问题