Basic knowledge of Keil C51 development system 1

Publisher:春林初盛Latest update time:2015-03-12 Source: laoguKeywords:Keil  C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Basic knowledge of Keil C51 development system 

1. Section 1 System Overview

Keil C51 is a 51 series compatible single-chip microcomputer C language software development system produced by Keil Software, USA. Compared with assembly language, C language has obvious advantages in function, structure, readability and maintainability, so it is easy to learn and use. After using assembly language, you will have a deeper understanding of C development.

Keil C51 software provides rich library functions and powerful integrated development and debugging tools, and a full Windows interface. Another important point is that as long as you look at the assembly code generated after compilation, you can appreciate that the target code generated by Keil C51 is very efficient. The assembly code generated by most statements is very compact and easy to understand. The advantages of high-level languages ​​can be better reflected when developing large-scale software.

The following is a detailed introduction to the functions and uses of each part of the Keil C51 development system.

2. Section 2 The overall structure of the Keil C51 single-chip microcomputer software development system

The overall structure of the C51 toolkit is shown in Figure (1), where uVision and Ishell are the integrated development environments (IDE) of C51 for Windows and for Dos respectively, which can complete the entire development process such as editing, compiling, connecting, debugging, and simulation. Developers can use the IDE itself or other editors to edit C or assembly source files. Then the C51 and A51 compilers compile and generate target files (.OBJ). The target file can be created by LIB51 to generate a library file, or it can be linked and located with the library file through L51 to generate an absolute target file (.ABS). The ABS file is converted into a standard Hex file by OH51 for use by the debugger dScope51 or tScope51 for source code level debugging, or it can be used by the emulator to debug the target board directly, or it can be written directly into the program memory such as EPROM.







Figure (1) Overall structure of the C51 toolkit





3. Section 3 Installation of the Keil C51 toolkit

1. 1. C51 for Dos

Directly run DOSC51DOS.exe in the software package under Windows and then select the installation directory. After the completion, the following operations must be performed to make the system work properly (assuming C:C51 is the installation directory):

Modify Autoexec.bat, add

path=C:C51Bin

Set C51LIB=C:C51LIB

Set C51INC=C:C51INC

Then run Autoexec.bat

2. 2. Installation and precautions of C51 for Windows:

Run WINSetup.exe in the software package under Windows. It is best to choose the same installation directory as C51 for Dos. This is the simplest setting (assuming it is installed in the C:C51 directory). Then copy the files in the crack directory in the software package to the C:C51Bin directory. 

4. Section 4 Introduction to the functions and usage of each part of the Keil C51 toolkit

1. 1. C51 and A51

1. (1) C51

C51 is a C language compiler. Its usage is:

C51 sourcefile [compilation control instructions]

or

C51 @ commandfile

, where sourcefile is a C source file (.C). A large number of compilation control instructions complete all the functions of the C51 compiler. The package controls the C51 output files C.LST, .OBJ, .I and .SRC. For the control of source files (.C), please refer to the detailed introduction in Part 5.

The Commandfile is a connection control file, which includes: .C source files and various compilation control instructions. It has no fixed name, and developers can specify it according to their own habits. It is suitable for occasions with more control instructions.

2. (2) A51

A51 is an assembly language compiler. The usage is:

A51 sourcefile [compilation control instructions]

or A51 @ commandfile

, where sourcefile is the assembly source file (.asm or .a51), and the use of compilation control instructions is similar to other assemblies such as ASM language. You can refer to other assembly language materials.

Commandfile is similar to the Commandfile in C51, which makes A51 easy to use and modify.

2. 2. L51 and BL51

1. (1) L51

L51 is a linker/locator provided by Keil C51 software package. Its function is to link and locate the compiled OBJ file with the library file to generate an absolute target file (.ABS). Its usage is:

L51 target file list [library file list] [to outputfile] [link control instruction]

or L51 @Commandfile

Multiple modules of the source program are compiled by C51 and A51 respectively to generate multiple OBJ files. When linking, all these files are listed in the target file list as input files. If they need to be linked with the library file (.LiB), the library file must also be listed after it. outputfile is the output file name. If missing, it is the first module name with the suffix .ABS. The link control instruction provides all the control functions when linking and locating. Commandfile is a connection control file. Its specific contents include the target file list, library file list, output file, and connection control command to replace the first cumbersome format. Since most target module library files have more than one, the second method is more common. The name of this file can also be specified by the user.

2. (2) Bl51

BL51 is also a connection/locator of the C51 software package. It has all the functions of L51. In addition, it has the following three special features:

