PICC18 command line driver based on HI-TECH C compiler

Publisher:FreeSpirit123Latest update time:2012-07-30 Source: 21ic Keywords:HI-TECH Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

PICl8F series products are high-end products of Microchip Technology Co., Ltd. of the United States. Users mostly use C language for programming and design. PICC18 compiler of HI-TECH Software Pty. Ltd. has been widely used. Most users use MPLAB integrated environment for programming (see references). There are some problems in the development of some important or large applications. For example, how to write C language library files, how to compile programs with code restrictions, etc. If only traditional programming is used, the desired effect cannot be achieved. The PICC18 command line driver of HI-TECH C compiler described in this article is to solve these problems.

1 HI-TECH C compiler

HI-TECH C compiler provides the standard features of C language, and also adds many extended functions designed to adapt to the specific hardware features of PIC series microcontrollers, and integrates with assembler to provide shared linker and library management tools, so it is widely used.

When compiling a program, there are many operations that can be completed independently by command line driver CLD (command-line driver) or HPD integrated environment driver (now HI-TIDE). In either case, HPD or CLD (menu options under HPD, or command line of CLD) uses the options specified by the programmer to determine which internal application needs to be executed and
what options need to be sent to each application.

C language source programs and assembly language programs provided by the user that are suitable for the target system can be operated by CLD or HPD. When using CLD, use any command of the command line to select the operation mode; when using HPD, type the required files in the Source File List dialog box.

Commonly used source programs can be compiled into a library file, so that the files can be processed more conveniently and accessed more quickly by the compiler. The compiler can directly receive library files like other source files and use the .lib extension to specify the type of file, so library files must be named in this way. When using CLD, use any command of the command line to select the operation mode; or when using HPD, type the required library files in the "Source File List..." dialog box.

In fact, when using the MPLAB IDE integrated environment for development, CLD is used, but it is not noticed in ordinary applications. The following is the result of compiling a C source file in MPLAB IDE:



From the above results, it can be seen that the compiler uses the CLD command, and the two can be unified. Only after understanding CLD can you have a deeper understanding and mastery of the HI-TECHC compiler.

2 PICC18 command line driver

PICC18 is a driver that calls the DOS command line to compile and/or link C language programs. The basic command format of PICC18 is:

PICC18 [option] files [file library]

is usually identified by a dash "——" before the file name, but this is not necessary. Files can be a mixture of source files (C or assembler) and object files. The file library is a list of library names, or an L option source file. Object files and library files are distinguished by PICC18 through file types or extensions, and the types are listed in Table 1.



PICC18 will check each file and complete the appropriate operation. C files will be compiled and assembly files will be assembled. Finally, all object files obtained by compilation or assembly, or explicitly listed on the command line, are linked with the standard runtime code library and any user-specified libraries, unless they are disabled by some option. Only when the source code is referenced, can the library functions be linked into the resulting output file. Using PICC18 as a program with only object files (i.e. no source files), which means that only the linking stage is performed, is a typical usage. Compile several home-written source files as object files using the C option of PICC18, and then call PICC18 with only the generated object files and the appropriate libraries (with appropriate options) to create the final program.
2.1 Long command lines

The PICC18 driver is a 32-bit Windows software that can handle command lines longer than 128 characters. The driver can be called from a DOS batch file, or options can be passed through a command file. When using a batch file, the command line sent to PICC18 must be listed on a single line. In the command file, driver options can be passed on multiple lines, which is achieved by separating the lines with a space bar followed by a backslash "\" and then a carriage return. For example, a command file can contain:



Since no command line instructions are provided, PICC18 will read xyz. cmd to get its command line instructions. The command file can also be read out through the @ symbol.

For example: PICC18@xyz. cmd

2.2 PICC18 compiler options

The compiler settings are mainly based on the generation of ROM code. Table 2 lists several commonly used important options for the PICC18 compiler.


① Define the processor type: -processor.

This option determines which processor is used. For example, use the command line -18c452 to compile PICl8C452. Users can also add their own processors to the compiler. [page]

② Specify ROM offset: -Aaddress.

The -A option is used to specify the base address for the ROM image area. If this option is required to boot such a debugging tool, the debugging tool expects the ROM mapping address to start at a non-zero address. This option affects all ROM-based parts, including reset and interrupt vectors, as well as linker classes that place code and constant data. If the base address is specified to external memory, the -ROM option must be used to specify the available address range of the external memory.

③Optimizer and optimization priority options: -O and -Zg.

-O means calling the optimizer of PICC18, and the -Zg option calls the global priority in the code generation path. This is of great significance for reducing code length and the use of internal RAM. This priority is not as harsh as the transfer priority, but it is very meaningful for reducing code length. Based on an execution function, the global priority can optimize the use of registers. It also uses the most common transfers in the code to avoid unnecessary memory access.

