The necessity and advantages of C51 data type expansion definition

2023/11/7 12:14:10

Views:

Data elements, also known as information units, are described by attributes that define, identify, represent, and allow values to construct semantically correct, independent, and unambiguous data units for specific conceptual semantics. In a specific context, data elements are used to construct information units, which are typically organized into a structured whole, known as a data model.

Generally, data elements consist of three parts:

(1) Object Class: It represents a collection of things in the real world or abstract concepts with clear boundaries and meanings. Object classes follow consistent rules for their characteristics and behavior and can be uniquely identified.

(2) Property: It is a property shared by all members of an object class and serves as a basis for distinguishing one object from others.

(3) Representation: It includes a combination of value range, data type, and representation method, sometimes including information like units of measurement and character sets. Object classes represent entities we want to study, collect, and store related data, such as individuals, equipment, organizations, environments, or items. Properties are ways to identify and differentiate things, like an individual's name, gender, height, weight, or position, or a tank's model, caliber, height, length, and effective range. Representation describes how data elements are represented. Any change in any part of the representation components results in a different representation. For example, a person's height can be represented using different units of measurement (such as centimeters or meters), resulting in different data element representations. Representations of data elements often use meaningful terms as labels, such as names, codes, amounts, quantities, dates, percentages, and more.

In the basic model of data elements, object classes correspond to entities in the data model, and properties and representations correspond to attributes in the data model.

Inside microcontrollers, there are numerous special function registers, each with a unique address within the microcontroller. Typically, these registers are given names based on their functions. When we need to manipulate these special function registers in a program, we must declare these names at the beginning of the program. The declaration process associates the addresses of these registers in memory with their names, allowing the compiler to recognize these names as references to the respective registers. For most beginners, these register declarations are already included in the special function register declaration header file "reg51.h" for the 51 microcontroller, so beginners can use these declarations without needing a deep understanding.

Here are some commonly used declarations for special function registers:

- sfr: Declares an 8-bit special function register.
- sfr16: Declares a 16-bit special function register.
- sbit: Declares a special function bit, meaning a specific bit within a special function register.
- bit: Declares a bit variable, which can be used to define a bit variable.

For example: sfr SCON=0x98;

In this example, SCON is the serial port control register of the microcontroller, and its memory address within the microcontroller is 0x98. With this declaration, we can directly manipulate SCON in the program, and the compiler will understand that we are actually manipulating the register at memory address 0x98, with SCON serving as a label or name for that address. Of course, we can choose other names to represent SCON as well.

For example: sfr16 T2=0xCC;

This declaration indicates the declaration of a 16-bit special function register with a starting address of 0xCC.

For example: sbit TI=SCON^1;

In this case, SCON is an 8-bit register, and SCON^1 represents the second least significant bit of that register, with SCON^0 representing the least significant bit and SCON^7 representing the most significant bit. This declaration is used to declare TI as representing the second least significant bit of the SCON register. In the future, when we need to operate on the second least significant bit of the SCON register, we can directly manipulate TI.

Commonly used header files in C51 include reg51.h, reg52.h, math.h, ctype.h, stdio.h, stdlib.h, absacc.h, and intrins.h. Among these, reg51.h and reg52.h are used to define the special function registers and bit registers for 51 and 52 microcontrollers. Most of their contents are similar, with reg52.h containing additional definitions for the T2 timer register, which is present in the 52 microcontroller but not in the 51 microcontroller.

math.h is used to define common mathematical operations, such as absolute value, square root, sine, cosine, etc. When mathematical operations are required, these functions can be directly called.

Once we have a basic understanding of special function registers, we can create our own custom header files and define the names of special function registers as needed. For example, on the TX-1C microcontroller learning board, we use microcontrollers with a 51 core from STC Corporation. These microcontrollers have some additional special functions beyond the standard 51 microcontroller features. When we need to use these special functions, we need to define the names of these special function registers ourselves, based on the register addresses provided in the chip's documentation. We will discuss this aspect further in future practical applications.

Related Information

Home

Home

Products

Products

Phone

Phone

Contact Us

Contact