a. It can connect and locate programs larger than 64kBytes.

b. With code domain and domain switching function (CodeBanking & Bank Switching)

c. Can be used for RTX51 operating system

RTX51 is a real-time multitasking operating system, which changes the traditional programming mode and does not even need to use the main() function. The development of microcontroller system software towards RTOS is a trend. This trend is more obvious and necessary for 186, 386 and 68K series CPUs. For 8051, because the CPU is relatively simple and the program structure is not too complicated, the role of RTX51 is not very prominent. Its professional version software PK51 software package does not even include RTX51Full, but only an RTX51TINY version of RTOS. RTX51 TINY is suitable for microcontroller systems without external RAM, so its application range is very narrow and will not be introduced in this article. Bank switching technology is rarely used and will not be introduced.

3. 3. DScope51, Tscope51 and Monitor51

1. (1) dScope51

dScope51 is a source-level debugger and simulator, which can debug programs generated by C51 compiler, A51 assembler, PL/M-51 compiler and ASM-51 assembler. It does not require a target board (for Windows, it can also be connected to the target board through mon51), and can only perform software simulation, but it is powerful and can simulate the CPU and its peripheral devices, such as internal serial ports, external I/O and timers, etc., and can effectively test embedded software functions.

Its usage is:

DS51[debugfile][INIT(initfile)]

where debugfile is an 8051 file in Hex format, that is, the file to be debugged. It is optional and can be loaded with the load command after entering dScope51.

Initfile is an initialization file, which is loaded after starting dScope51 and before debugfile is loaded. It contains some dScope initialization parameters and commonly used debugging functions. The following is the content of a dScope.ini file (for dos):

Load ....ds518051.iof

Map 0,0xffff

For dScope51 for Windows, you can directly enter with the mouse, and then use load to load the file to be debugged.

2. (2)

The difference between tScope51 and dScope51 is that Scope51 must be accompanied by a target board. Currently, it can access the target board in two ways. (1) Through the EMul51 online emulator, tScope51 prepares a dynamic link file EMUL51.IOT for the emulator, but this method must be used with the emulator. (2) Through the Monitov51 monitoring program, this method is feasible. tScope51 has a special MON51.IOT connection program for accessing Monitor51. When using it, you can debug the target board through the serial port and the monitoring program.

The usage is:

TS51[INIT(file_name.ini)]

, where file_name.ini is an initialization file.

After entering TS51, you must load the IOT file. There are two types available: MON51.IOT and EMUL51.IOT. For example, to load MON51.IOT:

Load.C:C51TS51MON51.IOT CPUTYPE(80517)

Unfortunately, tScope51 only has a version for Dos.

3. (3) Monitor 51

Monitor51 is a monitoring program that communicates with the target board through the serial port of the PC. Monitor operation requires MON51 or dScope51 for Windows. The following section will give a more detailed introduction to Monitor51.

4. 4. Ishell and uVision

1. (1) Ishell for Dos

This is an IDE for Dos. Simply type Ishell in the command line to enter the environment. It is simple and convenient to use. Its command line has the same functions as the DOS command line. For a single-module project, you can directly compile and link it from the menu. For a multi-module project, you can directly compile and link it from the menu. Then, through batch processing, BAT files are compiled and linked, and then the program is debugged by dScope51 or tScope51 through menu control. Because it is for dos, it will not be introduced in detail.

2. (2) uVision for Windows

uVision for Windows is a standard Windows application. It is an integrated software development platform for C51. It has functions such as source code editing, project management, and integrated make. Its human-computer interface is friendly and easy to operate. It is the first choice for developers. For specific configuration and use, please refer to Part 5. [page]

2. Chapter 2 Detailed Explanation of Keil C51 Software Use

1. Section 1 Control Instructions of Keil C51 Compiler

The control instructions of C51 compiler are divided into three categories: source file control class, target file control class and list control class.

1. 1. Source file control class

NOEXTEND: C51 source files are not allowed to use ANSI C extension functions.

DEFINE (DF): Define preprocessing (in C51 command line).

2. 2. Object file (Object) control class:

COMPACT LARGE SMALL Select compilation mode

DEBUG (DB) Contains debugging information for use by the simulator or dSCope51.

NOAMAKE (NOAM) Disable AutoMake information recording

NOREGPARMS Disable passing parameters using registers

OBJECTEXTEND (OE) Object file contains additional variable type information

OPTIMIZE (OT) Specify optimization level

REGFILE (RF) Specify a register file for overall optimization

REGISTERBANK (RB) Specify a register bank name

