Why do microcontrollers use C language?

Publisher:SereneHarmonyLatest update time:2018-10-10 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The transplantation of C to MCU (commonly known as single-chip microcomputer) 8051 began in the mid-to-late 1980s. Objectively speaking, there are many difficulties in transplanting C to 8051 MCU. For example:

The non-von Neumann architecture of the 8051 (separate program and data memory spaces), plus the addition of bit-addressable memory space on-chip;

The on-chip data and program memory space is too small and there is a possibility of expanding them off-chip;

On-chip integrated peripherals are registered (i.e. SFR) rather than using the conventional I/O address space;

There are many derivatives of the 8051 chip (more than a hundred), and the C language must be able to operate on each of their hardware resources without exception.

These are all features that the C language based on MPU did not have in the past. After unremitting efforts by Keil/Franklin, Archmeades, IAR, BSO/Tasking and other companies, it finally matured in the 1990s and became a professional MCU high-level language. The shortcomings that have long troubled people in the past, such as "the code generated by high-level languages ​​is too long and the running speed is too slow, so it is not suitable for single-chip microcomputers", have been largely overcome. At present, the code length of C language on 8051 has reached 1.2~1.5 times that of assembly level. Above 4K bytes, the advantages of C language can be more fully utilized. As for the issue of execution speed, as long as there is a good simulator to help find the key code and further optimize it manually, it can be very simple to achieve a very satisfactory level. If we talk about development speed, software quality, rigorous structure, and program robustness, the perfection of C language is by no means comparable to assembly language programming. Today, it is indeed time for MCU developers to pick up the weapon of C language.

The following introduces the advantages of the single-chip C language in combination with 8051:

Even if you don't know the instruction set of the microcontroller, you can still write a perfect microcontroller program;

·You can compile professional programs that conform to the actual hardware without having to understand the specific hardware of the microcontroller;

Data of different functions are overwritten to effectively utilize the limited RAM space on the chip;

·The program is robust: Data corruption is an important factor that causes program abnormality. C language performs many professional data processing to avoid non-asynchronous corruption during operation;

C language provides complex data types (arrays, structures, unions, enumerations, pointers, etc.), which greatly enhances program processing capabilities and flexibility;

Provide storage types such as auto, static, const, and storage types such as data, idata, pdata, xdata, code, etc. specifically for 8051 microcontrollers, and automatically allocate addresses for variables reasonably;

Provide small, compact, large and other compilation modes to adapt to the size of on-chip memory;

The scene protection and recovery of the interrupt service program and the filling of the interrupt vector table are directly related to the microcontroller and are handled by the C compiler;

Provide commonly used standard function libraries for users to use directly;

The header file defines macros, describes complex data types and function prototypes, which is conducive to the transplantation of programs and the development of serialized products supporting single-chip microcomputers;

There is strict syntax checking, and errors are rare, which can be easily and quickly eliminated at the high-level language level;

It can easily accept the services of various utilities: for example, the initialization of on-chip resources is automatically generated by special utilities; for another example, there is a real-time multitasking operating system that can schedule multiple tasks, simplify user programming, and improve operation security, etc.


Keywords:MCU Reference address:Why do microcontrollers use C language?

Previous article:Common methods and countermeasures for cracking single-chip microcomputers
Next article:Have you ever thought about how the microcontroller program runs?

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号