51 MCU Development Principles

Publisher:DreamyMoonLatest update time:2015-05-26 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Try to use the variable type that takes up the least code space, such as unsigned character type and bit operation (8051, as an 8-bit processor, provides bit operation support, and most operation instructions are 8-bit or bit operation. It is usually more efficient to write code with small data types)

2. Use unsigned data types as much as possible (8051 microcontrollers do not directly support signed data types. Signed operations require additional instructions to support them, but unsigned data types can be directly supported by 8051)

3. Choose the smallest storage mode possible, that is, small (most applications can be satisfied with the small storage mode, or the large storage mode. If some arrays and structures are stored in the xdata or pdata storage space, choose the extremely large storage mode. Note that the basic pointers used by the Keil C51 real-time library can work in any storage mode)

4. When applying other storage modes, store variables in the data area as much as possible (store variables in the data space, this part of the space can be directly accessed by the MCU, and has the highest execution efficiency. Usually this area stores the most efficient code) Local pictures, please re-upload

5. Know how to use PDATA storage mode on your device (pdata provides 256 bytes of space, using MOVX @Ri instruction to access 8-bit addresses. The use of pdata storage space is different from the internal devices of 8051 microcontrollers, and the page register needs to be set. Xdata storage type is universal and can achieve a maximum storage space of 64kb)

6. Use memory type pointers as much as possible (by default, the Keil C51 compiler uses general pointers to access any type of memory space, and memory type pointers can only access fixed storage space, but this method can generate faster and smaller program code)

7. Reduce the use of reentrant functions (the 8051 series lacks support for stack variables. The implementation of reentrant functions is achieved by the Keil C51 compiler using a compile-time stack to overwrite the data content within the memory range. The reentrant function simulates the stack structure on the 8051 microcontroller. Since reentrant function code is rarely used in embedded applications, you should use this reentrant property as little as possible during the design process)

8. Use LX51 Linker/Locate and Linker code packing to reduce the size of your program. (LX51 Linker/Locate analyzes and optimizes your entire program. The code will be rearranged in memory, using 2-byte AJMP and ACALL instructions to replace 3-byte LJMP and LCALL instructions. Linker code packing uses common code segments to generate subroutines)

9. Keep the interrupt function as short as possible (a well-structured interrupt function only performs data acquisition or timing, and data processing is completed in the main function or the task function of the real-time system, which can effectively reduce the calls of interrupt functions involving saving/storage)

10. Check the need for clock cycles (code access to data requires a certain period of time, especially in real-time systems using multiple threads or interrupt service routines that need to be in the main function)

Reference address:51 MCU Development Principles

Previous article:51 MCU Tuoji 955 Test
Next article:The simplest program of PID control algorithm for single chip microcomputer

Latest Microcontroller Articles
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号