SRC for absolute register access Do not generate object files, only generate assembly source files

Other controls are not commonly used.

3. 3. Listing file (listing) control class:

CODE (CD): add assembly list to the list file

LISTINCLUDE (LC): display indude file

SYMBOLS (SB): the list file includes a list of all symbols in the module

WARNINGLEVEL (WL): select the "warning" level

2. Section 2 Use of dScope51

1. 1. dScope51 for Dos

In general, dScope51 has the following features:

l High-level language display mode

l Integrated hardware environment simulation

l Single-step or "GO" execution mode

l Memory, register and variable access

l Watch expression value

l Function and signal function

The following is a detailed description of how to implement the above functions after entering dScope51 for Dos. dScope51 uses a drop-down menu format and window display control. There are four windows: language, serial, exe, and register. Among them, exe is the command line window, language is the program window, serial is the serial port window, and register is the register window.

1. (1) High-level language display mode

Click "View" in the main menu. The three commands "Highlevel", "Mixed" and "Assembly" in the first column respectively display the loaded program in "high level", "mixed level" and "assembly level" to facilitate debugging.

2. (2) Integrated hardware environment simulation display

The "Peripheral" items in the main menu can display the status of the simulated hardware environment, including:

i/o Port: Displays the value of each I/O port. For 8031, the values ​​of P1, P2, P3, P0 and pins in SFR are listed separately:

Interrupt: Displays whether the entry mode of the five interrupt sources is allowed, priority and other interrupt status.

Timer: Displays the mode, initial value status of each timer/counter, etc.

int Message: Interrupt information is allowed. If it is allowed (">>" appears), when the interrupt is requested, the interrupt source information is displayed. For example, when an interrupt occurs, it will display:

"interrupt Timer 0 occurred" etc.

A/D converter:

When the A/D converter status is displayed, it will prompt "None".

Serial: Serial port information display, including serial port mode, baud rate, etc.

Other: Other devices, such as 8031, will display "None"

3. (3) Single step or "Go" execution

"F8" single step execution, "F5" full speed execution to breakpoint. Or select Trace single step execution in the main menu CPU Go full speed execution.

4. (4) Memory register and variable access

External memory management MAP menu: Set (set), cancel (reset), display (Display) to process available storage space.

Modify Code code: ASM command

Memory display command: D category is (X, D, I, B, C)

Modify memory command: E There are the following commands EB, EC, EI, EL, EF, EP

Complex data type display: Object command; used to display the contents of a structure or array. To make this command effective, the C51 compiler must have DB and OBJECTEXTEND.

Disassembly command: U

5. (5) Value of "Watch" expression

There are four items in the "Watch" column of the View menu: Define, Delete Watch Point (remove, kill all), and Auto Update.

You can also use WS, WK and other commands instead. Let's take a look at the "Expression" type:

dScope51 can set up to 16 WatchPoint expressions at a time, which are displayed in the Watch Window. The expression can be a simple variable or a complex data type such as a structure, array, and pointer to a structure, for example:

>WS *ptime

>WS ptime→hour

>WS some_record[o], analog, etc.

6. (6) About .IOF file

After starting DS51, you must load the .IOF file to make the CPU and Peripheral items work. The use of this function is based on the different characteristics of the 8051 series CPU. Load the 8051 CPU hardware device simulation driver files. For example, the 8031CPU must load 8051.IOF in the DS51 directory.

2. 2. dScope for Windows

dScope for Windows has all the functions of dScope for DOS. In addition, it has the following obvious advantages:

(1) Standard Windows interface, easier and simpler to operate; 

(2) Common operations are performed in dialog boxes instead of DOS line commands;

(3) Richer window resources: memory window, coverage analysis, and running status analysis window, which enhance the debugging function;

because dScope for Windows is powerful, the specific operation is described in detail in Chapter 8.

3. Section 3 Monitor51 and its use

1. 1. Hardware requirements for Monitor51

(1) The hardware system is a 51 series CPU;

(2) With 5K external program memory (starting from address O) to store Monitor51 programs;

(3) 256Bytes external data memory and 5K trace buffer. In addition, the external data memory must be large enough to accommodate all application code and data, and all external data memories must be von Neumann memories, that is, they can consistently access XDATA and Code space.

(4) A timer is used as a baud rate generator for the serial port;

(5) 6 bytes of free stack.

2. 2. Use of Mon51

There are three ways to use Mon51:

(1) Dos line command method

That is, first use install to configure MON51, then use MON51 to enter the Monitor state and enable various commands to debug Monitor51.

(2) tScope51 method

