MPLab X 配置字的设置

近来突然想起自己还学过PIC,正好上午闲来无事,突然有点时间,打算重温一下!正好MicroChip发布了新的MPLab X IDE开发环境,传说还获过什么创新大奖,但是很不幸被硬件工程师狠狠的吐过槽,垃圾之类的话语都算是表扬。自己试试吧。

安装、打开,界面很炫

image

打开之后,也很炫

image

建立项目出现问题

不能从开始页建立工程,什么原因,我也不知道,反正是不行

从File建立一个Test工程

输入代码:

#include <pic.h>
__CONFIG(XT&WDTDIS&LVPDIS);
//定义配置字,晶振类型:XT,关闭开门狗,禁止低电压编程

void main()
{
    TRISC=0x00;
    PORTC=0xF0;
    while(1)
    {
        
    }
}

编译,问题来了。

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `G:/MpLab/Test.X'
make  -f nbproject/Makefile-default.mk dist/default/production/Test.X.production.hex
make[2]: Entering directory `G:/MpLab/Test.X'
"D:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe"  -odist/default/production/Test.X.production.cof  -mdist/default/production/Test.X.production.map --summary=default,-psect,-class,+mem,-hex --chip=16F877 -P --runtime=default,+clear,+init,-keep,+osccal,-resetbits,-download,-stackcall,+clib --summary=default,-psect,-class,+mem,-hex --opt=default,+asm,-asmfile,-speed,+space,-debug,9 -N31 --warn=0  --double=24 --float=24 --addrqual=ignore --mode=lite --output=default,-inhx032 -g --asmlist "--errformat=%%f:%%l: error: %%s" "--msgformat=%%f:%%l: advisory: %%s" "--warnformat=%%f:%%l warning: %%s" build/default/production/newmain.p1 
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.83
Copyright (C) 2011 Microchip Technology Inc.
Serial number: HCPICP-123456 (PRO)
make[2]: *** [dist/default/production/Test.X.production.hex] Error 1
C:\Users\��\AppData\Local\Temp\s4bo.:45: error: undefined symbol "LVPDIS"
C:\Users\��\AppData\Local\Temp\s4bo.:45: error: undefined symbol "WDTDIS"
C:\Users\��\AppData\Local\Temp\s4bo.:45: error: undefined symbol "XT"
make[2]: Leaving directory `G:/MpLab/Test.X'
make[1]: Leaving directory `G:/MpLab/Test.X'
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)

总之是失败!还两个错误!!!

难道水平降低了?就这么几行,这可是原来运行正确的代码,不可能出错的。

排错吧,未定义的常量

error: undefined symbol "LVPDIS"
error: undefined symbol "WDTDIS"
undefined symbol "XT"

打开,Hi Tech的文件夹,找到pic.h文件和pic16f877.h文件查看。

发现常量定义变了

// Config Register: CONFIG
#define CONFIG               0x2007
// Oscillator Selection bits
// RC oscillator
#define FOSC_EXTRC           0xFFFF
// HS oscillator
#define FOSC_HS              0xFFFE
// XT oscillator
#define FOSC_XT              0xFFFD
// LP oscillator
#define FOSC_LP              0xFFFC
// 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
// FLASH Program Memory Code Protection bits
// Code protection off
#define CP_OFF               0xFFFF
// 1F00h to 1FFFh code protected
#define CP_UPPER_256         0xEFEF
// 1000h to 1FFFh code protected
#define CP_HALF              0xDFDF
// 0000h to 1FFFh code protected
#define CP_All               0xCFCF
// Brown-out Reset Enable bit
// BOR enabled
#define BOREN_ON             0xFFFF
// BOR disabled
#define BOREN_OFF            0xFFBF
// Low Voltage 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
// Data EE Memory Code Protection
// Code Protection off

一点示例

原代码改成

#include <pic.h>

__CONFIG(FOSC_XT&WDTE_OFF&LVP_OFF); 
//定义配置字,晶振类型:XT,关闭开门狗,禁止低电压编程

void main()
{
    TRISC=0x00;
    PORTC=0xF0;
    while(1)
    {
        
    }
}
编译通过,不错。

后来终于发现PICC的版本不同,常量定义有所不同,准备动手之前做好功课,不然……,就这么点小问题,困扰了我一上午,记下来,警示+备忘。

原文地址:https://www.cnblogs.com/wangluojisuan/p/2826270.html