C Language Embedded system programming cultivation (a): Background article

Source: Internet
Author: User

The background of C language Embedded system programming

Different from the general form of software programming, embedded system programming based on a specific hardware platform, it is bound to require its programming language with strong hardware direct operation ability. Undoubtedly, assembly language has such a trait. However, due to the complexity of assembly language development process, it is not the general choice of embedded system development. In contrast, C language, a kind of "advanced low-level" language, becomes the best choice for the development of embedded system. In the development process of embedded system project, I feel the subtlety of C language again and again, and indulge in C language to bring convenience to the embedded development.

Figure 1 shows the hardware platform on which this discussion is based, in fact, this is also the hardware platform of most embedded systems. It consists of two parts:

(1) A general-purpose processor-centric Protocol processing module for network Control Protocol processing;

(2) A digital signal processor (DSP)-centric signal processing module for modulation, demodulation and/or analog signal conversion.

The discussion in this paper revolves around a general-purpose processor-centric Protocol processing module, because it involves more specific C language programming techniques. DSP programming is focused on the specific digital signal processing algorithms, mainly related to the field of communication knowledge, is not the focus of this paper.

Focusing on the common embedded system C programming skills, the system's protocol processing module did not choose a special CPU, but chose the well-known CPU chip--80186, every reader who has learned the principle of microcomputer should have a basic understanding of this chip, and its instruction set is familiar. 80186 of the word length is 16 bits, can be addressed to a memory space of 1MB, only the real address mode. C language compilation generates a pointer of 32 bits (double word), a height of 16 bits for the segment address, and a low 16 bits for the compilation within a segment, a maximum of 64KB.


Figure 1 System hardware Architecture

The flash and RAM in the


Protocol processing module are almost essential devices for each embedded system, which is used to store programs, and the latter is where program runtime directives and data are stored. The system chooses both Flash and ram with a bit width of 16 bits, consistent with the CPU. The

Real-time clock chip can be timed for the system, giving the current year, month, day and specific time (hours, minutes, seconds and milliseconds), you can set it over a period of time to interrupt the CPU or set the alarm time to arrive at the CPU interrupt (similar to the alarm function). The

NVRAM (non-volatile RAM) has the characteristics of the power-down data, which can be used to save the system's setup information, such as network protocol parameters. The previous setup information can still be read after the system has been power-down or restarted. Its bit width is 8 bits, which is smaller than the CPU word length. The article deliberately chooses a memory chip which is inconsistent with the CPU word length, and creates the conditions for the discussion in the following section. The

UART completes the conversion of the CPU parallel data transfer to the RS-232 serial data transfer, which can interrupt the CPU after it receives the [1~max_buffer] byte, and max_buffer the maximum buffer for the UART chip to store the bytes received. The

Keyboard controller and display controller complete the control of the system HMI.

The above provides a more complete embedded system hardware architecture, and the actual system may contain fewer peripherals. The reason for choosing a complete system is to discuss all aspects of the C language programming skills of embedded system in a more comprehensive way, and all the devices will be the analysis target.

Embedded system needs the support of good software development environment, because the target machine resource of embedded system is limited, it is impossible to build a large and complex development environment on it, so its development environment and target running environment are separated from each other. Therefore, the development of the embedded application software is generally, the host in the development environment, the application coding and cross-compiling, and then the host to establish a connection to the target machine, the application download to the target machine for cross-debugging, debugging and optimization, Finally, the application is cured to the target machine to actually run.  

Cad-ul is an embedded application development environment for x86 processors that runs on the Windows operating system to generate target code for x86 processors and to be downloaded to the target machine via the COM port (RS-232 serial port) or Ethernet port of the PC , 2. The monitor program, which resides in the target flash memory, can monitor the user debug instructions on the host Windows Debug platform, get the value of the CPU register and the contents of the target machine storage space and I/O space.


Figure 2 Cross-development environment


The following chapters will expound the programming skills of C language embedded system from the aspects of software architecture, memory operation, screen operation, keyboard operation and performance optimization. Software architecture is a macroscopic concept, with little contact with specific hardware; the memory operation mainly involves the Flash, RAM and NVRAM chip in the system, the screen operation involves the display controller and the real clock, the keyboard operation mainly involves the keyboard controller, and the performance optimization gives some specific techniques to reduce the program time and space consumption.

In our cultivation journey will pass through 25 gates, these gates are divided into two categories, one is the skill type, has a strong applicability, a class is common sense, in theory some meaning.

So, let's go.

C Language Embedded system programming cultivation (a): Background article

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.