Start tScope51 to load the MON51.IOT driver file in the TS51 directory and communicate with the target board.

(3) dScope51 for Windows method

When selecting the CPU driver file, select "MON51.dll", then check the target board and enter the MON51 state.

3. 3. Configuration of MON51

(1) Configuration of MON51 for Dos

Run the install file (in the MON51 directory), different parameters can configure different hardware environments. INSTALL Serialtype [xdstastart[codestart[bank][PROMCHECK]]], for specific instructions, see the MON51 help file or user manual.

(2) Configuration of MON51 for Windows

When MON51.dll is enabled, the system will automatically check the target board connection. If the configuration is incorrect, the "Configuration" dialog box will pop up. Set the PC serial port, baud rate, etc. Click "Apply" to make it effective.

4. 4. Serial port connection diagram:

cross-connection between sender and receiver, direct connection of RTS and CTS, and direct connection of DSR and DTR. For specific pin arrangement, refer to the serial port documentation.

5. 5. MON51 commands and usage For

detailed MON51 commands, please refer to the help.

4. Section 4: Use of Integrated Development Environment (IDE)

1. 1. Use of Ishell for Dos

After entering Ishell, you will see two windows: one is the file window and the other is the Dos command line window. Above the window is a drop-down command menu, in which Files controls the visibility of the file window. [page]

The first step in using Ishell is to configure the system, which means learning how to modify and create two files:

1. (1) Ishell.CFG file

Each project has an Ishell.CFG file, which contains some information under the "Option menu and Setup menu"; 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, etc. The

above information must be set for each project, and then save the "setup" and click "save" to start the following work.

2. (2) IShell.col file

For IDE color settings, if you do not change them, you can use the default as the main one.

3. (3) CDF file

This file is located in the BIN directory. Each file defines a set of external function toolkits, that is, defines external environments such as 8051.CDF, USER.CDF, etc. Developers can modify CDF files for their own use. As for the content of CDF files, you can check 8051.CDF to know. Note that .CDF files are the core of the Ishell system. Different CDF files can make this IDE suitable for different compilation and connection systems, that is, this IDE is not only suitable for C51. Let

's talk about the Automake tool:

C51's Automake is a project manager. In the 8051 toolkit, the information of a project is retained in the form of an OBJECT file. AutoMake uses this information to manage the project. Once a project is manually created, Automake can generate a new OBJECT. AutoMake uses this file to compile the modified files.

Automake supports C51, A51, L51/BL51, C166, A166, L166 and other compilers and connectors. Click Automake in the main menu to run this tool.

Ishell for Dos is relatively cumbersome to use, and it is recommended to use uVision for windows.

2. 2. Usage of uVision for windows

uVision is a standard windows application. Its compiling function, file handling function, project handling function, window function and tool reference function (such as A51, C51, PL/M41, BL51 dScope, etc.) are much stronger than Ishell for Dos.

uVision uses BL51 as a connector. Because BL51 is compatible with L51, all projects that can work under Dos can be connected and debugged in uVision.

uVision uses dScope for windows as a debugger. This debugger supports MON51 and system simulation. It is more powerful and easy to use than for DOS, and has powerful debugging functions.

Note:

(1) You must know how to use the items under the Option menu. A51, C51, PL/M51, and BL51 define the compilation and connection control instructions used by each file. dScope defines a dScope initialization file. Make defines a make file.

(2) To enter debugging, run dScope under the RUN menu.

(3) Project includes new creation, opening, modifying, updating, compiling, linking and other project processing. For specific usage, please refer to the following examples.

3. Chapter 3 Keil C51 vs Standard C

In-depth understanding and application of C51's extension of standard ANSI C is one of the keys to learning C51. Because most of the extended functions are directly aimed at the 8051 series CPU hardware. There are roughly 8 categories:

l 8051 storage type and storage area

l Storage mode

l Memory type declaration

l Variable type declaration

l Bit variable and bit addressing

l Special function register (SFR)

l C51 pointer

l Function attribute

The specific description is as follows (8031 is the default CPU).

1. Section 1 Keil C51 Extended Keywords

C51 V4.0 version has the following extended keywords (19 in total):

_at_ idata sfr16 alien interrupt small

bdata large _task_ Code bit pdata

using reentrant xdata compact sbit data sfr

2. Section 2 Memory Areas:

1. 1. Pragram Area:

The Code indicates that there can be up to 64kBytes of program memory

2. 2. Internal Data Memory:

The internal data memory can be described by the following keywords:

data: directly addressable area, the lower 128 bytes of the internal RAM 00H~7FH

