picc支援下的c程式**中一定要包含pic.h標頭檔案,該檔案安裝在ht-pic\include目錄下。它是很多標頭檔案的集合,c編譯器在pic.h中根據使用者選擇的晶元自動載入相應的其它標頭檔案,例如使用者選擇的晶元是pic16f877,則pic.h會把pic1687x.h載入;例如使用者選擇的晶元是pic16f877a,則pic.h會把pic168xa.h載入。載入的標頭檔案中其實是宣告晶元的暫存器和一些函式。例如以下程式片段:
static volatile unsigned char porta@ 0x05;
static volatile unsigned char portb@ 0x06;
static unsigned char bank1 option@ 0x81;
static unsigned char bank1 trisa@0x85;
static unsigned char bank1 trisb @0x86;
@符號表示位址的意思。這些宣告和pic彙編中的定義暫存器是差不多的。
例如:
其中rb7代表portb的bit7。tmr0 equ 0x01;
pcl equ 0x02;
status equ 0x03;
/* portb bits */
static volatile bit rb7 @ (unsigned)&portb*8+7;
static volatile bit rb6 @ (unsigned)&portb*8+6;
static volatile bit rb5 @ (unsigned)&portb*8+5;
static volatile bit rb4 @ (unsigned)&portb*8+4;
static volatile bit rb3 @ (unsigned)&portb*8+3;
static volatile bit rb2 @ (unsigned)&portb*8+2;
static volatile bit rb1 @ (unsigned)&portb*8+l;
static volatile bit rb0 @ (unsigned)&portb*8+0;
我們可以模仿pic.h檔案的定義方法定義ram中檔案暫存器的方法,定義bank0的20h,21h,22h為檔案暫存器以及他們的位位址。
假設我們把
20h取名ram20h,其位位址分別是ram20h7~ram20h0
21h取名ram21h,其位位址分別是ram21h7~ram21h0
22h取名ram22h,其位位址分別是ram22h7~ram22h0
定義如下:
將這些定義加入到相應的標頭檔案中,或者直接寫在源程式中,這樣就可以直接對通過變數ram20h對bank0的20h單元進行位元組操作,可以通過ram20h7~ram20h0對bank0的20h單元進行位操作。例如:static volatile unsigned char ram20h @0x20;
static volatile unsigned char ram21h @0x21;
static volatile unsigned char ram22h @0x22;
static volatile bit ram20h7 @(unsigned)&ram20h*8+7;
static volatile bit ram20h6 @(unsigned)&ram20h*8+6;
static volatile bit ram20h5 @(unsigned)&ram20h*8+5;
static volatile bit ram20h4 @(unsigned)&ram20h*8+4;
static volatile bit ram20h3 @(unsigned)&ram20h*8+3;
static volatile bit ram20h2 @(unsigned)&ram20h*8+2;
static volatile bit ram20h1 @(unsigned)&ram20h*8+1;
static volatile bit ram20h0 @(unsigned)&ram20h*8+0;
static volatile bit ram21h7 @(unsigned)&ram21h*8+7;
static volatile bit ram21h6 @(unsigned)&ram21h*8+6;
static volatile bit ram21h5 @(unsigned)&ram21h*8+5;
static volatile bit ram21h4 @(unsigned)&ram21h*8+4;
static volatile bit ram21h3 @(unsigned)&ram21h*8+3;
static volatile bit ram21h2 @(unsigned)&ram21h*8+2;
static volatile bit ram21h1 @(unsigned)&ram21h*8+1;
static volatile bit ram21h0 @(unsigned)&ram21h*8+0;
static volatile bit ram22h7 @(unsigned)&ram22h*8+7;
static volatile bit ram22h6 @(unsigned)&ram22h*8+6;
static volatile bit ram22h5 @(unsigned)&ram22h*8+5;
static volatile bit ram22h4 @(unsigned)&ram22h*8+4;
static volatile bit ram22h3 @(unsigned)&ram22h*8+3;
static volatile bit ram22h2 @(unsigned)&ram22h*8+2;
static volatile bit ram22h1 @(unsigned)&ram22h*8+1;
static volatile bit ram22h0 @(unsigned)&ram22h*8+0;
#includemain()
}
以上程式假設ram20h、ram21h和ram22h的宣告已經加入到相應的標頭檔案中,那麼在源程式中就可以直接使用。 PIC微控制器入門 PICC的指向RAM的指標
將30h,31h,32h單元中最大的數放入40h。include static volatile unsigned char add1 0x30 static volatile unsigned char add2 0x31 static volatile unsigned char add3 0x...
PIC微控制器開發中PICC編譯環境的應用
picc基本上符合ansi標準,但是不支援函式的遞迴呼叫,其主要原因是pic微控制器特殊的堆疊結構。pic微控制器中的堆疊是硬體實現的,其深度已隨晶元固定,無法實現需要大量堆疊操作的遞迴演算法 另外在pic微控制器中實現軟體堆疊的效率也不是很高。為此,picc編譯器採用一種 靜態覆蓋 技術,以實現對...
PIC微控制器引腳
微控制器的訊號引腳是微控制器外特性的體現,在硬體上使用者只能使用引腳,通過引腳的連線組建微控制器系統。pic 8位微控制器系列和mcs 51系列微控制器一樣,其引腳除電源 vdd vss為單一功能外,其餘的訊號引腳常是多個功能,即引腳的復用功能。常見的引腳符號和主要功能如下 1 clr vpp 清除...