PIC单片机: 解决undefined symbol "lvpdis"/“hs"/"wdtdis"等报错

错误

  • undefined symbol "lvpdis"

  • undefined symbol “hs"

  • undefined symbol "wdtdis"

  • 报错代码

    #include <htc.h>
    #include <pic16f877a.h>
    
    __CONFIG(HS & WDTDIS & LVPDIS);
    int main(int argc, char** argv) {
        TRISD  = 0;
        PORTD  = 0b00000111;
        while(1);
        return (EXIT_SUCCESS);
    }
    

寻找头文件位置

  • 点击跳转 __CONFIG() 位配置注解

  • PICC所实现的头文件位置: C:\Program Files (x86)\HI-TECH Software\PICC\9.83\include

  • pic16f877a.h - CONFIG位

    // Config Register: CONFIG
    #define CONFIG               0x2007
    // Oscillator Selection bits
    // RC oscillator
    #define FOSC_EXTRC           0xFFFF // 直接用内部的RC时钟电路
    // HS oscillator
    #define FOSC_HS              0xFFFE // 使用超过4M的石英晶体振荡器
    // XT oscillator
    #define FOSC_XT              0xFFFD // 使用1M到4M的石英晶体振荡器
    // LP oscillator
    #define FOSC_LP              0xFFFC // 使用低于1M的陶瓷振荡器,不是什么感抗震荡
    
    /**************看门狗位*************/
    // Watchdog Timer Enable bit
    // WDT enabled
    #define WDTE_ON              0xFFFF
    // WDT disabled
    #define WDTE_OFF             0xFFFB
    
    /**********电源启动分时器启用位*******/
    // Power-up Timer Enable bit
    // PWRT disabled
    #define PWRTE_OFF            0xFFFF
    // PWRT enabled
    #define PWRTE_ON             0xFFF7
    
    // Brown-out Reset Enable bit
    // BOR enabled
    #define BOREN_ON             0xFFFF
    // BOR disabled
    #define BOREN_OFF            0xFFBF
    
    /*****低电压(单电源)在线串行编程启用位**/
    // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit
    // RB3/PGM pin has PGM function; low-voltage programming enabled
    #define LVP_ON               0xFFFF
    // RB3 is digital I/O, HV on MCLR must be used for programming
    #define LVP_OFF              0xFF7F
    
    /*******EEPROM代码保护位**************/
    // Data EEPROM Memory Code Protection bit
    // Data EEPROM code protection off
    #define CPD_OFF              0xFFFF
    // Data EEPROM code-protected
    #define CPD_ON               0xFEFF
    
    
    // Flash Program Memory Write Enable bits
    // Write protection off; all program memory may be written to by EECON control
    #define WRT_OFF              0xFFFF
    // 0000h to 00FFh write-protected; 0100h to 1FFFh may be written to by EECON control
    #define WRT_256              0xFDFF
    // 0000h to 07FFh write-protected; 0800h to 1FFFh may be written to by EECON control
    #define WRT_1FOURTH          0xFBFF
    // 0000h to 0FFFh write-protected; 1000h to 1FFFh may be written to by EECON control
    #define WRT_HALF             0xF9FF
    
    
    /************在线调试模式位*************/
    // In-Circuit Debugger Mode bit
    // In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
    #define DEBUG_OFF            0xFFFF
    // In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
    #define DEBUG_ON             0xF7FF
    
    /**************代码保护位*************/
    // Flash Program Memory Code Protection bit
    // Code protection off
    #define CP_OFF               0xFFFF 
    // All program memory code-protected
    #define CP_ON                0xDFFF
    

转换为以下代码即可

#include <htc.h> // Header file pic16f877a.h included directly. Use #include <htc.h> instead.
#include <pic16f877a.h>

/*
 * 
 */
__CONFIG(FOSC_HS & WDTE_OFF & LVP_OFF & CP_ON);

int main(int argc, char** argv) {
    TRISD  = 0;
    PORTD  = 0b00000111;
    while(1);
    return (EXIT_SUCCESS);
}
posted @ 2021-05-15 19:11  南方与南  阅读(468)  评论(0)    收藏  举报