MPLab X 配置字的設定

來源:互聯網
上載者:User

近來突然想起自己還學過PIC,正好上午閑來無事,突然有點時間,打算重溫一下!正好MicroChip發布了新的MPLab X IDE開發環境,傳說還獲過什麼創新大獎,但是很不幸被硬體工程師狠狠的吐過槽,垃圾之類的話語都算是表揚。自己試試吧。

安裝、開啟,介面很炫

開啟之後,也很炫

建立項目出現問題

不能從開始頁建立工程,什麼原因,我也不知道,反正是不行

從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的版本不同,常量定義有所不同,準備動手之前做好功課,不然……,就這麼點小問題,困擾了我一上午,記下來,警示+備忘。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.