C51工具包的總體結構,如圖(1)所示,其中uVision與Ishell分別是C51 for Windows和for Dos的集成開發環境(IDE),能夠完成編輯、編譯、鏈接、調試、仿真等整個開發流程。開發人員可用IDE自己或其它編輯器編輯C或彙編源文件。而後分別由C51及A51編譯器編譯生成目標文件(.OBJ)。目標文件可由LIB51建立生成庫文件,也能夠與庫文件一塊兒經L51鏈接定位生成絕對目標文件(.ABS)。ABS文件由OH51轉換成標準的Hex文件,以供調試器dScope51或tScope51使用進行源代碼級調試,也可由仿真器使用直接對目標板進行調試,也能夠直接寫入程序存貯器如EPROM中。 git
BL51也是C51軟件包的鏈接/定位器,其具備L51的全部功能,此外它還具備如下3點特別之處: a. 能夠鏈接定位大於64kBytes的程序。 b. 具備代碼域及域切換功能(CodeBanking & Bank Switching) c. 可用於RTX51操做系統RTX51是一個實時多任務操做系統,它改變了傳統的編程模式,甚至沒必要用main( )函數,單片機系統軟件向RTOS發展是一種趨勢,這種趨勢對於186和386及68K系列CPU更爲明顯和必須,對8051因CPU較爲簡單,程序結構等都不太複雜,RTX51做用顯得不太突出,其專業版軟件PK51軟件包甚至不包括RTX51Full,而只有一個RTX51TINY版本的RTOS。RTX51 TINY適用於無外部RAM的單片機系統,於是可用面很窄,在本文中不做介紹。Bank switching技術因使用不多也不做介紹。windows
3. DScope51,Tscope51及Monitor51
(1) dScope51
dScope51是一個源級調試器和模擬器,它能夠調試由C51編譯器、A51彙編器、PL/M-51編譯器及ASM-51彙編器產生的程序。它不需目標板(for windows也可經過mon51接目標板),只能進行軟件模擬,但其功能強大,可模擬CPU及其外圍器件,如內部串口,外部I/O及定時器等,能對嵌入式軟件功能進行有效測試。其使用方法爲: DS51[debugfile][INIT(initfile)]其中debugfile是一個Hex格式的8051文件,即待調試的文件其爲可選的,可在進入dScope51後用load命令裝入。Initfile爲一個初使化文件,它在啓動dScope51後,在debugfile裝入前裝入,裝有一些dScope的初使化參數及經常使用調試函數等。下面是一個dScope.ini文件(for dos)的內容: Load ../../ds51/8051.iof Map 0,0xffffdScope51 for Windows則直接用鼠標進入,而後用load裝入待調文件。數組
dScope for windows具備dScope for dos的所有功能,此外,它還具備如下明顯的優勢: (1) 標準的Windows界面,操做更容易更簡單; (2) 經常使用操做多用對話框,而非Dos的行命令方式; (3) 窗口資源更加豐富:存儲器窗口、覆蓋率分析、運行狀態分析窗口,增強了調試功能;由於dScope for Windows功能強大,具體操做在第八章詳細介紹。
每個project都有一個Ishell.CFG,其中存放有「Option菜單和Setup菜單下的部分信息;Bell enabled、Monochrome enabled、Editor Selected、CRT Lines、target enviroment、name of user edit、Automatic load for configuration enabled、file window enabled、file specification for file window、translate command line controls、project name等。對每一個project都必須設置以上信息,而後存盤「setup」的的「save」,這樣纔可正式開始下面工做。
(2) IShell.col文件
對IDE顏色設置,如不改動,能夠缺省爲主。
(3) CDF文件
該文件位於BIN目錄下,每一文件定義一組外部函數工具包,即定義外部環境如8051.CDF,USER.CDF等,開發者可修改CDF文件,供本身使用,至於CDF文件內容可查看一下8051.CDF便可知道。注意.CDF文件是Ishell系統的核心所在,不一樣的CDF文件可以使本IDE適用於不一樣的編譯、鏈接系統,即本IDE並不只適於C51。下面談一談Automake工具:C51的Automake是一個project管理器,在8051工具包中以OBJECT文件形式保留了一個project的信息,AutoMake用這些信息來進行project管理,一旦手工創建一個project,Automake可生成一個新的OBJECT,AutoMake利用此文件來編譯那些修改過的文件。Automake支持C5一、A5一、L51/BL5一、C16六、A16六、L166等編譯鏈接器。點中主菜單中的Automake即運行本工具。Ishell for Dos使用比較繁瑣,推薦使用uVision for windows。
2. uVision for windows的使用
uVision是一個標準的windows應用程序,其編譯功能、文件處理功能、project處理功能、窗口功能以及工具引用功能(如A5一、C5一、PL/M4一、BL51 dScope等)等都較Ishell for Dos要強得多。uVision採用BL51做鏈接器,由於BL51兼容L51,因此一切能在Dos下工做的project均可以到uVision中進行鏈接調試。uVision採用dScope for windows做調試器,該調試器支持MON51及系統模擬兩種方式,功能較for DOS要強大好用,調試功能強大。注意:(1) Option菜單下的各項要會使用,其中A5一、C5一、PL/M5一、BL51定義各文件所使用的編譯、鏈接控制指令,dScope定義一個dScope初始化文件。Make則是定義一個make文件。(2) 進入調試是在RUN菜單下運行dScope。(3) project中包括新建、打開、修改、更新、編譯、鏈接等poject處理,具體使用可參考後面的例子。
中斷聲明方法以下:void serial_ISR () interrupt 4 [using 1]{/* ISR */}爲提升代碼的容錯能力,在沒用到的中斷入口處生成iret語句,定義沒用到的中斷。/* define not used interrupt, so generate \"IRET\" in their entrance */void extern0_ISR() interrupt 0{} /* not used */void timer0_ISR () interrupt 1{} /* not used */void extern1_ISR() interrupt 2{} /* not used */void timer1_ISR () interrupt 3{} /* not used */void serial_ISR () interrupt 4{} /* not used */
2. 通用存儲工做區
3. 選通用存儲工做區由using x聲明,見上例。
4. 指定存儲模式
由small compact 及large說明,例如:void fun1(void) small { }提示:small說明的函數內部變量所有使用內部RAM。關鍵的常常性的耗時的地方能夠這樣聲明,以提升運行速度。
直接在數據定義後加上_at_ const便可,可是注意:(1)絕對變量不能被初使化;(2)bit型函數及變量不能用_at_指定。例如:idata struct link list _at_ 0x40;指定list結構從40h開始。xdata char text[25b] _at_0xE000;指定text數組從0E000H開始提示:若是外部絕對變量是I/O端口等可自行變化數據,須要使用volatile關鍵字進行描述,請參考absacc.h。
啓動文件STARTUP.A51中包含目標板啓動代碼,可在每一個project中加入這個文件,只要復位,則該文件當即執行,其功能包括:l 定義內部RAM大小、外部RAM大小、可重入堆棧位置l 清除內部、外部或者以此頁爲單元的外部存儲器l 按存儲模式初使化重入堆棧及堆棧指針l 初始化8051硬件堆棧指針l 向main( )函數交權開發人員可修改如下數據從而對系統初始化 常數名 意義IDATALEN 待清內部RAM長度XDATA START 指定待清外部RAM起始地址XDATALEN 待清外部RAM長度IBPSTACK 是否小模式重入堆棧指針需初始化標誌,1爲須要。缺省爲0IBPSTACKTOP 指定小模式重入堆棧頂部地址XBPSTACK 是否大模式重入堆棧指針需初始化標誌,缺省爲0XBPSTACKTOP 指定大模式重入堆棧頂部地址PBPSTACK 是否Compact重入堆棧指針,需初始化標誌,缺省爲0PBPSTACKTOP 指定Compact模式重入堆棧頂部地址PPAGEENABLE P2初始化容許開關PPAGE 指定P2值PDATASTART 待清外部RAM頁首址PDATALEN 待清外部RAM頁長度提示:若是要初始化P2做爲緊湊模式高端地址,必須:PPAGEENAGLE=1,PPAGE爲P2值,例如指定某頁1000H-10FFH,則PPAGE=10H,並且鏈接時必須以下:L51
PDATA(1080H),其中1080H是1000H-10FFH中的任一個值。如下是STARTUP.A51代碼片段,紅色是常常可能須要修改的地方:;------------------------------------------------------------------------------; This file is part of the C51 Compiler package; Copyright KEIL ELEKTRONIK GmbH 1990;------------------------------------------------------------------------------; STARTUP.A51: This code is executed after processor reset.;; To translate this file use A51 with the following invocation:;; A51 STARTUP.A51;; To link the modified STARTUP.OBJ file to your application use the following; L51 invocation:;; L51 , STARTUP.OBJ ;;------------------------------------------------------------------------------;; User-defined Power-On Initialization of Memory;; With the following EQU statements the initialization of memory; at processor reset can be defined:;; ; the absolute start-address of IDATA memory is always 0IDATALEN EQU 80H ; the length of IDATA memory in bytes.;XDATASTART EQU 0H ; the absolute start-address of XDATA memoryXDATALEN EQU 0H ; the length of XDATA memory in bytes.;PDATASTART EQU 0H ; the absolute start-address of PDATA memoryPDATALEN EQU 0H ; the length of PDATA memory in bytes.;; Notes: The IDATA space overlaps physically the DATA and BIT areas of the; 8051 CPU. At minimum the memory space occupied from the C51 ; run-time routines must be set to zero.;------------------------------------------------------------------------------;; Reentrant Stack Initilization;; The following EQU statements define the stack pointer for reentrant; functions and initialized it:;; Stack Space for reentrant functions in the SMALL model.IBPSTACK EQU 0 ; set to 1 if small reentrant is used.IBPSTACKTOP EQU 0FFH+1 ; set top of stack to highest location+1.;; Stack Space for reentrant functions in the LARGE model. XBPSTACK EQU 0 ; set to 1 if large reentrant is used.XBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1.;; Stack Space for reentrant functions in the COMPACT model. PBPSTACK EQU 0 ; set to 1 if compact reentrant is used.PBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1.;;------------------------------------------------------------------------------;; Page Definition for Using the Compact Model with 64 KByte xdata RAM;; The following EQU statements define the xdata page used for pdata; variables. The EQU PPAGE must conform with the PPAGE control used; in the linker invocation.;PPAGEENABLE EQU 0 ; set to 1 if pdata object are used.PPAGE EQU 0 ; define PPAGE number.;;------------------------------------------------------------------------------
bit isalnum(char c); bit isalpha(char c); bit iscntrl(char c); bit isdigit(char c); bit isgraph(char c); bit islower(char c); bit isprint(char c); bit ispunct(char c); bit isspace(char c); bit isupper(char c); bit isxdigit(char c); bit toascii(char c); bit toint(char c); char tolower(char c); char __tolower(char c); char toupper(char c); char __toupper(char c);
2. INTRINS.H
unsigned char _crol_(unsigned char c,unsigned char b); unsigned char _cror_(unsigned char c,unsigned char b); unsigned char _chkfloat_(float ual); unsigned int _irol_(unsigned int i,unsigned char b); unsigned int _iror_(unsigned int i,unsigned char b); unsigned long _irol_(unsigned long l,unsigned char b); unsigned long _iror_(unsigned long L,unsigned char b); void _nop_(void); bit _testbit_(bit b);