The default level of this option is 1 (lowest priority). The priority can be set to any level from 1 to 9 (9 is the highest priority). The number indicates the degree to which the priority attempts to reduce the code. For PICC18, priorities higher than 3 are usually useless.

After understanding the command line driver, you will have a deeper understanding of the example of compiling C source files in MPLAB IDE in Section 1.

3 Command line driver application

The following introduces some examples of command line drivers in practical applications. Through these examples, you can have a preliminary understanding of the application of command line drivers, and on this basis, you can conduct in-depth study and application of the PICC18 compiler.

3.1 Command line driver compiles source files

In Win2000, perform the following operations: execute the "Start" → "Run" command, and then enter "CMD"; or execute the "Start" → "Programs" → "Accessories" → "Command Prompt" command, and the cmd.exe interface will pop up, as shown in Figure 1. If the current directory in cmd.exe is not in the root directory of the C drive, you need to enter the root directory of the C drive by entering the command "cd c:\". Enter the "cd htsoft\picl8\bin" command to enter the directory where the PICC18.exe software is located (the directory when it is installed by default), as shown in Figure 2.

(1) Compile Izqmwyz.c

Input "PICC18-18f458 lzqmwyz.c", which means to use PICC18.exe compiler to compile lzqmwyz.c source file, and the microcontroller model is
18f458 (i.e. PIC18F458 microcontroller). At this time, the required compilation result will be output. In the generated file, lzqmwyz.hex with hex extension is more important. If there is a syntax error in the source program, the error message and the line where it is located will also be displayed.

Note: When operating in the cmd.exe interface, all source files are stored in the same directory of PICC18.exe (the default installation directory of PICC18.exe is c:\HTSOFT\PIC18\Bin). In this article, PICC18 uses this default installation directory. Here lzqmwyz.c is stored in c:\HTSOFT\PIC18\Bin.

(2) -noerrata option

The "-noerrata" option does not enable error correction of the output code, while by default, the compiler's output code will be modified. Some chips do not have a bug table and will not be modified by the compiler. This option can be used by the compiler to prohibit any bug table position. When the bug table changes, it will be safely prohibited. For some chips (such as PIC18F458, etc.), PICC18 limits the code length of the program (generally limited to within 0x4000, that is, within 16KB). This is the reason why some netizens in the PICl8 application forum mentioned above have limited code. Some programmers have written the following prompt program in the program:




If the compiled program code exceeds this range, an error message will be listed.

Figure 3 is the prompt message that appears when the code exceeds the length of Ox4000 when compiling the solar050408.c source file.

When using the -noerrata option, solar050408. c source file, the correct compilation result will be obtained. The command is "PICC18-18f458solar050408.co-zgl-noerrata". In the command, "-o" means calling the optimizer of PICC18, and "-zg1" means that the priority used when calling the optimizer is level 1.



3.2 Library file generation and application

3.2.1 C source file

(1) lzqmwyzl.c source file containing the main function




(2) funcx3.c source file containing the function_X3 function [page]



3.2.2 Generate library file

Use the two files in 3.2.1 to directly create an application, which is often used in daily applications. Here we introduce the method of generating a library file from the funcx3. c source file and then calling it from lzqmwyz. c, that is, making a library file yourself for use.

(1) Generate obj file

Store the funcx3. c source file in the same directory as PICC18. exe, and then in cmd. Enter "PICC18-18f458-C funcx3.c" in cmd.exe. The -C option is to compile several source files into target files (.obj files). Here, the source file of funcx3.c is compiled into the funcx3.obj file, and then the funcx3.obj file can be found in the c:\HTSOFT\PICl8\Bin directory.

(2) Generate lib library file

Enter "libr r fun.lib runcx3.obj" in cmd.exe. The r option is the replacement module. fun.lib is the file name of the library file made by the function funcx3.c, as shown in Figure 4.



3.2.3 Library file application

Figure 5 is a project using the lzqmwyzl.c source file of 3.2.1 and calling the library file fun.1ib made in 3.2.2. At this time, only the lzqmwyzl.c source file and fun. 1ib file, and no longer need to use the funcx3.c source file containing the runetton_X3 function.



Conclusion

The PICC18 compiler command line driver has many applications in practice. Only by understanding it can we have a deeper understanding of the C compiler. Due to the limited space, this article only serves as a starting point and provides a way of thinking for the majority of programmers to refer to; at the same time, it also has corresponding reference value for PICC.
Keywords:HI-TECH Reference address:PICC18 command line driver based on HI-TECH C compiler

Previous article:Design of Programmable Power Supply Based on PIC Microcontroller
Next article:MCU interrupt C language usage

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号