51实时多任务安卓系统多任务的hex文件不能生成

<p class="lanlink">本文话题:keil c51
&nbsp &nbsp &nbsp &nbspKeil C51开发系统基本知识&nbsp &nbsp &nbsp &nbsp1. 第一节 系统概述&nbsp &nbsp &nbsp &nbspKeil C51是美国Keil Software公司出品的51系列兼容单片机C语言软件开发系统,与汇编相比,C语言在功能上、结构性、可读性、可维护性上有明显的优势,因而易学易用。用过汇编语言后再使用C来开发,体会更加深刻。&nbsp &nbsp &nbsp &nbspKeil C51软件提供丰富的库函数和功能强大的集成开发调试工具,全Windows界面。另外重要的一点,只要看一下编译后生成的汇编代码,就能体会到Keil C51生成的目标代码效率非常之高,多数语句生成的汇编代码很紧凑,容易理解。在开发大型软件时更能体现高级语言的优势。&nbsp &nbsp &nbsp &nbsp下面详细介绍Keil C51开发系统各部分功能和使用。&nbsp &nbsp &nbsp &nbsp2. 第二节 Keil C51单片机软件开发系统的整体结构&nbsp &nbsp &nbsp &nbspC51工具包的整体结构,如图(1)所示,其中uVision与Ishell分别是C51 for&nbsp &nbsp &nbsp &nbspWindows和for Dos的集成开发环境(IDE),可以完成编辑、编译、连接、调试、仿真等整个开发流程。开发人员可用IDE本身或其它编辑器编辑C或汇编源文件。然后分别由C51及A51编译器编译生成目标文件(.OBJ)。目标文件可由LIB51创建生成库文件,也可以与库文件一起经L51连接定位生成绝对目标文件(.ABS)。ABS文件由OH51转换成标准的Hex文件,以供调试器dScope51或tScope51使用进行源代码级调试,也可由仿真器使用直接对目标板进行调试,也可以直接写入程序存贮器如EPROM中。&nbsp &nbsp &nbsp &nbsp图(1) C51工具包整体结构图&nbsp &nbsp &nbsp &nbsp3. 第三节 Keil C51工具包的安装&nbsp &nbsp &nbsp &nbsp1. 1. C51 for Dos&nbsp &nbsp &nbsp &nbsp在Windows下直接运行软件包中DOS\C51DOS.exe然后选择安装目录即可。完毕后欲使系统正常工作须进行以下操作(设C:\C51为安装目录):&nbsp &nbsp &nbsp &nbsp修改Autoexec.bat,加入&nbsp &nbsp &nbsp &nbsppath=C:\C51\Bin&nbsp &nbsp &nbsp &nbspSet C51LIB=C:\C51\LIB&nbsp &nbsp &nbsp &nbspSet C51INC=C:\C51\INC&nbsp &nbsp &nbsp &nbsp然后运行Autoexec.bat&nbsp &nbsp &nbsp &nbsp2. 2. C51 for Windows的安装及注意事项:&nbsp &nbsp &nbsp &nbsp在Windows下运行软件包中WIN\Setup.exe,最好选择安装目录与C51 for Dos相同,这样设置最简单(设安装于C:\C51目录下)。然后将软件包中crack目录中的文件拷入C:\C51\Bin目录下。&nbsp &nbsp &nbsp &nbsp4. 第四节 Keil C51工具包各部分功能及使用简介&nbsp &nbsp &nbsp &nbsp1. 1. C51与A51&nbsp &nbsp &nbsp &nbsp1. (1) C51&nbsp &nbsp &nbsp &nbspC51是C语言编译器,其使用方法为:&nbsp &nbsp &nbsp &nbspC51 sourcefile[编译控制指令]&nbsp &nbsp &nbsp &nbsp或者&nbsp &nbsp &nbsp &nbspC51 @ commandfile&nbsp &nbsp &nbsp &nbsp其中sourcefile为C源文件(.C)。大量的编译控制指令完成C51编译器的全部功能。包控C51输出文件C.LST,.OBJ,.I和.SRC文件的控制。源文件(.C)的控制等,详见第五部分的具体介绍。&nbsp &nbsp &nbsp &nbsp而Commandfile为一个连接控制文件其内容包括:.C源文件及各编译控制指令,它没有固定的名字,开发人员可根据自己的习惯指定,它适于用控制指令较多的场合。&nbsp &nbsp &nbsp &nbsp2. (2) A51&nbsp &nbsp &nbsp &nbspA51是汇编语言编译器,使用方法为:&nbsp &nbsp &nbsp &nbspA51 sourcefile[编译控制指令]&nbsp &nbsp &nbsp &nbsp或A51 @ commandfile&nbsp &nbsp &nbsp &nbsp其中sourcefile为汇编源文件(.asm或.a51),而编译控制指令的使用与其它汇编如ASM语言类似,可参考其他汇编语言材料。&nbsp &nbsp &nbsp &nbspCommandfile同C51中的Commandfile类似,它使A51使用和修改方便。&nbsp &nbsp &nbsp &nbsp2. 2. L51和BL51&nbsp &nbsp &nbsp &nbsp1. (1) L51&nbsp &nbsp &nbsp &nbspL51是Keil C51软件包提供的连接/定位器,其功能是将编译生成的OBJ文件与库文件连接定位生成绝对目标文件(.ABS),其使用方法为:&nbsp &nbsp &nbsp &nbspL51 目标文件列表[库文件列表] [to outputfile] [连接控制指令]&nbsp &nbsp &nbsp &nbsp或 L51 @Commandfile&nbsp &nbsp &nbsp &nbsp源程序的多个模块分别经C51与A51编译后生成多个OBJ文件,连接时,这些文件全列于目标文件列表中,作为输入文件,如果还需与库文件(.LiB)相连接,则库文件也必须列在其后。outputfile为输文件名,缺少时为第一模块名,后缀&nbsp &nbsp &nbsp &nbsp为.ABS。连接控制指令提供了连接定位时的所有控制功能。Commandfile为连接控制文件,其具体内容是包括了目标文件列表,库文件列表及输出文件、连接控制命令,以取代第一种繁琐的格式,由于目标模块库文件大多不止1个,因而第2种方法较多见,这个文件名字也可由使用者随意指定。&nbsp &nbsp &nbsp &nbsp2. (2) Bl51&nbsp &nbsp &nbsp &nbspBL51也是C51软件包的连接/定位器,其具有L51的所有功能,此外它还具有以下3点特别之处:&nbsp &nbsp &nbsp &nbspa. 可以连接定位大于64kBytes的程序。&nbsp &nbsp &nbsp &nbspb. 具有代码域及域切换功能(CodeBanking & Bank Switching)&nbsp &nbsp &nbsp &nbspc. 可用于RTX51操作系统&nbsp &nbsp &nbsp &nbspRTX51是一个实时多任务操作系统,它改变了传统的编程模式,甚至不必用&nbsp &nbsp &nbsp &nbspmain( )函数,单片机系统软件向RTOS发展是一种趋势,这种趋势对于186和386及68K系列CPU更为明显和必须,对8051因CPU较为简单,程序结构等都不太复杂,RTX51作用显得不太突出,其专业版软件PK51软件包甚至不包括&nbsp &nbsp &nbsp &nbspRTX51Full,而只有一个RTX51TINY版本的RTOS。RTX51 TINY适用于无外部RAM的单片机系统,因而可用面很窄,在本文中不作介绍。Bank switching技术因&nbsp &nbsp &nbsp &nbsp使用很少也不作介绍。&nbsp &nbsp &nbsp &nbsp3. 3. DScope51,Tscope51及Monitor51&nbsp &nbsp &nbsp &nbsp1. (1) dScope51&nbsp &nbsp &nbsp &nbspdScope51是一个源级调试器和模拟器,它可以调试由C51编译器、A51汇编器、PL/M-51编译器及ASM-51汇编器产生的程序。它不需目标板(for windows也可通过mon51接目标板),只能进行软件模拟,但其功能强大,可模拟CPU及其外围器件,如内部串口,外部I/O及定时器等,能对嵌入式软件功能进行有效测试。 其使用方法为:&nbsp &nbsp &nbsp &nbspDS51[debugfile][INIT(initfile)]&nbsp &nbsp &nbsp &nbsp其中debugfile是一个Hex格式的8051文件,即待调试的文件其为可选的,可在进入dScope51后用load命令装入。&nbsp &nbsp &nbsp &nbspInitfile为一个初使化文件,它在启动dScope51后,在debugfile装入前装入,装有一些dScope的初使化参数及常用调试函数等。下面是一个dScope.ini文件(for dos)的内容:&nbsp &nbsp &nbsp &nbspLoad ..\..\ds51\8051.iof&nbsp &nbsp &nbsp &nbspMap 0,0ffff&nbsp &nbsp &nbsp &nbspdScope51 for Windows则直接用鼠标进入,然后用load装入待调文件。&nbsp &nbsp &nbsp &nbsp2. (2) tScope51&nbsp &nbsp &nbsp &nbsp与dScope51不同的是Scope51必须带目标板,目前它可以通过两种方式访问目标板。(1) 通过EMul51在线仿真器,tScope51为该仿真器准备了一个动态连接文件EMUL51.IOT,但该方法必须配合该仿真器。(2) 通过Monitov51监控程序,这种方法是可行的,tScope51为访问Monitor51专门带有MON51.IOT连接程序,使用时可通过串口及监控程序来调试目标板。&nbsp &nbsp &nbsp &nbsp其使用方法为:&nbsp &nbsp &nbsp &nbspTS51[INIT(file_name.ini)]&nbsp &nbsp &nbsp &nbsp其中file_name.ini为一个初使化文件。&nbsp &nbsp &nbsp &nbsp进入TS51后,必须装入IOT文件,可用的有MON51.IOT及EMUL51.IOT两种,如装入MON51.IOT:&nbsp &nbsp &nbsp &nbspLoad.C:\C51\TS51\MON51.IOT CPUTYPE(80517)&nbsp &nbsp &nbsp &nbsp可惜的是tScope51只有for Dos的版本。&nbsp &nbsp &nbsp &nbsp3. (3) Monitor 51&nbsp &nbsp &nbsp &nbspMonitor51是一个监控程序通过PC机的串口与目标板进行通信,Monitor操作需要MON51或dScope51 for Windows,后面部分将对Monitor51做较为详细的介绍。&nbsp &nbsp &nbsp &nbsp4. 4. Ishell及uVision&nbsp &nbsp &nbsp &nbsp1. (1) Ishell for Dos&nbsp &nbsp &nbsp &nbsp这是一个for Dos的IDE,直接在命令行键入Ishell,则进入该环境,它使用简单方便。其命令行与DOS命令行具有同样的功能,对单模块的Project直接由菜单进行编译连接,对多模块的project。则通过批处理,BAT文件进行编译连接,然后通过菜单控制由dScope51或tScope51对程序进行调试,因为是for dos的,不做太详细介绍。&nbsp &nbsp &nbsp &nbsp2. (2) uVision for Windows&nbsp &nbsp &nbsp &nbspuVision for Windows是一个标准的Windows应用程序,它是C51的一个集成软件开发平台,具有源代码编辑、project管理、集成的make等功能,它的人机界面友好,操作方便,是开发者的首选,具体配置及使用见第五部分。&nbsp &nbsp &nbsp &nbsp2. 第二章 Keil C51软件使用详解&nbsp &nbsp &nbsp &nbsp1. 第一节 Keil C51编译器的控制指令&nbsp &nbsp &nbsp &nbspC51编译器的控制指令分为三类:源文件控制类,目标文件控制类及列表控制类。&nbsp &nbsp &nbsp &nbsp1. 1. 源文件控制类&nbsp &nbsp &nbsp &nbspNOEXTEND:C51源文件不允许使用ANSI C扩展功能。&nbsp &nbsp &nbsp &nbspDEFINE(DF):定义预处理(在C51命令行)。&nbsp &nbsp &nbsp &nbsp2. 2. 目标文件(Object)控制类:&nbsp &nbsp &nbsp &nbspCOMPACT LARGE SMALL 选编译模式&nbsp &nbsp &nbsp &nbspDEBUG(DB) 包含调试信息,以供仿真器或dSCope51使用。&nbsp &nbsp &nbsp &nbspNOAMAKE(NOAM) 禁止AutoMake信息记录&nbsp &nbsp &nbsp &nbspNOREGPARMS 禁止用寄存器传递参数&nbsp &nbsp &nbsp &nbspOBJECTEXTEND(OE) Object文件包含附加变量类型信息&nbsp &nbsp &nbsp &nbspOPTIMIZE(OT) 指定优化级别&nbsp &nbsp &nbsp &nbspREGFILE(RF) 指定一个寄存器使用的文件以供整体优化用&nbsp &nbsp &nbsp &nbspREGISTERBANK(RB) 指定一个供绝对寄存器访问的寄存器区名&nbsp &nbsp &nbsp &nbspSRC 不生成目标文件只生成汇编源文件&nbsp &nbsp &nbsp &nbsp其它控件不常用。&nbsp &nbsp &nbsp &nbsp3. 3. 列表文件(listing)控制类:&nbsp &nbsp &nbsp &nbspCODE(CD):向列表文件加入汇编列表&nbsp &nbsp &nbsp &nbspLISTINCLUDE(LC):显示indude文件&nbsp &nbsp &nbsp &nbspSYMBOLS(SB):列表文件包括模块内所有符号的列表&nbsp &nbsp &nbsp &nbspWARNINGLEVEL(WL):选择“警告”级别&nbsp &nbsp &nbsp &nbsp2. 第二节 dScope51的使用&nbsp &nbsp &nbsp &nbsp1. 1. dScope51 for Dos&nbsp &nbsp &nbsp &nbsp总的来说dScope51具有以下特性:&nbsp &nbsp &nbsp &nbspl 高级语言显示模式&nbsp &nbsp &nbsp &nbspl 集成硬件环境模拟&nbsp &nbsp &nbsp &nbspl 单步或“GO”执行模式&nbsp &nbsp &nbsp &nbspl 存储器、寄存器及变量访问&nbsp &nbsp &nbsp &nbspl Watch表达式之值&nbsp &nbsp &nbsp &nbspl 函数与信号功能&nbsp &nbsp &nbsp &nbsp下面,具体说明在进入dScope51 for Dos之后,如何实现上述功能,dScope51采用下拉菜单格式和窗口显示控制,共有language、serial、exe、register四个窗口,其中exe为命令行窗口,language为程序窗口,serial为串口窗,register为寄存器窗。&nbsp &nbsp &nbsp &nbsp1. (1) 高级语言显示模式&nbsp &nbsp &nbsp &nbsp单击主菜单中的“View”,第一栏中的三条命令“Highlevel”、“Mixed”、&nbsp &nbsp &nbsp &nbsp“Assembly”分别对所装入的程序按照“高级”、“混合级”及“汇编级”三种方式显示,以方便调试使用。&nbsp &nbsp &nbsp &nbsp2. (2) 集成硬件环境模拟显示&nbsp &nbsp &nbsp &nbsp主菜单中“Peripheral”各条能显示模拟硬件环境的状态,其中:&nbsp &nbsp &nbsp &nbspi/o Port:显示各I/O口之值,对8031而言SFR中的P1、P2、P3、P0与引脚之值分别列出:&nbsp &nbsp &nbsp &nbspInterrupt:显示5个中断源的入口模式是否允许,优先级等中断状态。&nbsp &nbsp &nbsp &nbspTimer:显示各定时/计数器的模式,初始值状态等。&nbsp &nbsp &nbsp &nbspint Message:中断信息允许,如为允许(“&&”出现),则当中断申请时,显示中断源信息。比如当中断发生时会显示:&nbsp &nbsp &nbsp &nbsp“interrupt Timer 0 occured”等&nbsp &nbsp &nbsp &nbspA/D converter:&nbsp &nbsp &nbsp &nbsp显示A/D转换器状态无时,则提示“无”。&nbsp &nbsp &nbsp &nbspSerial:串口信息显示,包括串口模式、波特产等&nbsp &nbsp &nbsp &nbspOther:其它器件,如为8031则显示“ 无”&nbsp &nbsp &nbsp &nbsp3. (3) 单步或“Go”执行&nbsp &nbsp &nbsp &nbsp“F8”单步执行,“F5”全速执行到断点。或选主菜单中Trace单步执行CPU中的Go全速执行。&nbsp &nbsp &nbsp &nbsp4. (4) 存储器寄存器及变量访问&nbsp &nbsp &nbsp &nbsp外部存储器管理MAP菜单:设置(set)、取消(reset)、显示(Display)处理可用存储空间。&nbsp &nbsp &nbsp &nbsp修改Code代码:ASM命令&nbsp &nbsp &nbsp &nbsp存储器显示命令:D 类别为(X、D、I、B、C)&nbsp &nbsp &nbsp &nbsp修改存储器命令:E 有以下几种命令EB、EC、EI、EL、EF、EP&nbsp &nbsp &nbsp &nbsp复杂数据类型显示:Object命令;用以显示结构或数组的内容。欲使此命令有效,C51编译器必须有DB及OBJECTEXTEND两条。&nbsp &nbsp &nbsp &nbsp反汇编命令:U&nbsp &nbsp &nbsp &nbsp5. (5) “Watch”表达式之值&nbsp &nbsp &nbsp &nbsp在View菜单的“Watch”一栏中有四项:其中包括定义Watch Point(Define)、删除Watch Point(remove,kill all),及自动更新选项。&nbsp &nbsp &nbsp &nbsp也可用WS、WK等命令代替,下面具体看“表达式”类型:&nbsp &nbsp &nbsp &nbspdScope51一次最多可设16个WtchPoint表达式,显示于Watch Window之中,表达式可以是简单变量,也可是复杂数据类型如结构、数组和指向结构的指针等,例如:&nbsp &nbsp &nbsp &nbsp&WS *ptime&nbsp &nbsp &nbsp &nbsp&WS ptime→hour&nbsp &nbsp &nbsp &nbsp&WS some_record[o],analog等等&nbsp &nbsp &nbsp &nbsp6. (6) 关于.IOF文件&nbsp &nbsp &nbsp &nbsp14Keil_C51开发系统基本知识_keil c51&nbsp &nbsp &nbsp &nbsp启动DS51后必须装入.IOF文件才能使CPU及Peripheral各项起作用,这个函数的使用是依据8051系列CPU的不同特点,装入8051各CPU硬件设备模拟驱动文件,比如8031CPU就必须load DS51目录下的8051.IOF。&nbsp &nbsp &nbsp &nbsp2. 2. dScope for Windows&nbsp &nbsp &nbsp &nbspdScope for windows具有dScope for dos的全部功能,此外,它还具有以下明显的优点:&nbsp &nbsp &nbsp &nbsp(1) 标准的Windows界面,操作更容易更简单;&nbsp &nbsp &nbsp &nbsp(2) 常用操作多用对话框,而非Dos的行命令方式;&nbsp &nbsp &nbsp &nbsp(3) 窗口资源更加丰富:存储器窗口、覆盖率分析、运行状态分析窗口,加强了调试功能;&nbsp &nbsp &nbsp &nbsp因为dScope for Windows功能强大,具体操作在第八章详细介绍。&nbsp &nbsp &nbsp &nbsp3. 第三节 Monitor51及其使用&nbsp &nbsp &nbsp &nbsp1. 1. Monitor51对硬件的要求&nbsp &nbsp &nbsp &nbsp(1) 硬件系统为51系列CPU;&nbsp &nbsp &nbsp &nbsp(2) 带5K外部程序存储器(从O地址开始),存放Monitor51程序;&nbsp &nbsp &nbsp &nbsp(3) 256Bytes的外部数据存储器以及5K的跟踪缓冲区,此外,外部数据存储器必须足够容纳所有应用程序代码及数据,且所有外部数据存储器必须为冯·诺伊曼存储器,即能一致访问XDATA与Code空间。&nbsp &nbsp &nbsp &nbsp(4) 一个定时器作为波特率发生器供串口使用;&nbsp &nbsp &nbsp &nbsp(5) 6 Bytes的空余堆栈。&nbsp &nbsp &nbsp &nbsp2. 2. Mon51的使用&nbsp &nbsp &nbsp &nbspMon51的使用途径有三种方式:&nbsp &nbsp &nbsp &nbsp(1) Dos行命令方式&nbsp &nbsp &nbsp &nbsp即先用install对MON51进行配置,然后用MON51进入Monitor状态,启用各种命令对Monitor51进行调试。&nbsp &nbsp &nbsp &nbsp(2) tScope51方式&nbsp &nbsp &nbsp &nbsp启动tScope51装入TS51目录下的MON51.IOT驱动文件,与目标板通信。&nbsp &nbsp &nbsp &nbsp(3) dScope51 for Windows方式&nbsp &nbsp &nbsp &nbsp在选CPU驱动文件时,选“MON51.dll”,则检查目标板并进入MON51状态。&nbsp &nbsp &nbsp &nbsp3. 3. MON51的配置&nbsp &nbsp &nbsp &nbsp(1) MON51 for Dos的配置&nbsp &nbsp &nbsp &nbsp运行install文件(在MON51目录下),不同的参数可以配置不同的硬件环境。INSTALL Serialtype [xdstastart[codestart[bank][PROMCHECK]]],具体说明见MON51帮助文件或使用手册。&nbsp &nbsp &nbsp &nbsp(2) MON51 for Windows的配置&nbsp &nbsp &nbsp &nbsp在启用MON51.dll时,会使得系统自动检查目标板连接,如配置不对,则弹出“Configuration”对话框,设置PC串口,波特率等,完毕单击“apply”有效。&nbsp &nbsp &nbsp &nbsp4. 4. 串口连接图:&nbsp &nbsp &nbsp &nbsp收发交叉互连,RTS、CTS直连,DSR、DTR直连,具体引脚排列参考串口资料。&nbsp &nbsp &nbsp &nbsp5. 5. MON51命令及使用&nbsp &nbsp &nbsp &nbsp详细的MON51命令可参阅帮助。&nbsp &nbsp &nbsp &nbsp4. 第四节 集成开发环境(IDE)的使用&nbsp &nbsp &nbsp &nbsp1. 1. Ishell for Dos的使用&nbsp &nbsp &nbsp &nbsp进入Ishell之后看到两个窗口:一个是文件窗口,一个是Dos命令行窗口,窗口上方是下拉式的命令菜单,其中的Files控制文件窗口的显隐。&nbsp &nbsp &nbsp &nbsp使用Ishell,第一步就是配置系统,即要学习两个文件的修改与创建:&nbsp &nbsp &nbsp &nbsp1. (1) Ishell.CFG文件&nbsp &nbsp &nbsp &nbsp每一个project都有一个Ishell.CFG,其中存放有“Option菜单和Setup菜单下的部分信息;Bell enabled、Monochrome enabled、Editor seleced、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等。&nbsp &nbsp &nbsp &nbsp对每个project都必须设置以上信息,然后存盘“setup”的的“save”,这样才可正式开始下面工作。&nbsp &nbsp &nbsp &nbsp2. (2) IShell.col文件&nbsp &nbsp &nbsp &nbsp对IDE颜色设置,如不改动,可以缺省为主。&nbsp &nbsp &nbsp &nbsp3. (3) CDF文件&nbsp &nbsp &nbsp &nbsp该文件位于BIN目录下,每一文件定义一组外部函数工具包,即定义外部环境如8051.CDF,USER.CDF等,开发者可修改CDF文件,供自己使用,至于CDF文件内容可查看一下8051.CDF即可知道。注意.CDF文件是Ishell系统的核心所在,不同的CDF文件可使本IDE适用于不同的编译、连接系统,即本IDE并不仅适于C51。&nbsp &nbsp &nbsp &nbsp下面谈一谈Automake工具:&nbsp &nbsp &nbsp &nbspC51的Automake是一个project管理器,在8051工具包中以OBJECT文件形式保留了一个project的信息,AutoMake用这些信息来进行project管理,一旦手工建立一个project,Automake可生成一个新的OBJECT,AutoMake利用此文件来编译那些修改过的文件。&nbsp &nbsp &nbsp &nbspAutomake支持C51、A51、L51/BL51、C166、A166、L166等编译连接器。点中主菜单中的Automake即运行本工具。&nbsp &nbsp &nbsp &nbspIshell for Dos使用比较繁琐,推荐使用uVision for windows。&nbsp &nbsp &nbsp &nbsp2. 2. uVision for windows的使用&nbsp &nbsp &nbsp &nbspuVision是一个标准的windows应用程序,其编译功能、文件处理功能、project处理功能、窗口功能以及工具引用功能(如A51、C51、PL/M41、BL51 dScope等)等都较Ishell for Dos要强得多。&nbsp &nbsp &nbsp &nbspuVision采用BL51作连接器,因为BL51兼容L51,所以一切能在Dos下工作的project都可以到uVision中进行连接调试。&nbsp &nbsp &nbsp &nbspuVision采用dScope for windows作调试器,该调试器支持MON51及系统模拟两种方式,功能较for DOS要强大好用,调试功能强大。&nbsp &nbsp &nbsp &nbsp注意:&nbsp &nbsp &nbsp &nbsp(1) Option菜单下的各项要会使用,其中A51、C51、PL/M51、BL51定义各文件所使用的编译、连接控制指令,dScope定义一个dScope初始化文件。Make则是定义一个make文件。&nbsp &nbsp &nbsp &nbsp(2) 进入调试是在RUN菜单下运行dScope。&nbsp &nbsp &nbsp &nbsp(3) project中包括新建、打开、修改、更新、编译、连接等poject处理,具体使用可参考后面的例子。&nbsp &nbsp &nbsp &nbsp3. 第三章 Keil C51 vs 标准C&nbsp &nbsp &nbsp &nbsp深入理解并应用C51对标准ANSIC的扩展是学习C51的关键之一。因为大多数扩展功能都是直接针对8051系列CPU硬件的。大致有以下8类:&nbsp &nbsp &nbsp &nbspl 8051存储类型及存储区域&nbsp &nbsp &nbsp &nbspl 存储模式&nbsp &nbsp &nbsp &nbspl 存储器类型声明&nbsp &nbsp &nbsp &nbspl 变量类型声明&nbsp &nbsp &nbsp &nbspl 位变量与位寻址&nbsp &nbsp &nbsp &nbspl 特殊功能寄存器(SFR)&nbsp &nbsp &nbsp &nbspl C51指针&nbsp &nbsp &nbsp &nbspl 函数属性&nbsp &nbsp &nbsp &nbsp具体说明如下(8031为缺省CPU)。&nbsp &nbsp &nbsp &nbsp1. 第一节 Keil C51扩展关键字&nbsp &nbsp &nbsp &nbspC51 V4.0版本有以下扩展关键字(共19个):&nbsp &nbsp &nbsp &nbsp_at_ idata sfr16 alien interrupt small&nbsp &nbsp &nbsp &nbspbdata large _task_ Code bit pdata&nbsp &nbsp &nbsp &nbspusing reentrant xdata compact sbit data sfr&nbsp &nbsp &nbsp &nbsp2. 第二节 内存区域(Memory Areas):&nbsp &nbsp &nbsp &nbsp1. 1. Pragram Area:&nbsp &nbsp &nbsp &nbsp由Code说明可有多达64kBytes的程序存储器&nbsp &nbsp &nbsp &nbsp2. 2. Internal Data Memory:&nbsp &nbsp &nbsp &nbsp内部数据存储器可用以下关键字说明:&nbsp &nbsp &nbsp &nbspdata:直接寻址区,为内部RAM的低128字节 00H~7FH&nbsp &nbsp &nbsp &nbspidata:间接寻址区,包括整个内部RAM区 00H~FFH&nbsp &nbsp &nbsp &nbspbdata:可位寻址区, 20H~2FH&nbsp &nbsp &nbsp &nbsp3. 3. External Data Memory&nbsp &nbsp &nbsp &nbsp外部RAM视使用情况可由以下关键字标识:&nbsp &nbsp &nbsp &nbspxdata:可指定多达64KB的外部直接寻址区,地址范围0000H~0FFFFH&nbsp &nbsp &nbsp &nbsppdata:能访问1页(25bBytes)的外部RAM,主要用于紧凑模式(Compact Model)。&nbsp &nbsp &nbsp &nbsp4. 4. Speciac Function Register Memory&nbsp &nbsp &nbsp &nbsp8051提供128Bytes的SFR寻址区,这区域可位寻址、字节寻址或字寻址,用以控制定时器、计数器、串口、I/O及其它部件,可由以下几种关键字说明:&nbsp &nbsp &nbsp &nbspsfr:字节寻址 比如 sfr P0=080;为PO口地址为80H,“=”后H~FFH之间的常数。&nbsp &nbsp &nbsp &nbspsfr16:字寻址,如sfr16 T2=0指定Timer2口地址T2L=0cc T2H=0CD sbit:位寻址,如sbit EA=0AF;指定第0AF位为EA,即中断允许&nbsp &nbsp &nbsp &nbsp还可以有如下定义方法:&nbsp &nbsp &nbsp &nbspsbit 0V=PSW^2;(定义0V为PSW的第2位)&nbsp &nbsp &nbsp &nbspsbit 0V=0DO^2;(同上)&nbsp &nbsp &nbsp &nbsp或bit 0V-=0D2(同上)。&nbsp &nbsp &nbsp &nbsp3. 第三节 存储模式&nbsp &nbsp &nbsp &nbsp存储模式决定了没有明确指定存储类型的变量,函数参数等的缺省存储区域,共三种:&nbsp &nbsp &nbsp &nbsp1. 1. Small模式&nbsp &nbsp &nbsp &nbsp所有缺省变量参数均装入内部RAM,优点是访问速度快,缺点是空间有限,只适用于小程序。&nbsp &nbsp &nbsp &nbsp2. 2. Compact模式&nbsp &nbsp &nbsp &nbsp所有缺省变量均位于外部RAM区的一页(256Bytes),具体哪一页可由P2口指定,在STARTUP.A51文件中说明,也可用pdata指定,优点是空间较Small为宽裕速度较Small慢,较large要快,是一种中间状态。&nbsp &nbsp &nbsp &nbsp3. 3. large模式&nbsp &nbsp &nbsp &nbsp所有缺省变量可放在多达64KB的外部RAM区,优点是空间大,可存变量多,缺点是速度较慢。&nbsp &nbsp &nbsp &nbsp提示:存储模式在C51编译器选项中选择。&nbsp &nbsp &nbsp &nbsp4. 第四节 存储类型声明&nbsp &nbsp &nbsp &nbsp变量或参数的存储类型可由存储模式指定缺省类型,也可由关键字直接声明指定。各类型分别用:code,data,idata,xdata,pdata说明,例:&nbsp &nbsp &nbsp &nbspdata uar1&nbsp &nbsp &nbsp &nbspchar code array[ ]=“hello!”;&nbsp &nbsp &nbsp &nbspunsigned char xdata arr[10][4][4];&nbsp &nbsp &nbsp &nbsp5. 第五节 变量或数据类型&nbsp &nbsp &nbsp &nbspC51提供以下几种扩展数据类型:&nbsp &nbsp &nbsp &nbspbit 位变量值为0或1&nbsp &nbsp &nbsp &nbspsbit 从字节中定义的位变量 0或1&nbsp &nbsp &nbsp &nbspsfr sfr字节地址 0~255&nbsp &nbsp &nbsp &nbspsfr16 sfr字地址 0~65535&nbsp &nbsp &nbsp &nbsp其余数据类型如:char,enum,short,int,long,float等与ANSI C相同。&nbsp &nbsp &nbsp &nbsp6. 第六节 位变量与声明&nbsp &nbsp &nbsp &nbsp1. 1. bit型变量&nbsp &nbsp &nbsp &nbspbit型变量可用变量类型,函数声明、函数返回值等,存贮于内部RAM20H~2FH。&nbsp &nbsp &nbsp &nbsp注意:&nbsp &nbsp &nbsp &nbsp(1) 用#pragma disable说明函数和用“usign”指定的函数,不能返回bit值。&nbsp &nbsp &nbsp &nbsp(2) 一个bit变量不能声明为指针,如bit *ptr;是错误的&nbsp &nbsp &nbsp &nbsp(3) 不能有bit数组如:bit arr[5];错误。&nbsp &nbsp &nbsp &nbsp2. 2. 可位寻址区说明20H-2FH&nbsp &nbsp &nbsp &nbsp可作如下定义:&nbsp &nbsp &nbsp &nbspint bdata i;&nbsp &nbsp &nbsp &nbspchar bdata arr[3],&nbsp &nbsp &nbsp &nbsp然后:&nbsp &nbsp &nbsp &nbspsbit bito=in0;sbit bit15=I^15;&nbsp &nbsp &nbsp &nbspsbit arr07=arr[0]^7;sbit arr15=arr ^7;&nbsp &nbsp &nbsp &nbsp7. 第七节 Keil C51指针&nbsp &nbsp &nbsp &nbspC51支持一般指针(Generic Pointer)和存储器指针(Memory_Specific Pointer).&nbsp &nbsp &nbsp &nbsp1. 1. 一般指针&nbsp &nbsp &nbsp &nbsp一般指针的声明和使用均与标准C相同,不过同时还可以说明指针的存储类型,例如:&nbsp &nbsp &nbsp &nbsplong *为一个指向long型整数的指针,而state本身则依存储模式存放。 char * xdata ptr;ptr为一个指向char数据的指针,而ptr本身放于外部RAM区,以上的long,char等指针指向的数据可存放于任何存储器中。&nbsp &nbsp &nbsp &nbsp一般指针本身用3个字节存放,分别为存储器类型,高位偏移,低位偏移量。&nbsp &nbsp &nbsp &nbsp2. 2. 存储器指针&nbsp &nbsp &nbsp &nbsp基于存储器的指针说明时即指定了存贮类型,例如:&nbsp &nbsp &nbsp &nbspchar data *str指向data区中char型数据&nbsp &nbsp &nbsp &nbspint xdata * pow指向外部RAM的int型整数。&nbsp &nbsp &nbsp &nbsp这种指针存放时,只需一个字节或2个字节就够了,因为只需存放偏移量。&nbsp &nbsp &nbsp &nbsp3. 3. 指针转换&nbsp &nbsp &nbsp &nbsp即指针在上两种类型之间转化:&nbsp &nbsp &nbsp &nbspl 当基于存储器的指针作为一个实参传递给需要一般指针的函数时,指针自动转化。&nbsp &nbsp &nbsp &nbspl 如果不说明外部函数原形,基于存储器的指针自动转化为一般指针,导致错误,因而请用“#include”说明所有函数原形。&nbsp &nbsp &nbsp &nbspl 可以强行改变指针类型。&nbsp &nbsp &nbsp &nbsp8. 第八节 Keil C51函数&nbsp &nbsp &nbsp &nbspC51函数声明对ANSI C作了扩展,具体包括:&nbsp &nbsp &nbsp &nbsp1. 1. 中断函数声明:&nbsp &nbsp &nbsp &nbsp中断声明方法如下:&nbsp &nbsp &nbsp &nbspvoid serial_ISR () interrupt 4 [using 1]&nbsp &nbsp &nbsp &nbsp{&nbsp &nbsp &nbsp &nbsp&nbsp &nbsp &nbsp &nbsp}&nbsp &nbsp &nbsp &nbsp为提高代码的容错能力,在没用到的中断入口处生成iret语句,定义没用到的中断。&nbsp &nbsp &nbsp &nbsp&nbsp &nbsp &nbsp &nbspvoid extern0_ISR() interrupt 0{} &nbsp &nbsp &nbsp &nbspvoid timer0_ISR () interrupt 1{} &nbsp &nbsp &nbsp &nbspvoid extern1_ISR() interrupt 2{} &nbsp &nbsp &nbsp &nbsp14Keil_C51开发系统基本知识_keil c51&nbsp &nbsp &nbsp &nbspvoid timer1_ISR () interrupt 3{} &nbsp &nbsp &nbsp &nbspvoid serial_ISR () interrupt 4{} &nbsp &nbsp &nbsp &nbsp2. 2. 通用存储工作区&nbsp &nbsp &nbsp &nbsp3. 3. 选通用存储工作区由using x声明,见上例。&nbsp &nbsp &nbsp &nbsp4. 4. 指定存储模式&nbsp &nbsp &nbsp &nbsp由small compact 及large说明,例如:&nbsp &nbsp &nbsp &nbspvoid fun1(void) small { }&nbsp &nbsp &nbsp &nbsp提示:small说明的函数内部变量全部使用内部RAM。关键的经常性的耗时的地方可以这样声明,以提高运行速度。&nbsp &nbsp &nbsp &nbsp5. 5. #pragma disable&nbsp &nbsp &nbsp &nbsp在函数前声明,只对一个函数有效。该函数调用过程中将不可被中断。&nbsp &nbsp &nbsp &nbsp6. 6. 递归或可重入函数指定&nbsp &nbsp &nbsp &nbsp在主程序和中断中都可调用的函数,容易产生问题。因为51和PC不同,PC使用堆栈传递参数,且静态变量以外的内部变量都在堆栈中;而51一般使用寄存器传递参数,内部变量一般在RAM中,函数重入时会破坏上次调用的数据。可以用以下两种方法解决函数重入:&nbsp &nbsp &nbsp &nbspa、在相应的函数前使用前述“#pragma disable”声明,即只允许主程序或中断之一调用该函数;&nbsp &nbsp &nbsp &nbspb、将该函数说明为可重入的。如下:&nbsp &nbsp &nbsp &nbspvoid func(param...)&nbsp &nbsp &nbsp &nbspKeilC51编译后将生成一个可重入变量堆栈,然后就可以模拟通过堆栈传递变量的方法。&nbsp &nbsp &nbsp &nbsp由于一般可重入函数由主程序和中断调用,所以通常中断使用与主程序不同的R寄存器组。&nbsp &nbsp &nbsp &nbsp另外,对可重入函数,在相应的函数前面加上开关“#pragma noaregs”,以禁止编译器使用绝对寄存器寻址,可生成不依赖于寄存器组的代码。&nbsp &nbsp &nbsp &nbsp7. 7. 指定PL/M-51函数&nbsp &nbsp &nbsp &nbsp由alien指定。&nbsp &nbsp &nbsp &nbsp4. 第四章 Keil C51高级编程&nbsp &nbsp &nbsp &nbsp本章讨论以下内容:&nbsp &nbsp &nbsp &nbspl 绝对地址访问&nbsp &nbsp &nbsp &nbspl C与汇编的接口&nbsp &nbsp &nbsp &nbspl C51软件包中的通用文件&nbsp &nbsp &nbsp &nbspl 段名转换与程序优化&nbsp &nbsp &nbsp &nbsp1. 第一节 绝对地址访问&nbsp &nbsp &nbsp &nbspC51提供了三种访问绝对地址的方法:&nbsp &nbsp &nbsp &nbsp1. 1. 绝对宏:&nbsp &nbsp &nbsp &nbsp在程序中,用“#include&absacc.h&”即可使用其中定义的宏来访问绝对地址,包括:&nbsp &nbsp &nbsp &nbspCBYTE、XBYTE、PWORD、DBYTE、CWORD、XWORD、PBYTE、DWORD 具体使用可看一看absacc.h便知&nbsp &nbsp &nbsp &nbsp例如:&nbsp &nbsp &nbsp &nbsprval=CBYTE[00002];指向程序存贮器的0002h地址&nbsp &nbsp &nbsp &nbsprval=XWORD [00002];指向外RAM的0004h地址&nbsp &nbsp &nbsp &nbsp2. 2. _at_关键字&nbsp &nbsp &nbsp &nbsp直接在数据定义后加上_at_ const即可,但是注意:&nbsp &nbsp &nbsp &nbsp(1)绝对变量不能被初使化;&nbsp &nbsp &nbsp &nbsp(2)bit型函数及变量不能用_at_指定。&nbsp &nbsp &nbsp &nbsp例如:&nbsp &nbsp &nbsp &nbspidata struct link list _at_ 040;指定list结构从40h开始。&nbsp &nbsp &nbsp &nbspxdata char text[25b] _at_0E000;指定text数组从0E000H开始&nbsp &nbsp &nbsp &nbsp提示:如果外部绝对变量是I/O端口等可自行变化数据,需要使用volatile关键字进行描述,请参考absacc.h。&nbsp &nbsp &nbsp &nbsp3. 3. 连接定位控制&nbsp &nbsp &nbsp &nbsp此法是利用连接控制指令code xdata pdata \data bdata对“段”地址进行,如要指定某具体变量地址,则很有局限性,不作详细讨论。&nbsp &nbsp &nbsp &nbsp2. 第二节 Keil C51与汇编的接口&nbsp &nbsp &nbsp &nbsp1. 1. 模块内接口&nbsp &nbsp &nbsp &nbsp方法是用#pragma语句具体结构是:&nbsp &nbsp &nbsp &nbsp#pragma asm&nbsp &nbsp &nbsp &nbsp汇编行&nbsp &nbsp &nbsp &nbsp#pragma endasm&nbsp &nbsp &nbsp &nbsp这种方法实质是通过asm与ndasm告诉C51编译器中间行不用编译为汇编行,因而在编译控制指令中有SRC以控制将这些不用编译的行存入其中。&nbsp &nbsp &nbsp &nbsp2. 2. 模块间接口&nbsp &nbsp &nbsp &nbspC模块与汇编模块的接口较简单,分别用C51与A51对源文件进行编译,然后用L51将obj文件连接即可,关键问题在于C函数与汇编函数之间的参数传递问题,C51中有两种参数传递方法。&nbsp &nbsp &nbsp &nbsp(1) 通过寄存器传递函数参数&nbsp &nbsp &nbsp &nbsp最多只能有3个参数通过寄存器传递,规律如下表:&nbsp &nbsp &nbsp &nbsp参数数目 char int long,float 一般指针&nbsp &nbsp &nbsp &nbsp123 R7R5R3 R6 & R7R4 & R5R2 & R3 R4~R7R4~R7 R1~R3R1~R3R1~R3&nbsp &nbsp &nbsp &nbsp(2) 通过固定存储区传递(fixed memory)&nbsp &nbsp &nbsp &nbsp这种方法将bit型参数传给一个存储段中:&nbsp &nbsp &nbsp &nbsp?function_name?BIT&nbsp &nbsp &nbsp &nbsp将其它类型参数均传给下面的段:?function_name?BYTE,且按照预选顺序存放。 至于这个固定存储区本身在何处,则由存储模式默认。&nbsp &nbsp &nbsp &nbsp(3) 函数的返回值&nbsp &nbsp &nbsp &nbsp函数返回值一律放于寄存器中,有如下规律:&nbsp &nbsp &nbsp &nbspreturn type Registev 说明&nbsp &nbsp &nbsp &nbspbit 标志位 由具体标志位返回&nbsp &nbsp &nbsp &nbspchar/unsigned char 1_byte指针 R7 单字节由R7返回&nbsp &nbsp &nbsp &nbspint/unsigned int 2_byte指针 R6 & R7 双字节由R6和R7返回,MSB在R6 long&unsigned long R4~R7 MSB在R4, LSB在R7&nbsp &nbsp &nbsp &nbspfloat R4~R7 32Bit IEEE格式&nbsp &nbsp &nbsp &nbsp一般指针 R1~R3 存储类型在R3 高位R2 低R1&nbsp &nbsp &nbsp &nbsp(4) SRC控制&nbsp &nbsp &nbsp &nbsp该控制指令将C文件编译生成汇编文件(.SRC),该汇编文件可改名后,生成汇编.ASM文件,再用A51进行编译。&nbsp &nbsp &nbsp &nbsp3. 第三节 Keil C51软件包中的通用文件&nbsp &nbsp &nbsp &nbsp在C51\LiB目录下有几个C源文件,这几个C源文件有非常重要的作用,对它们稍事修改,就可以用在自己的专用系统中。&nbsp &nbsp &nbsp &nbsp1. 1. 动态内存分配&nbsp &nbsp &nbsp &nbspinit_mem.C:此文件是初始化动态内存区的程序源代码。它可以指定动态内存的位置及大小,只有使用了init_mem( )才可以调回其它函数,诸如malloc calloc,realloc等。&nbsp &nbsp &nbsp &nbspcalloc.c:此文件是给数组分配内存的源代码,它可以指定单位数据类型及该单元数目。&nbsp &nbsp &nbsp &nbspmalloc.c:此文件是malloc的源代码,分配一段固定大小的内存。&nbsp &nbsp &nbsp &nbsprealloc.c:此文件是realloc.c源代码,其功能是调整当前分配动态内存的大小。&nbsp &nbsp &nbsp &nbsp2. 2. C51启动文件STARTUP.A51&nbsp &nbsp &nbsp &nbsp启动文件STARTUP.A51中包含目标板启动代码,可在每个project中加入这个文件,只要复位,则该文件立即执行,其功能包括:&nbsp &nbsp &nbsp &nbspl 定义内部RAM大小、外部RAM大小、可重入堆栈位置&nbsp &nbsp &nbsp &nbspl 清除内部、外部或者以此页为单元的外部存储器&nbsp &nbsp &nbsp &nbspl 按存储模式初使化重入堆栈及堆栈指针&nbsp &nbsp &nbsp &nbspl 初始化8051硬件堆栈指针&nbsp &nbsp &nbsp &nbspl 向main( )函数交权&nbsp &nbsp &nbsp &nbsp开发人员可修改以下数据从而对系统初始化&nbsp &nbsp &nbsp &nbsp常数名 意义&nbsp &nbsp &nbsp &nbspIDATALEN 待清内部RAM长度&nbsp &nbsp &nbsp &nbspXDATA START 指定待清外部RAM起始地址&nbsp &nbsp &nbsp &nbspXDATALEN 待清外部RAM长度&nbsp &nbsp &nbsp &nbspIBPSTACK 是否小模式重入堆栈指针需初始化标志,1为需要。缺省为0 IBPSTACKTOP 指定小模式重入堆栈顶部地址&nbsp &nbsp &nbsp &nbspXBPSTACK 是否大模式重入堆栈指针需初始化标志,缺省为0&nbsp &nbsp &nbsp &nbspXBPSTACKTOP 指定大模式重入堆栈顶部地址&nbsp &nbsp &nbsp &nbspPBPSTACK 是否Compact重入堆栈指针,需初始化标志,缺省为0&nbsp &nbsp &nbsp &nbspPBPSTACKTOP 指定Compact模式重入堆栈顶部地址&nbsp &nbsp &nbsp &nbspPPAGEENABLE P2初始化允许开关&nbsp &nbsp &nbsp &nbspPPAGE 指定P2值&nbsp &nbsp &nbsp &nbspPDATASTART 待清外部RAM页首址&nbsp &nbsp &nbsp &nbspPDATALEN 待清外部RAM页长度&nbsp &nbsp &nbsp &nbsp提示:如果要初始化P2作为紧凑模式高端地址,必须:PPAGEENAGLE=1,PPAGE为P2值,例如指定某页1000H-10FFH,则PPAGE=10H,而且连接时必须如下:&nbsp &nbsp &nbsp &nbspL51&input modules& PDATA(1080H),其中1080H是1000H-10FFH中的任一个值。&nbsp &nbsp &nbsp &nbsp以下是STARTUP.A51代码片断,红色是经常可能需要修改的地方:&nbsp &nbsp &nbsp &------------------------------------------------------------------------------&nbsp &nbsp &nbsp & This file is part of the C51 Compiler package&nbsp &nbsp &nbsp & Copyright KEIL ELEKTRonIK GmbH 1990&nbsp &nbsp &nbsp &------------------------------------------------------------------------------&nbsp &nbsp &nbsp & STARTUP.A51: This code is executed after processor reset.&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & To translate this file use A51 with the following invocation:&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & A51 STARTUP.A51&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & To link the modified STARTUP.OBJ file to your applicatio L51 invocation:&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & L51 &your object file list&, STARTUP.OBJ &controls&&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp &------------------------------------------------------------------------------&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & User-defined Power-On Initialization of Memory&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & With the following EQU statements the initialization of memory&nbsp &nbsp &nbsp & at processor reset can be defined:&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & ; the absolute start-address of IDATA memory is always 0&nbsp &nbsp &nbsp &nbspIDATALEN EQU 80H ; the length of IDATA memory in bytes.&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp &nbspXDATASTART EQU 0H ; the absolute start-address of XDATA memory&nbsp &nbsp &nbsp &nbspXDATALEN EQU 0H ; the length of XDATA memory in bytes.&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp &nbspPDATASTART EQU 0H ; the absolute start-address of PDATA memory&nbsp &nbsp &nbsp &nbspPDATALEN EQU 0H ; the length of PDATA memory in bytes.&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & Notes: The IDATA space overlaps physically the DATA and BIT 8051 CPU. At minimum the memory space occupied from the C51&nbsp &nbsp &nbsp & run-time routines must be set to zero.&nbsp &nbsp &nbsp &------------------------------------------------------------------------------&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & Reentrant Stack Initilization&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & The following EQU statements define the stack pointer for reentrant&nbsp &nbsp &nbsp & functions and initialized it:&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & Stack Space for reentrant functions in the SMALL model.&nbsp &nbsp &nbsp &nbspIBPSTACK EQU 0 ; set to 1 if small reentrant is used.&nbsp &nbsp &nbsp &nbspIBPSTACKTOP EQU 0FFH+1 ; set top of stack to highest location+1.&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & Stack Space for reentrant functions in the LARGE model.&nbsp &nbsp &nbsp &nbspXBPSTACK EQU 0 ; set to 1 if large reentrant is used.&nbsp &nbsp &nbsp &nbspXBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1.&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & Stack Space for reentrant functions in the COMPACT model.&nbsp &nbsp &nbsp &nbspPBPSTACK EQU 0 ; set to 1 if compact reentrant is used.&nbsp &nbsp &nbsp &nbspPBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1.&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp &------------------------------------------------------------------------------&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & Page Definition for Using the Compact Model with 64 KByte xdata RAM&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp & The following EQU statements define the xdata page used for pdata&nbsp &nbsp &nbsp & variables. The EQU PPAGE must conform with the PPAGE control used&nbsp &nbsp &nbsp & in the linker invocation.&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp &nbspPPAGEENABLE EQU 0 ; set to 1 if pdata object are used.&nbsp &nbsp &nbsp &nbspPPAGE EQU 0 ; define PPAGE number.&nbsp &nbsp &nbsp &&nbsp &nbsp &nbsp &------------------------------------------------------------------------------&nbsp &nbsp &nbsp &nbsp3. 3. 标准输入输出文件&nbsp &nbsp &nbsp &nbspputchar.c&nbsp &nbsp &nbsp &nbspputchar.c是一个低级字符输出子程,开发人员可修改后应用到自己的硬件系统上,例如向CLD或LEN输出字符。&nbsp &nbsp &nbsp &nbsp缺省:putchar.c是向串口输出一个字符XON|XOFF是流控标志,换行符“\*n”自动转化为回车/换行“\r\n”。&nbsp &nbsp &nbsp &nbspgetkey.c&nbsp &nbsp &nbsp &nbspgetkey函数是一个低级字符输入子程,该程序可用到自己硬件系统,如矩阵键盘输入中,缺省时通过串口输入字符。&nbsp &nbsp &nbsp &nbsp4. 4. 其它文件&nbsp &nbsp &nbsp &nbsp还包括对Watch-Dog有独特功能的INIT.A51函数以及对8×C751适用的函数,可参考源代码。&nbsp &nbsp &nbsp &nbsp4. 第四节 段名协定与程序优化&nbsp &nbsp &nbsp &nbsp1. 1. 段名协定(Segment Naming Conventions)&nbsp &nbsp &nbsp &nbspC51编译器生成的目标文件存放于许多段中,这些段是代码空间或数据空间的一些单元,一个段可以是可重定位的,也可以是绝对段,每一个可重定位的段都有一个类型和名字,C51段名有以下规定:&nbsp &nbsp &nbsp &nbsp14Keil_C51开发系统基本知识_keil c51&nbsp &nbsp &nbsp &nbsp每个段名包括前缀与模块名两部分,前缀表示存储类型,模块名则是被编译的模块的名字,例如:&nbsp &nbsp &nbsp &nbsp?CO?main1 :表示main1模块中的代码段中的常数部分&nbsp &nbsp &nbsp &nbsp?PR?function1?module 表module模块中函数function1的可执行段,具体规定参阅手册。&nbsp &nbsp &nbsp &nbsp2. 2. 程序优化&nbsp &nbsp &nbsp &nbspC51编译器是一个具有优化功能的编译器,它共提供六级优化功能。确保生成目标代码的最高效率(代码最少,运行速度最快)。具体六级优化的内容可参考帮助。 在C51中提供以下编译控制指令控制代码优化:&nbsp &nbsp &nbsp &nbspOPTIMIZE(SJXE):尽量采用子程序,使程序代码减少。&nbsp &nbsp &nbsp &nbspNOAREGS:不使用绝对寄存器访问,程序代码与寄存器段独立。&nbsp &nbsp &nbsp &nbspNOREGPARMS:参数传递总是在局部数据段实现,程序代码与低版本C51兼容。 OPTIMIZE(SIZE)AK OPTIMIZE(speed)提供6级优化功能,缺省为:&nbsp &nbsp &nbsp &nbspOPTIMIZE(6,SPEED)。&nbsp &nbsp &nbsp &nbsp5. 第五章 Keil C51库函数参考&nbsp &nbsp &nbsp &nbspC51强大功能及其高效率的重要体现之一在于其丰富的可直接调用的库函数,多使用库函数使程序代码简单,结构清晰,易于调试和维护,下面介绍C51的库函数系统。&nbsp &nbsp &nbsp &nbsp1. 第一节 本征库函数(intrinsic routines)和非本征证库函数&nbsp &nbsp &nbsp &nbspC51提供的本征函数是指编译时直接将固定的代码插入当前行,而不是用ACALL和LCALL语句来实现,这样就大大提供了函数访问的效率,而非本征函数则必须由ACALL及LCALL调用。&nbsp &nbsp &nbsp &nbspC51的本征库函数只有9个,数目虽少,但都非常有用,列如下:&nbsp &nbsp &nbsp &nbsp_crol_,_cror_:将char型变量循环向左(右)移动指定位数后返回&nbsp &nbsp &nbsp &nbsp_iror_,_irol_:将int型变量循环向左(右)移动指定位数后返回&nbsp &nbsp &nbsp &nbsp_lrol_,_lror_:将long型变量循环向左(右)移动指定位数后返回&nbsp &nbsp &nbsp &nbsp_nop_: 相当于插入NOP&nbsp &nbsp &nbsp &nbsp_testbit_: 相当于JBC bitvar测试该位变量并跳转同时清除。&nbsp &nbsp &nbsp &nbsp_chkfloat_: 测试并返回源点数状态。&nbsp &nbsp &nbsp &nbsp使用时,必须包含#inclucle &intrins.h&一行。&nbsp &nbsp &nbsp &nbsp如不说明,下面谈到的库函数均指非本征库函数。&nbsp &nbsp &nbsp &nbsp2. 第二节 几类重要库函数&nbsp &nbsp &nbsp &nbsp1. 1. 专用寄存器include文件&nbsp &nbsp &nbsp &nbsp例如均为REG51.h其中包括了所有8051的SFR及其位定义,一般系统都必须包括本文件。&nbsp &nbsp &nbsp &nbsp2. 2. 绝对地址include文件absacc.h&nbsp &nbsp &nbsp &nbsp该文件中实际只定义了几个宏,以确定各存储空间的绝对地址。&nbsp &nbsp &nbsp &nbsp3. 3. 动态内存分配函数,位于stdlib.h中&nbsp &nbsp &nbsp &nbsp4. 4. 缓冲区处理函数位于“string.h”中&nbsp &nbsp &nbsp &nbsp其中包括拷贝比较移动等函数如:&nbsp &nbsp &nbsp &nbspmemccpy memchr memcmp memcpy memmove memset&nbsp &nbsp &nbsp &nbsp这样很方便地对缓冲区进行处理。&nbsp &nbsp &nbsp &nbsp5. 5. 输入输出流函数,位于“stdio.h”中&nbsp &nbsp &nbsp &nbsp流函数通8051的串口或用户定义的I/O口读写数据,缺省为8051串口,如要修改,比如改为LCD显示,可修改lib目录中的getkey.c及putchar.c源文件,然后在库中替换它们即可。&nbsp &nbsp &nbsp &nbsp3. 第三节 Keil C51库函数原型列表&nbsp &nbsp &nbsp &nbsp1. 1. CTYPE.H&nbsp &nbsp &nbsp &nbspbit isalnum(char c);&nbsp &nbsp &nbsp &nbspbit isalpha(char c);&nbsp &nbsp &nbsp &nbspbit iscntrl(char c);&nbsp &nbsp &nbsp &nbspbit isdigit(char c);&nbsp &nbsp &nbsp &nbspbit isgraph(char c);&nbsp &nbsp &nbsp &nbspbit islower(char c);&nbsp &nbsp &nbsp &nbspbit isprint(char c);&nbsp &nbsp &nbsp &nbspbit ispunct(char c);&nbsp &nbsp &nbsp &nbspbit isspace(char c);&nbsp &nbsp &nbsp &nbspbit isupper(char c);&nbsp &nbsp &nbsp &nbspbit isxdigit(char c);&nbsp &nbsp &nbsp &nbspbit toasci(char c);&nbsp &nbsp &nbsp &nbspbit toint(char c);&nbsp &nbsp &nbsp &nbspchar tolower(char c);&nbsp &nbsp &nbsp &nbspchar __tolower(char c);&nbsp &nbsp &nbsp &nbspchar toupper(char c);&nbsp &nbsp &nbsp &nbspchar __toupper(char c);&nbsp &nbsp &nbsp &nbsp2. 2. INTRINS.H&nbsp &nbsp &nbsp &nbspunsigned char _crol_(unsigned char c,unsigned char b);&nbsp &nbsp &nbsp &nbspunsigned char _cror_(unsigned char c,unsigned char b);&nbsp &nbsp &nbsp &nbspunsigned char _chkfloat_(float ual);&nbsp &nbsp &nbsp &nbspunsigned int _irol_(unsigned int i,unsigned char b);&nbsp &nbsp &nbsp &nbspunsigned int _iror_(unsigned int i,unsigned char b);&nbsp &nbsp &nbsp &nbspunsigned long _irol_(unsigned long l,unsigned char b);&nbsp &nbsp &nbsp &nbspunsigned long _iror_(unsigned long L,unsigned char b);&nbsp &nbsp &nbsp &nbspvoid _nop_(void);&nbsp &nbsp &nbsp &nbspbit _testbit_(bit b);&nbsp &nbsp &nbsp &nbsp3. 3. STDIO.H&nbsp &nbsp &nbsp &nbspchar getcha(void);&nbsp &nbsp &nbsp &nbspchar _getkey(void);&nbsp &nbsp &nbsp &nbspchar *gets(char * string,int len);&nbsp &nbsp &nbsp &nbspint printf(const char * fmtstr[,argument]…);&nbsp &nbsp &nbsp &nbspchar putcha(char c);&nbsp &nbsp &nbsp &nbspint puts (const char * string);&nbsp &nbsp &nbsp &nbspint scanf(const char * fmtstr.[,argument]…);&nbsp &nbsp &nbsp &nbspint sprintf(char * buffer,const char *fmtstr[;argument]);&nbsp &nbsp &nbsp &nbspint sscanf(char *buffer,const char * fmtstr[,argument]);&nbsp &nbsp &nbsp &nbspchar ungetcha(char c);&nbsp &nbsp &nbsp &nbspvoid vprintf (const char *fmtstr,char * argptr);&nbsp &nbsp &nbsp &nbspvoid vsprintf(char *buffer,const char * fmtstr,char * argptr);&nbsp &nbsp &nbsp &nbsp4. 4. STDLIB.H&nbsp &nbsp &nbsp &nbspfloat atof(void * string);&nbsp &nbsp &nbsp &nbspint atoi(void * string);&nbsp &nbsp &nbsp &nbsplong atol(void * string);&nbsp &nbsp &nbsp &nbspvoid * calloc(unsigned int num,unsigned int len);&nbsp &nbsp &nbsp &nbspvoid free(void xdata *p);&nbsp &nbsp &nbsp &nbspvoid init_mempool(void *data *p,unsigned int size);&nbsp &nbsp &nbsp &nbspvoid *malloc (unsigned int size);&nbsp &nbsp &nbsp &nbspint rand(void);&nbsp &nbsp &nbsp &nbspvoid *realloc (void xdata *p,unsigned int size);&nbsp &nbsp &nbsp &nbspvoid srand (int seed);&nbsp &nbsp &nbsp &nbsp5. 5. STRING.H&nbsp &nbsp &nbsp &nbspvoid *memccpy (void *dest,void *src,char c,int len);&nbsp &nbsp &nbsp &nbspvoid *memchr (void *buf,char c,int len);&nbsp &nbsp &nbsp &nbspchar memcmp(void *buf1,void *buf2,int len);&nbsp &nbsp &nbsp &nbspvoid *memcopy (void *dest,void *SRC,int len);&nbsp &nbsp &nbsp &nbspvoid *memmove (void *dest,void *src,int len);&nbsp &nbsp &nbsp &nbspvoid *memset (void *buf,char c,int len);&nbsp &nbsp &nbsp &nbspchar *strcat (char *dest,char *src);&nbsp &nbsp &nbsp &nbspchar *strchr (const char *string,char c);&nbsp &nbsp &nbsp &nbspchar strcmp (char *string1,char *string2);&nbsp &nbsp &nbsp &nbspchar *strcpy (char *dest,char *src);&nbsp &nbsp &nbsp &nbspint strcspn(char *src,char * set);&nbsp &nbsp &nbsp &nbspint strlen (char *src);&nbsp &nbsp &nbsp &nbspchar *strncat (char 8dest,char *src,int len);&nbsp &nbsp &nbsp &nbspchar strncmp(char *string1,char *string2,int len);&nbsp &nbsp &nbsp &nbspchar strncpy (char *dest,char *src,int len);&nbsp &nbsp &nbsp &nbspchar *strpbrk (char *string,char *set);&nbsp &nbsp &nbsp &nbspint strpos (const char *string,char c);&nbsp &nbsp &nbsp &nbspchar *strrchr (const char *string,char c);&nbsp &nbsp &nbsp &nbspchar *strrpbrk (char *string,char *set);&nbsp &nbsp &nbsp &nbspint strrpos (const char *string,char c);&nbsp &nbsp &nbsp &nbspint strspn(char *string,char *set);&nbsp &nbsp &nbsp &nbsp6. 第六章 Keil C51例子:Hello.c&nbsp &nbsp &nbsp &nbspHello位于\C51\excmples\Hello\目录,其功能是向串口输出“Hello,world”整个程序如下:&nbsp &nbsp &nbsp &nbsp#pragma DB OE CD&nbsp &nbsp &nbsp &nbsp#indule &reg51.h&&nbsp &nbsp &nbsp &nbsp#include&stdio.h&&nbsp &nbsp &nbsp &nbspvoid main(void)&nbsp &nbsp &nbsp &nbsp{&nbsp &nbsp &nbsp &nbspSCOn=050;&nbsp &nbsp &nbsp &nbspTMOD=020&nbsp &nbsp &nbsp &nbspTH1=0f3;&nbsp &nbsp &nbsp &nbspTri=1;&nbsp &nbsp &nbsp &nbspTI=1;&nbsp &nbsp &nbsp &nbspprintf(“Hello,world \n”);&nbsp &nbsp &nbsp &nbspwhile(1) { }&nbsp &nbsp &nbsp &nbsp}&nbsp &nbsp &nbsp &nbsp1. 第一节 uVision for Windows的使用步骤&nbsp &nbsp &nbsp &nbsp(1) file_new新建一个hello.c文件,输入如上内容或直接用目录下源文件。&nbsp &nbsp &nbsp &nbsp(2) file_save或工具栏将文件存盘。&nbsp &nbsp &nbsp &nbsp(3) project_new project创建一个project名为hello,并在其中加入hello.c。 这时该project已是打开状态,或用open project打开已存在的project。&nbsp &nbsp &nbsp &nbsp(4) option_C51 compiler中选出至少包括两项DB OE。&nbsp &nbsp &nbsp &nbsp(5) option_dscope Debugger选中hello\DS51.INI&nbsp &nbsp &nbsp &nbsp查看DS51.INI看其是否为:&nbsp &nbsp &nbsp &nbsp“load…\…\BIN\8051.DLL&nbsp &nbsp &nbsp &nbspmap 0, 0ffff”&nbsp &nbsp &nbsp &nbsp否则修改。&nbsp &nbsp &nbsp &nbsp(6) 在option_make选make文件顺序。&nbsp &nbsp &nbsp &nbsp(7) project选Build project,看是否有语法错误,若无则生成HEX文件,若有则修改源文件后重复以上部分步骤。&nbsp &nbsp &nbsp &nbsp(8) run_dScope debugger进入dScope51后装入hello则可用go直接运行看serial窗口有无输出,正常每系统运行一次,serial窗口均出现一个“Hello,world”表明运行无误。&nbsp &nbsp &nbsp &nbsp2. 第二节 Ishell for Dos使用步骤&nbsp &nbsp &nbsp &nbsp(1) 进入Ishell 用Setup editer选择编辑器。&nbsp &nbsp &nbsp &nbsp然后单击Edit或用Edit命令编辑hello.c源文件,存盘,也可以在files窗口中直接选中hello.c。&nbsp &nbsp &nbsp &nbsp(2) 用cd改换project目录至hello目录。&nbsp &nbsp &nbsp &nbsp(3) 在setup_target一项目选8051。&nbsp &nbsp &nbsp &nbsp(4) 在setup_C51中输出DB OE。&nbsp &nbsp &nbsp &nbsp(5) 在setup_project输入project名hello。&nbsp &nbsp &nbsp &nbsp(6) 在setup_save保存Ishell.CFG文件。&nbsp &nbsp &nbsp &nbsp(7) 编辑一个link文件hello.lin中有“hell.obj”一行。&nbsp &nbsp &nbsp &nbsp(8) 由光标落在files菜单中的Hello.c上,单击“translate”,如无语法错,再击“link”,则Hex文件生成。&nbsp &nbsp &nbsp &nbsp(9) 单击Simulate如在8051.CDF中选Simulate为dScope则进入dScope调试直接“Go”,看serial窗口输出为“Hello.world”。&nbsp &nbsp &nbsp &nbsp(10) 如程序有误修改源代码后不必再translate或link了,只要一步Amake即可。 若project中包括不止一个文件,在DOS的Ishell中不能用Translate编译,而应建立bat文件,直接在命令窗编译,然后link连接。&nbsp &nbsp &nbsp &nbsp如还需用Translate则只能多个文件分别编译,然后连接。&nbsp &nbsp &nbsp &nbsp7. 第七章 Keil C51的代码效率&nbsp &nbsp &nbsp &nbspC51程序编译生成汇编代码的效率,是由许多因素共同决定的,对于Keil C51,主要受以下两种因素影响:&nbsp &nbsp &nbsp &nbsp1. 第一节 存储模式的影响&nbsp &nbsp &nbsp &nbsp存储模式决定了缺省变量的存储空间,而访问各空间变量的汇编代码的繁简程度决定了代码率的高低。&nbsp &nbsp &nbsp &nbsp例如:一个整形变量i,如放于内存18H、19H空间,则++i的操作编译成四条语句:&nbsp &nbsp &nbsp &nbspINC 019&nbsp &nbsp &nbsp &nbspMOV A,019&nbsp &nbsp &nbsp &nbspJNZ 0272D&nbsp &nbsp &nbsp &nbspINC 018&nbsp &nbsp &nbsp &nbsp0272D:&nbsp &nbsp &nbsp &nbsp而如果放于外存空间0000H、0001H则++i的操作编译成九条语句:&nbsp &nbsp &nbsp &nbspMOV DPTR,0001&nbsp &nbsp &nbsp &nbspMOVX A,@ DPTR&nbsp &nbsp &nbsp &nbspINC A&nbsp &nbsp &nbsp &nbspMOVX @ DPTR,A&nbsp &nbsp &nbsp &nbspJNz #5&nbsp &nbsp &nbsp &nbspMOV OPTR,#0000&nbsp &nbsp &nbsp &nbspMOVX A,@DPTR&nbsp &nbsp &nbsp &nbspINC A&nbsp &nbsp &nbsp &nbspMOVX @ DPTR,A&nbsp &nbsp &nbsp &nbsp就汇编之后的语句而言,对外部存储器的操作较内部存储器操作代码率要低得多,生成的语句为内存的两倍以上,而程序中有大量的这种操作,可见存储模式对代码率的响了。&nbsp &nbsp &nbsp &nbsp因此程序设计的原则是&nbsp &nbsp &nbsp &nbsp1、存储模式从small-Compact-large依次选择,实在是变量太多,才选large模式。&nbsp &nbsp &nbsp &nbsp2、即使选择了large模式,对一些常用的局部的或者可放于内存中的变量,最好放于内存中,以尽量提高程序的代码率。&nbsp &nbsp &nbsp &nbsp2. 第二节 程序结构的影响&nbsp &nbsp &nbsp &nbsp程序的结构单元包括模块、函数等等。同样的功能,如果结构越复杂,其所涉及的操作、变量、功能模块函数等就越多,较之结构性好,代码简单的程序其代码率自然就低得多。&nbsp &nbsp &nbsp &nbsp此外程序的运行控制语句,也是影响代码率的关键因素,例如:switch -case语句,许多编译器都把它们译得非常复杂,Keil C51也不例外,相对较为简易的Switch-case语句,编译成跳转指令形式,代码率较高,但对较为复杂的Switch-Case,则要调用一个系统库函数?C?ICASE进行处理,非常复杂。&nbsp &nbsp &nbsp &nbsp14Keil_C51开发系统基本知识_keil c51&nbsp &nbsp &nbsp &nbsp再如if( ),while( ),等语句也是代码相对较低的语句,但编译以后比switch-case要高得多。&nbsp &nbsp &nbsp &nbsp因此建议设计者尽量少用switch-case之类语句来控制程序结构,以提高代码率。 除以上两点外,其它因素也会对代码率产生影响,例如:&nbsp &nbsp &nbsp &nbsp是否用寄存器传递参数 即NOAREGS选项是否有&nbsp &nbsp &nbsp &nbsp是否包括调试信息:即DEBUG选项&nbsp &nbsp &nbsp &nbsp是否包括扩展的调试信息:即BJECTEXTEND&nbsp &nbsp &nbsp &nbsp8. 第八章 dScope for Windows使用详解&nbsp &nbsp &nbsp &nbsp1. 第一节 概述&nbsp &nbsp &nbsp &nbsp1. 1. 主窗口(Mainframe Window)&nbsp &nbsp &nbsp &nbsp可设置其它各种调试窗口,设置断点、观察点,修改地址空间,加载文件等等;&nbsp &nbsp &nbsp &nbsp2. 2. 调试窗口(DEBUG Window)&nbsp &nbsp &nbsp &nbsp支持用户程序的各种显示方式,可连续运行,单步运行用户程序,并可在线 汇编;&nbsp &nbsp &nbsp &nbsp3. 3. 命令窗口(Command Window)&nbsp &nbsp &nbsp &nbsp支持命令行的输入;&nbsp &nbsp &nbsp &nbsp4. 4. 观察窗口(Watch Window)&nbsp &nbsp &nbsp &nbsp可设置所要观察的变量、表达式等;&nbsp &nbsp &nbsp &nbsp5. 5. 寄存器窗口(Registe Window)&nbsp &nbsp &nbsp &nbsp显示内部寄存器的内容,程序运行次数等;&nbsp &nbsp &nbsp &nbsp6. 6. 串口窗口(Serical Windows)&nbsp &nbsp &nbsp &nbsp显示串口接收和发送的数据;&nbsp &nbsp &nbsp &nbsp7. 7. 性能分析窗口&nbsp &nbsp &nbsp &nbsp显示所要观察的各程序段占用CPU的空间;&nbsp &nbsp &nbsp &nbsp8. 8. 内存窗口(Memory Window)&nbsp &nbsp &nbsp &nbsp显示所选择的内存中的数据;&nbsp &nbsp &nbsp &nbsp9. 9. 符号浏览窗口(Symbol Browser Window)&nbsp &nbsp &nbsp &nbsp显示各种符号名称,包括专有符号,用户自定义符号(函数名、变量、标号)等;&nbsp &nbsp &nbsp &nbsp10. 10. 调用线窗口(Call-Stack Window)&nbsp &nbsp &nbsp &nbsp动态显示当前执行的程序段的函数调用关系;&nbsp &nbsp &nbsp &nbsp11. 11. 代码覆盖窗口&nbsp &nbsp &nbsp &nbsp提供当前模块内各程序段中被执行代码的比率;。&nbsp &nbsp &nbsp &nbsp12. 12. 外围设备窗口(peripherals)&nbsp &nbsp &nbsp &nbsp可显示I/O口,定时器,中断,串口等外围设备状态;&nbsp &nbsp &nbsp &nbsp2. 第二节 dScope for Windows基本操作&nbsp &nbsp &nbsp &nbsp1. 1. 指定初始化文件&nbsp &nbsp &nbsp &nbsp在uVision的Option菜单dScope Debugger中指定dScope的初始化文件,用uVision的RUN启动dScope将自动加载此初始化文件,自动执行其中命令; 下面是一个例子,可以看出调入一个调试代码的过程。Ds51.ini:&nbsp &nbsp &nbsp &nbspload 8051.dll&nbsp &nbsp &nbsp &nbspload test&nbsp &nbsp &nbsp &nbspslog&&test.log&nbsp &nbsp &nbsp &nbspxtal=11.0592&nbsp &nbsp &nbsp &nbspdefine button &go to main&,&g,main&&nbsp &nbsp &nbsp &nbspws RevCounter&nbsp &nbsp &nbsp &nbspws rm.r&nbsp &nbsp &nbsp &nbspg,main&nbsp &nbsp &nbsp &nbspPA RESET&nbsp &nbsp &nbsp &nbspPA serial&nbsp &nbsp &nbsp &nbspPA timer0&nbsp &nbsp &nbsp &nbsp2. 2. 观察变量&nbsp &nbsp &nbsp &nbsp方法1:命令行&nbsp &nbsp &nbsp &nbspWS expression [, numberbase ] [ LINE ]&nbsp &nbsp &nbsp &nbsp其中numberbase为显示数制,10对应10进制,16对应16进制,缺省为16进制。LINE为单行显示,缺省为多行显示。&nbsp &nbsp &nbsp &nbsp方法2:setup-&Watchpoints,在对话框中输入变量&nbsp &nbsp &nbsp &nbsp3. 3. 显示RAM的值&nbsp &nbsp &nbsp &nbspd i(x,d):起始地址,终止地址&nbsp &nbsp &nbsp &nbspd 变量名&nbsp &nbsp &nbsp &nbsp4. 4. 观察堆栈&nbsp &nbsp &nbsp &nbspView-&Call-stack-&Show invocation,可以跟踪调用过程;&nbsp &nbsp &nbsp &nbsp5. 5. 中断处理程序调试&nbsp &nbsp &nbsp &nbsp在装入8051.dll后,在dScope的主菜单中将增加Peripherial,其有4个字菜单: I/0 port:Pi端口状态&nbsp &nbsp &nbsp &nbspInterrupt:中断设置&nbsp &nbsp &nbsp &nbspTimer:定时器中断状态&nbsp &nbsp &nbsp &nbspSerial:串口中断状态&nbsp &nbsp &nbsp &nbsp设置相应的中断请求标志位即可产生中断。&nbsp &nbsp &nbsp &nbsp6. 6. 性能分析(Performance Analyzer:PA)&nbsp &nbsp &nbsp &nbspPA用来分析一段代码执行占用CPU的百分比。定义:&nbsp &nbsp &nbsp &nbsp命令行 PA func_name&nbsp &nbsp &nbsp &nbsp3. 第三节 dScope for Windows命令文件的编制&nbsp &nbsp &nbsp &nbspdScope除了用命令行的方式进行调试以外,还可将各种调试命令汇集于一个调试文件中,然后调用该文件,就可达到自动测试用户源代码的目的。dScope的命令文件支持C/PL/M的格式,因而编制调试命令文件与编制C语言程序有些类似。&nbsp &nbsp &nbsp &nbsp1. 1. 地址空间及地址空间类型&nbsp &nbsp &nbsp &nbsp1. (1) 地址空间分段&nbsp &nbsp &nbsp &nbspdScope提供的最大可用空间为16M,实际上我们只用以下三段:&nbsp &nbsp &nbsp &nbsp① 内部数据空间段(000段或D段)&nbsp &nbsp &nbsp &nbsp000:FFFF(对MSC51而言为000:000FF)&nbsp &nbsp &nbsp &nbsp② 外部数据空间段(001段式或X段)&nbsp &nbsp &nbsp &nbsp001:0~0FFFF&nbsp &nbsp &nbsp &nbsp③ 程序空间段(0FF段或C段)&nbsp &nbsp &nbsp &nbsp0FF:00000~0FF:0FFFF&nbsp &nbsp &nbsp &nbsp2. (2) 地址空间类型&nbsp &nbsp &nbsp &nbspC:代码空间&nbsp &nbsp &nbsp &nbspD:内部直接寻址空间&nbsp &nbsp &nbsp &nbspI: 内部间接寻址空间&nbsp &nbsp &nbsp &nbspX:外部数据空间&nbsp &nbsp &nbsp &nbspB:位寻址空间&nbsp &nbsp &nbsp &nbspP:I/O口&nbsp &nbsp &nbsp &nbspEB:扩展的位寻址空间(MCS251专有)&nbsp &nbsp &nbsp &nbspED:扩展的数据空间(MCS251专有)&nbsp &nbsp &nbsp &nbspCO:常数空间(MCS251专有)&nbsp &nbsp &nbsp &nbspHC:正常数空间(MCS251专有)&nbsp &nbsp &nbsp &nbsp2. 2. 常量&nbsp &nbsp &nbsp &nbspdScope支持十六进制、八进制、十进制、二进制常数,其后缀分别为H、Q(O)、T(或无)、Y;&nbsp &nbsp &nbsp &nbspdScope不区分常量的大、小写。&nbsp &nbsp &nbsp &nbsp1. (1) 整型常量&nbsp &nbsp &nbsp &nbsp分为整型(int),无符号整型(uint,00rd),长整型(long),无符号长整型(Wlong、Word)。&nbsp &nbsp &nbsp &nbsp2. (2) 浮点型常量&nbsp &nbsp &nbsp &nbsp与ANSI C相同。&nbsp &nbsp &nbsp &nbsp3. (3) 字符串常量&nbsp &nbsp &nbsp &nbsp与ANSI C相同&nbsp &nbsp &nbsp &nbsp4. (4) 字符常量&nbsp &nbsp &nbsp &nbsp分为字符型(Char)和无符号字符型(Uchar)一种。&nbsp &nbsp &nbsp &nbsp5. (5) 行号常数&nbsp &nbsp &nbsp &nbsp指用户程序中的行号,实际上是个地址&nbsp &nbsp &nbsp &nbsp6. (6) 位常量(Bit):&nbsp &nbsp &nbsp &nbsp0和1&nbsp &nbsp &nbsp &nbsp7. (7) 地址常数&nbsp &nbsp &nbsp &nbsp地址常数的种类很多,地址常数不同于行号常数,行号常数就是一个地址,而地址数被引用时,实际上是取该地址中的数据。&nbsp &nbsp &nbsp &nbspC:代码地址常数,如C:00012或0FF:00012&nbsp &nbsp &nbsp &nbspD:内部直接寻址地址常数,如D:0:00068&nbsp &nbsp &nbsp &nbspI:内部间按寻址地址常数,如I:0:00010&nbsp &nbsp &nbsp &nbspX:外部数据空间地址常数,如X:0:00028&nbsp &nbsp &nbsp &nbspB:位地址常数,如B:020或B:024.0&nbsp &nbsp &nbsp &nbspEB:扩展的位地址常数(MCS251专有),&nbsp &nbsp &nbsp &nbspED:扩展的数据空间地址常数(MCS251专有)&nbsp &nbsp &nbsp &nbspCO:常数空间地址常数(MCS251专有)&nbsp &nbsp &nbsp &nbspHC:正常数空间地址常数(MCS251专有)&nbsp &nbsp &nbsp &nbsp8. (8) 标识符常量&nbsp &nbsp &nbsp &nbsp即用户源程序中的标号、函数名等,实际上代表某一地址。&nbsp &nbsp &nbsp &nbsp9. (9) 用户源程序中定义的常数&nbsp &nbsp &nbsp &nbsp3. 3. 变量&nbsp &nbsp &nbsp &nbspdScope所支持的变量名或标识符最多可由31个字符组成,第一个字母为A~Z,a~z,下划线或问号,后续字符可为字母、数字、下划线和问号。除CPU变量和系统变量外,dScope不支持全局变量,但可视“define”命令定义的变量为全局变量。&nbsp &nbsp &nbsp &nbspDscope所支持的变量分为以下几种(变量名称不区分大、小写),支持类型转换:&nbsp &nbsp &nbsp &nbsp1. (1) 整型变量&nbsp &nbsp &nbsp &nbsp分为整型变量(int)、无符号整型变量(uint/word),长整型(Long) 、无符号长整型(Ulong/dword)。&nbsp &nbsp &nbsp &nbsp2. (2) 浮点型变量(float)&nbsp &nbsp &nbsp &nbsp与ANSI C相同。&nbsp &nbsp &nbsp &nbsp3. (3) 字符型变量L&nbsp &nbsp &nbsp &nbsp分为字符型(char)变量和无符号字符型(Uchar)&nbsp &nbsp &nbsp &nbsp4. (4) 位变量(Bit)&nbsp &nbsp &nbsp &nbsp5. (5) 系统变量&nbsp &nbsp &nbsp &nbspdScope自己定义了一系列内部变量,用户可对这些变量进行读或读/写操作, 可被用户自定义数所引用。&nbsp &nbsp &nbsp &nbspa. Cycles (Read Only)&nbsp &nbsp &nbsp &nbsp32位变量(Ulong),指示当前程序执行已花费的指令周期(cycle)。 b. Ramsize(R/W)&nbsp &nbsp &nbsp &nbsp16位变量(Uint),指示内部可直接寻址的数据空间大小。&nbsp &nbsp &nbsp &nbspc. Radix(R/N)&nbsp &nbsp &nbsp &nbsp8位变量(Uchar),决定输出的数制&nbsp &nbsp &nbsp &nbspRadix=00A (10进制),Radix=010 (16进制)&nbsp &nbsp &nbsp &nbspd. -IIP-(R/W)&nbsp &nbsp &nbsp &nbsp8位变量(Uchar),指示当前的中断嵌套数目。&nbsp &nbsp &nbsp &nbspe. $ (R/W)&nbsp &nbsp &nbsp &nbsp32位变量(Ulong),指出PC值,通过对其进行写操作,可改变程序执行的流程。&nbsp &nbsp &nbsp &nbspf. Itrace (R/W)&nbsp &nbsp &nbsp &nbsp8位变量(Uchar),决定是否对程序运行情况进行记录&nbsp &nbsp &nbsp &nbspItrace=1,使能记录操作&nbsp &nbsp &nbsp &nbspItrace=0,根本上记录操作&nbsp &nbsp &nbsp &nbspg. __Break__(R/W)&nbsp &nbsp &nbsp &nbsp8位变量(Uchar) __Break__=1,中止程序的运行&nbsp &nbsp &nbsp &nbsph. __Mode__和__frame size__是MCS 251专有的变量。&nbsp &nbsp &nbsp &nbsp6. (6) CPU变量&nbsp &nbsp &nbsp &nbsp即R0~R7、A、C(位变量)、B、DPTR及特殊功能寄存器变量,对这些变量均可进行读、写操作。&nbsp &nbsp &nbsp &nbsp7. (7) 用户源程序中定义的变量、数组、结构等&nbsp &nbsp &nbsp &nbsp4. 4. 运算符&nbsp &nbsp &nbsp &nbspdScope支持ANSI C的运算符,包括算术运算符,逻辑运算符,关系运算符。&nbsp &nbsp &nbsp &nbsp5. 5. 表达式&nbsp &nbsp &nbsp &nbsp以运算符将dScope所支持的常量、变量、函数等连接在一起,就构成了dScope的表达式。&nbsp &nbsp &nbsp &nbsp6. 6. 数组&nbsp &nbsp &nbsp &nbspdScope不支持在命令文件中定义数组,但可引用用户程序中的数组,引用方式如同C。&nbsp &nbsp &nbsp &nbsp7. 7. 结构和联合&nbsp &nbsp &nbsp &nbspdScope不支持在命令文件中定义结构和联合,但可引用用户程序中的结构和联合,引用方式如同C,但如要输出整个结构或联合的结果,就要用命令“OBJ”。&nbsp &nbsp &nbsp &nbsp8. 8. 指针:&nbsp &nbsp &nbsp &nbsp不可自定义指针,但支持用户源程序中的指针变量。&nbsp &nbsp &nbsp &nbsp9. 9. dScope命令语句&nbsp &nbsp &nbsp &nbspdScope提供了一系列调试命令。在命令文件中,dScope只支持这些语句及前述定义的表达式,C语言的语句均不被支持,但在命令文件所包含的用户自定义函数(非用户源程序中的函数)中支持C语句,但用户自定义函数中同样不支持数组、结构、联合和指针。&nbsp &nbsp &nbsp &nbsp1. (1) ASM&nbsp &nbsp &nbsp &nbsp在线汇编命令,格式如下:&nbsp &nbsp &nbsp &nbspASM C:0nnnn (或标号);设定插入汇编指令的地址&nbsp &nbsp &nbsp &nbspASM 汇编指令&nbsp &nbsp &nbsp &nbspASM 汇编指令&nbsp &nbsp &nbsp &nbsp插入完毕后,在debug窗口内选择“Assemble-&Assemble”完成编译。&nbsp &nbsp &nbsp &nbsp2. (2) Assign&nbsp &nbsp &nbsp &nbsp串行口分配指令,格式如下:&nbsp &nbsp &nbsp &nbspAssign channel&unreg&outreg&nbsp &nbsp &nbsp &nbsp对MCS51为:Assign Win&SOIN& Soot&nbsp &nbsp &nbsp &nbsp但目前的dScope版本并未提供完整串口窗口功能。&nbsp &nbsp &nbsp &nbsp3. (3) Define&nbsp &nbsp &nbsp &nbsp用户自定义变量指令,格式如下:&nbsp &nbsp &nbsp &nbspDefine &类型& &变量名&&nbsp &nbsp &nbsp &nbsp类型一为如前所述的变量类型,Define指令定义的变量可能为全局变量,可为用户自定义函数所引用。&nbsp &nbsp &nbsp &nbsp4. (4) Display&nbsp &nbsp &nbsp &nbsp内存显示命令,格式如下二:&nbsp &nbsp &nbsp &nbspD 起始地址,结束地址&nbsp &nbsp &nbsp &nbsp地址如前所述的地址常数,标识符常量。&nbsp &nbsp &nbsp &nbsp5. (5) Enter&nbsp &nbsp &nbsp &nbsp14Keil_C51开发系统基本知识_keil c51&nbsp &nbsp &nbsp &nbsp内存修改指令,格式如下:&nbsp &nbsp &nbsp &nbspE 类型地址=表达式 [表达式2],[……]&nbsp &nbsp &nbsp &nbsp类型如前所述,地址如前所述的地址常数。表达式如前所述,但如果是函数名称(含标号、指针变量),则关键字E→EP&nbsp &nbsp &nbsp &nbsp6. (6) Map/Reset map&nbsp &nbsp &nbsp &nbspMap为内存段修改指令,Reset map将内存段复位或缺省值。&nbsp &nbsp &nbsp &nbsp7. (7) Object&nbsp &nbsp &nbsp &nbsp用以引用用户源程序中的结构(联合)、数组、格式如下:&nbsp &nbsp &nbsp &nbspObj表达式 [n,],[Line]&nbsp &nbsp &nbsp &nbsp表达式为用户源程序中的数组,结构(联合)名称。当Line缺省时,数目、结构(联合)的内容按n行输出;如有Line,则单行输出。&nbsp &nbsp &nbsp &nbsp8. (8) U&nbsp &nbsp &nbsp &nbsp反汇编命令,格式如下:&nbsp &nbsp &nbsp &nbspU [地址]&nbsp &nbsp &nbsp &nbsp地址包括地址常 数及标识符常量,指明反汇编的起始地址。&nbsp &nbsp &nbsp &nbsp9. (9) WK&nbsp &nbsp &nbsp &nbsp观察点删除命令,格式如下:&nbsp &nbsp &nbsp &nbspWK n1[n2 ],[……] ;删除指定的观察点,n为字符型,整型&nbsp &nbsp &nbsp &nbsp常数&nbsp &nbsp &nbsp &nbspWK * ;删除所有的观察点&nbsp &nbsp &nbsp &nbsp10. (10) WS&nbsp &nbsp &nbsp &nbsp观察点设置命令,格式如下:&nbsp &nbsp &nbsp &nbspWS 表达式[,n][LINE]&nbsp &nbsp &nbsp &nbsp关键字LINE存在时,观察点表达式单行输出&nbsp &nbsp &nbsp &nbspLINE缺省时,观察点表达式n行输出。&nbsp &nbsp &nbsp &nbsp11. (11) G&nbsp &nbsp &nbsp &nbsp连续运行命令,格式如下:&nbsp &nbsp &nbsp &nbspG [起始地址],[终止地址]&nbsp &nbsp &nbsp &nbsp地址为标识符常量或地址常数,地址缺省时,为连续运行。&nbsp &nbsp &nbsp &nbsp12. (12) T/P&nbsp &nbsp &nbsp &nbsp单步运行指令,格式如下:&nbsp &nbsp &nbsp &nbspT/P n ;n指至单行运行的步数,P指给用户当调用某函数时,把它作为一步处理,并不进入该函数运行。&nbsp &nbsp &nbsp &nbsp13. (13) PA&nbsp &nbsp &nbsp &nbsp性能分析操作指令,其分以下几种:&nbsp &nbsp &nbsp &nbspPA&nbsp &nbsp &nbsp &nbsp显示当前所设置的性能分析程度段&nbsp &nbsp &nbsp &nbspPA Kill&SPAN style=&mso-s<p class="lanlink">
相关阅读:
下一篇:暂无
相关推荐:
“如果发现本网站发布的资讯影响到您的版权,可以联系本站!同时欢迎来本站投稿!
本周热门资讯排行

我要回帖

更多关于 实时多任务 的文章

 

随机推荐