新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PIC單片機(jī) 配置位如何寫 (MPLAB X集成開發(fā)環(huán)境,XC編譯器)

        PIC單片機(jī) 配置位如何寫 (MPLAB X集成開發(fā)環(huán)境,XC編譯器)

        作者: 時(shí)間:2016-11-13 來源:網(wǎng)絡(luò) 收藏
        最近剛接觸MPLABX集成開發(fā)環(huán)境,X16和X8編譯器,和以前的PIC的開發(fā)環(huán)境有了很大的區(qū)別,這里就說一下新建工程的第一步,配置位的編寫。
        1:MPALB X IDE用戶指南里面例子的配置位寫法:
        2:根據(jù)MPALB X IDE用戶指南里面的描述,可以自動(dòng)生成配置位的代碼
        3:根據(jù)MPALB X IDE用戶指南,說明配置位的編寫是和編譯器相關(guān)的,因此我們看編譯器的說明文檔
        4:根據(jù)X8編譯器的說明文檔,看編譯器安裝目錄下的文檔說明
        5:下面就是編譯器安裝目錄下的文檔說明

        16F877A Support Information

        #pragma config Usage

        #pragma config =

        For example:
        // Brown-out Reset Enable bit: BOR disabled
        // Data EEPROM Memory Code Protection bit: Data EEPROM code protection off
        // In-Circuit Debugger Mode bit: In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
        // Flash Program Memory Write Enable bits: Write protection off; all program memory may be written to by EECON control
        // Oscillator Selection bits: XT oscillator
        // Watchdog Timer Enable bit: WDT disabled
        // Flash Program Memory Code Protection bit: Code protection off
        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit: RB3 is digital I/O, HV on MCLR must be used for programming
        // Power-up Timer Enable bit: PWRT disabled
        #pragma config BOREN = OFF, CPD = OFF, DEBUG = OFF, WRT = OFF, FOSC = XT, WDTE = OFF, CP = OFF, LVP = OFF, PWRTE = OFF

        #pragma config =

        For example:
        // Brown-out Reset Enable bit: BOR disabled
        // Data EEPROM Memory Code Protection bit: Data EEPROM code protection off
        // In-Circuit Debugger Mode bit: In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
        // Flash Program Memory Write Enable bits: Write protection off; all program memory may be written to by EECON control
        // Oscillator Selection bits: XT oscillator
        // Watchdog Timer Enable bit: WDT disabled
        // Flash Program Memory Code Protection bit: Code protection off
        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit: RB3 is digital I/O, HV on MCLR must be used for programming
        // Power-up Timer Enable bit: PWRT disabled
        #pragma config BOREN = 0x0, CPD = 0x1, DEBUG = 0x1, WRT = 0x3, FOSC = 0x1, WDTE = 0x0, CP = 0x1, LVP = 0x0, PWRTE = 0x1

        #pragma config =

        For example:
        // Brown-out Reset Enable bit: BOR disabled
        // Data EEPROM Memory Code Protection bit: Data EEPROM code protection off
        // In-Circuit Debugger Mode bit: In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
        // Flash Program Memory Write Enable bits: Write protection off; all program memory may be written to by EECON control
        // Oscillator Selection bits: XT oscillator
        // Watchdog Timer Enable bit: WDT disabled
        // Flash Program Memory Code Protection bit: Code protection off
        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit: RB3 is digital I/O, HV on MCLR must be used for programming
        // Power-up Timer Enable bit: PWRT disabled
        #pragma config CONFIG = 0xFF39

        For example:
        // IDLOC @ 0x2000
        #pragma config IDLOC0 = 0x3FFF

        #pragma config Settings

        Register: CONFIG @ 0x2007

        BOREN =Brown-out Reset Enable bit
        OFFBOR disabled
        ONBOR enabled
        CPD =Data EEPROM Memory Code Protection bit
        OFFData EEPROM code protection off
        ONData EEPROM code-protected
        DEBUG =In-Circuit Debugger Mode bit
        OFFIn-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
        ONIn-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
        WRT =Flash Program Memory Write Enable bits
        OFFWrite protection off; all program memory may be written to by EECON control
        HALF0000h to 0FFFh write-protected; 1000h to 1FFFh may be written to by EECON control
        1FOURTH0000h to 07FFh write-protected; 0800h to 1FFFh may be written to by EECON control
        2560000h to 00FFh write-protected; 0100h to 1FFFh may be written to by EECON control
        FOSC =Oscillator Selection bits
        XTXT oscillator
        LPLP oscillator
        EXTRCRC oscillator
        HSHS oscillator
        WDTE =Watchdog Timer Enable bit
        OFFWDT disabled
        ONWDT enabled
        CP =Flash Program Memory Code Protection bit
        OFFCode protection off
        ONAll program memory code-protected
        LVP =Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit
        OFFRB3 is digital I/O, HV on MCLR must be used for programming
        ONRB3/PGM pin has PGM function; low-voltage programming enabled
        PWRTE =Power-up Timer Enable bit
        OFFPWRT disabled
        ONPWRT enabled

        Register: IDLOC0 @ 0x2000

        Register: IDLOC1 @ 0x2001

        Register: IDLOC2 @ 0x2002

        Register: IDLOC3 @ 0x2003

        配置位的大概說明:
        總結(jié):我們可以根據(jù)編譯器的文檔說明來自己編寫配置位,也可以使用IDE來自動(dòng)生成。推薦使用自動(dòng)生成的配置位代碼。


        關(guān)鍵詞: PIC單片機(jī)配置

        評(píng)論


        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 武胜县| 嘉鱼县| 赞皇县| 阳信县| 枣阳市| 津南区| 潮州市| 福海县| 依安县| 永德县| 灵丘县| 宁波市| 墨竹工卡县| 虹口区| 瑞昌市| 海宁市| 隆化县| 镇江市| 宣化县| 比如县| 石门县| 广丰县| 滦南县| 孝感市| 凌源市| 龙州县| 包头市| 桑日县| 奉化市| 若尔盖县| 武功县| 安图县| 广宁县| 凉城县| 公安县| 平武县| 蒙自县| 东光县| 依兰县| 鸡西市| 图们市|