idata: indirectly addressable area, including the entire internal RAM area 00H~FFH

bdata: bit addressable area, 20H~2FH

3. 3. External Data Memory

The external RAM can be identified by the following keywords depending on the usage:

xdata: can specify up to 64KB of external direct addressing area, address range 0000H ~ 0FFFFH

pdata: can access 1 page (25bBytes) of external RAM, mainly used in compact model.

4. 4. Special Function Register Memory

8051 provides 128Bytes SFR addressing area, which can be bit-addressed, byte-addressed or word-addressed to control timers, counters, serial ports, I/O and other components. It can be described by the following keywords:

sfr: byte addressing, such as sfr P0=0x80; the address of the PO port is 80H, and the constant between H and FFH after "=".

sfr16: word addressing, such as sfr16 T2=0xcc; specifies the Timer2 port address T2L=0xcc T2H=0xCD

sbit: bit addressing, such as sbit EA=0xAF; specifies the 0xAF bit as EA, that is, interrupt enable

There are also the following definition methods:

sbit 0V=PSW^2; (define 0V as the second bit of PSW)

sbit 0V=0XDO^2; (same as above)

or bit 0V-=0xD2 (same as above).
Keywords:Keil  C51 Reference address:Basic knowledge of Keil C51 development system 1

Previous article:P3 port keyboard input program
Next article:Basic knowledge of Keil C51 development system 2

Recommended ReadingLatest update time:2024-11-16 20:34

Detailed Analysis of C51 MCU Timer/Counter Interrupt Function (Part 2)
1. External interrupt related registers 1. Timer/Counter Control Register Control Register (TCON)    IT0: External Interrupt 0 Trigger Mode Control Bit  When IT0=0, it is level trigger mode (low level is valid)  When IT0=1, it is edge trigger mode (falling edge is valid)  IT1: External Interrupt 1 Trigger Mode Contro
[Microcontroller]
Detailed Analysis of C51 MCU Timer/Counter Interrupt Function (Part 2)
STM32:keil software logic analyzer (logic analyzer) usage
The software logic analyzer in Keil MDK has powerful functions, which can analyze digital signals, analog signals, CPU bus (UART, IIC and other output pins), provide debugging function mechanism, and generate custom signals, such as Sin, triangle wave, bath sound signal, etc., which can be defined.   Take the built-i
[Microcontroller]
STM32:keil software logic analyzer (logic analyzer) usage
Keil C51 User Tutorial --- Detailed Explanation of dScope Usage (VIII)
Detailed instructions for using dScope for Windows Section 1 Overview 1. Main Window You can set various other debugging windows, set breakpoints, watchpoints, modify address space, load files, etc. 2. DEBUG Window Support various display modes of user programs, can run user programs continuously, run user programs
[Microcontroller]
DS18B20 MCU C51 Thermometer Practice
18B20 thermometer, positive and negative temperature display. Maximum 99 degrees Celsius. Manually soldered with a universal board. Successfully debugged, normal display. Common anode digital tube driven by a triode. The following is a C51 program. You will understand it at a glance:                    #include reg52.
[Microcontroller]
What are the memory types of C51 microcontroller?
C51 memory types include bit sbit data xdata bdata pdata sfr code, etc., which may not be comprehensive and may be omitted. The corresponding physical memory is: bit, that is, bit data: data memory bit addressing area, that is, the range of 20H~2FH, a total of 16 bytes, 16*8=128 bits, bit address 00h~7fh, continuous
[Microcontroller]
Keil usage notes
Enter address_type:address in the Memory window to see the variable with the correct address. Add the module name to be viewed in debug~perfermance analyzer, and then view~perfermance analyzer  window to view the running time of each module. ①Display address_type:address B:Bit address C:Code Memory Bx:Code Bank
[Microcontroller]
Summary of Accurate Delay in Keil C51 Programming
1. Two methods to achieve delay 1. Hardware delay Advantages: Using timer/counter, this method can improve CPU efficiency and achieve accurate delay; Disadvantages: When the accuracy requirement is not very high, the timer/counter will be overqualified, and in extreme cases, the timer is not enough.   2. Software de
[Microcontroller]
Micro2440 Nboot ADS ported to Keil5 and compiled successfully
Since the project needs to develop the old version of S3C2440, due to limited time, the system runs WinCE6.0, and the software compatibility is good. Of course, installing development tools and so on is quite a headache. I have done a lot of STM32 before, and a lot of personal computers are 32 BSP packages. Keil is ve
[Microcontroller]
Micro2440 Nboot ADS ported to Keil5 and compiled successfully
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号