找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 6566|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

picc18應(yīng)用筆記:在源程序中設(shè)置配置位

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:26661 發(fā)表于 2010-11-2 16:07 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
對(duì)于HI-TECH C18 , 配置字的設(shè)定通過宏 __CONFIG(n,x)來(lái)實(shí)現(xiàn).
宏__CONFIG(n,x)的聲明在文件pic18.h中,各位元的聲明在對(duì)應(yīng)芯片型號(hào)的頭文件中.18F452的例程如下:

//***************************************************************************************
        #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
}
//*************************************************************************

在pic18.h中,__CONFIG(n,x)的聲明如下         
#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))
部分在pic18.h中的聲明大體如下,具體請(qǐng)參考對(duì)應(yīng)的頭文件。
// Configuration bit values
// Config. Register 1
#define OSCSEN                0xDFFF                // enable oscillator system clock
#define OSCSDIS                0xFFFF
// oscilator types
#define RCRA6                0xFFFF                // RC w/OSC2 config as RA6
#define HSPLL                0xFEFF                // HS w/PLL Enabled, Clk Freq = 4xFreq Osc.
#define ECRA6                0xFDFF                // EC w/OSC2 config. as RA6
#define ECDB4                0xFCFF                // EC w/OSC2 as divide by 4 clock output
#define RC                0xFBFF
#define HS                0xFAFF
#define XT                0xF9FF                 
#define LP                        0xF8FF

// Config. Register 2
// Brown Out reset
#define        BOREN                0xFFFF                // Brown-out reset enable

n代表 Config. Register n, 例如__CONFIG(1,x); 1 代表Config. Register 1, X可為OSCSEN,RC等。

評(píng)分

參與人數(shù) 1黑幣 +15 收起 理由
guangshi_wq + 15 很給力!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表