版主
Joined
: 2004/4/30 10:53 最後登入時間
: 2021/11/30 18:11
From CAE, Microchip
Group:
站務管理者 註冊會員
Level : 75 HP : 744 / 1861 MP : 5367 / 111159 EXP : 45
|
Configuration 設定的範例 : [code] ;************************************************************************************ ;*CONFIG Setting for PIC16/18 * ;*This text is mainly on the method for the setting of configuration bits with both assembler&C. * ;************************************************************************************
-------------- MPASM for PIC16Fxxx ----------------------------------------------------
;******************************************************************************************* ;*1.To set CONFIG with assembler * ;*With the source code written in assembler the configuration bits can been set by micro __CONFIG * ;*The micro __CONFIG is after with the include file. * ;*******************************************************************************************
;******************************************************************************************* ;*Example 1, CONFIG set for 16F877A * ;******************************************************************************************* list p=16f877A ; list directive to define processor #include <p16f877A.inc> ; processor specific variable definitions ;************************************************************************ ;*Configuration bits * ;*The __CONFIG directive defines configuration data within the .ASM file. * ;* The labels following the directive are defined in the P16F877A.INC file. * ;*The PIC16F877A Data Sheet explains the functions of the configuration bits. * ;************************************************************************ __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
; variable definitions ;your code ;; END ˙end of program ;**********************************************************************************
------------------- MPASM for PIC18Fxxxx 舊版 -----------------------------------
;************************************************************************************** ;*Example 2, CONFIG set for 18F452. As the configuration bits is more complex than 16F877, * ;*it maps to more bytes in program memory instead of one word. * ;************************************************************************************** LIST P=18F452 ;directive to define processor #include <P18F452.INC> ;processor specific variable definitions ;**************************************************************************** ;*Configuration bits * ;*The __CONFIG directive defines configuration data within the .ASM file. * ;* The labels following the directive are defined in the P18F452.INC file. * ; *The PIC18FXX2 Data Sheet explains the functions of the configuration bits. * ;*****************************************************************************
__CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H __CONFIG _CONFIG2L, _BOR_OFF_2L & _PWRT_OFF_2L __CONFIG _CONFIG2H, _WDT_OFF_2H __CONFIG _CONFIG3H, _CCP2MX_OFF_3H __CONFIG _CONFIG4L, _STVR_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L __CONFIG _CONFIG7H, _EBTRB_OFF_7H
;****************************************************************************** ;Variable definitions ;your code ;; END; end of program ;******************************************************************************
;**************************** PIC18Fxxxx 新版使用方式 ********************************* ; * ; Files required: P18F4520.INC * ; * ;******************************************************************************
LIST P=18F4520 ;directive to define processor #include <P18F4520.INC> ;processor specific variable definitions
;****************************************************************************** ;Configuration bits ;Microchip has changed the format for defining the configuration bits, please ;see the .inc file for futher details on notation. Below are a few examples.
; Oscillator Selection: CONFIG OSC = LP ;LP ******************************************************
------------------------- Hi-Tech PICC (16Fxxxx) -------------------------------------
;******************************************************** ;*2.To set CONFIG with C language * ;********************************************************
;************************************************************************************ ;*a. Here is a example for HI-TECH PICC * ;************************************************************************************ //************************************************************************************** #include <pic.h> #include <pic168xa.h>
//*************************************************************************************** //*The declaration of __CONFIG() is in pic.h * //*The __CONFIG(x) directive defines configuration data within is in pic168xa.h * //*************************************************************************************** __CONFIG(XT&WDTDIS&PWRTEN&BORDIS&LVPDIS&DUNPROT&DEBUGDIS&UNPROTECT); void main(void) { //your code } //***************************************************************************************
//**************************************************************************** //*In pic.h the definition of __CONFIG(x) is as follows: * /*#define __CONFIG(x) asm("\tpsect config,class=CONFIG,delta=2");\ * asm("\tdw "___mkstr(x)) */ //* pic168xa.h defines all the configuation bit values * //*#define CONFIG_ADDR 0x2007
--------------------- Hi-Tech PICC18 ------------------------------------------------
**************************************************************************************** //*b.In HI-TECH C18 , use macro __CONFIG(n,x) //*************************************************************************************** #include <pic18.h> //*************************************************************************************** //*The declaration of __CONFIG(n,x) is in pic18.h * //*The __CONFIG(n,x) directive defines configuration data within is in pic18fxx2.h * //*************************************************************************************** __CONFIG(1,RC) ; __CONFIG(2,PWRTDIS & WDTPS1 & WDTEN ) ; __CONFIG(4,STVRDIS) ; void main(void) { //your code } //*************************************************************************
//************************************************************************ //*In pic18.h the definition of __CONFIG(n,x) is as follows * //*#define __CONFIG(n, x) asm("\tpsect config,class=CONFIG");\ * //* asm("global config_word" ___mkstr(n)); \ * //* asm("config_word" ___mkstr(n)":"); \ * //* asm("\torg ("___mkstr(n)"-1)*2"); \ * //* asm("\tdw "___mkstr(x)) * //* pic18fxx2.h defines the configuration bit values, * //************************************************************************
-------------------- MPLAB C18 ----------------------------------------
;******************************************************************************* ;*3.For MPLAB C18 V2.40 or higher, use #pragma config directive * ;*for example * //****************************************************************************** #include <p18f452.h> //******************************************************************************* //*Configuration settings may be specified with multiple #pragma config directives. * //*MPLAB C18 verifies that the configuration settings specified are valid for the processor* //*for which it is compiling * //*The labels following the directive "pragma config" are defined in the P18F452.h file. * //******************************************************************************* #pragma config OSC=HS #pragma config PWRT=ON #pragma config BOR=OFF, BORV=42 #pragma config WDT=OFF #pragma config CCP2MUX=ON #pragma config STVR=OFF, LVP=OFF, DEBUG=OFF #pragma config CPD=OFF void main(void) { //your code } //******************************************************************************** {/code]
發表於: 2007/8/8 17:27
|