当前位置:网站首页>Detailed explanation of C51 common data types
Detailed explanation of C51 common data types
2022-07-19 09:36:00 【timerring】
Catalog
2、 special function register ——sfr
3、16 Bit special function register ——sfr16
Background knowledge
Keil C51 Is the U.S. Keil Software company-developed 51 Series compatible with SCM C Language software development system .
(1) compiler C51: American standard optimization C Cross compiler C51 You can put C Source code Convert to relocatable Target file .
(2) Assembler A51 : Assembler A51 hold MCS-51 Assembly source code conversion Into relocatable Target file .
(3) Connect / Heavy positioner BL51:BL51 Combination by C51 and A51 The generated relocatable object file generates an absolute object file .
(4) Library manager LIB51:LIB51 Combine the target file to generate a library file that can be used by the connector .
(5) converter OH51:OH51 Convert the absolute target file to Intel HEX Executable in format .
(6) Monitoring program Monitor-51: use Monitor-51 When debugging the target board , This monitor program resides in the memory of the target board .
(7) Real-time operating system RTX-51: Real-time operating system RTX-51 It simplifies the development of complex and time sensitive software projects .
Summary of data types
KEIL C51 The data types supported by the compiler are shown in the following table :
1、 Bit variable ——bit
bit The bit variable is C51 An extended data type of a compiler , Its value is a binary bit , No 0 Namely 1.
(1) Bit variable C51 Definition
Bit variable C51 The general syntax format of the definition is as follows :
Bit type identifier (bit) Bit variable name ;
for example :
bit direction; /* hold direction Defined as a bit variable */
bit allright ; /* hold allright Defined as a bit variable */
(2) Functions can contain types "bit" Parameters of , It can also be used as a return value .
for example :
bit func(bit b0, bit b1) /* Variable b0,b1 As an argument to a function */
{
return (b1); /* Variable b1 As the return value of the function */
}
(3) Restrictions on bit variable definitions .
A bit variable cannot be defined as a pointer , If it cannot be defined :
bit * bit_point.
No digit group exists , If it cannot be defined :
bit b_array[ ]
2、 special function register ——sfr
sfr It is also an extended data type , The value range is 0~255. Used to access the 51 All special function registers in the single chip microcomputer . special function register C51 The general syntax format of the definition is as follows :
sfr sfr-name = int constant
among “sfr” Is the keyword that defines the statement , It must be followed by MSC-51 The register name of the real special function of MCU ,“=” It must be followed by an integer constant , Expressions with operators are not allowed , Is a special function register “sfr-name” Byte address of , The range of this constant value must be SFR Address range , be located 0x80-0xFF.
If used :sfr P1 = 0x90 Definition P1 by P1 Port on-chip register , In the program we use P1 = 255( Yes P1 All pins of the port are set high ) Such statements to operate special function registers .
C51 The commonly used special function registers are reg51.h or reg52.h Is defined in .
3、16 Bit special function register ——sfr16
Same as sfr equally ,sfr16 by C51 Extended data type , It is just used to define the interior of the single chip microcomputer 16 Bit special function register , And occupy two memory units . for example :DPTR、 Timer T0 and T1.
sfr16 Define the syntax format of the statement and 8 position SFR identical , It's just "=" The following address must be 16 position SFR Low byte address , That is, the low byte address is used as "sfr16" The definition address of .
for example :
sfr16 T2 = 0xCC /* Timer / Counter 2:T2 low 8 The bit address is 0CCH,T2 high 8 The bit address is 0CDH*/
4、 Addressable bits ——sbit
sbit It's also C51 An extended data type in , It can be used to access the inside of the chip RAM Addressable bits in or addressable bits in special function registers . It has three definition formats :
The first format :
sbit bit-name = sfr-name^int constant;
Addressing bit symbol name bit-name( Must be MCS-51 The bit name specified in the SCM ),“=” After “sfr-name” Must be defined SFR Name ,“^” After int constant( Integral constant ) Is the address bit in the special function register “sfr-name” Tag number in , Must be 0~7 Number in range .
for example :
sfr PSW=0xD0 ; /* Definition PSW The register address is D0H */
sbit OV=PSW^2 ; /* Definition OV Position as PSW.2, The address is D2H */
sbit CY=PSW^7 ;/* Definition CY Position as PSW.7, The address is D7H */
Second format :
sbit bit-name = int constant^int constant;
“=” After int constant Is the address of the special function register where the address bit is located Byte address ,“^” After the symbol int constant Is the bit number of the addressing bit in the special function register . for example :
sbit OV=0XD0^2 ;/* Definition OV The bit address is D0H The... In bytes 2 position */
sbit CY=0XD0^7 ;/* Definition CY The bit address is D0H The... In bytes 7 position */
Third format :
sbit bit-name = int constant;
“=” After int constant For addressing bits Absolute bit address . for example :
sbit OV=0XD2 ; /* Definition OV The bit address is D2H */
sbit CY=0XD7 ; /* Definition CY The bit address is D7H */
Be careful sbit and bit difference :bit And other common variable types ( Such as int) similar , It just defines a bit ordinary variable , and sbit The defined bits must be special function registers or internal RAM Addressable bits in the area .
5、 Pointer types
Pointer data itself is a variable , What is stored is the address pointing to another data . For the definition and standard of pointer C Language is similar , example :char * pt; Define a pointer to a character variable . Pointer variables also occupy a certain memory unit , stay C51 Its length is generally 1-3 Bytes .3 A pointer of bytes includes :1 Byte storage type and 2 Byte offset address , As shown in the following table :
About C51 The variable of , Here are two additional points :
(1) In addition to using the above data types , Programmers can also redefine data types according to their habits or hobbies , The definition format is as follows :
typedef Existing data types New data types ;
for example :
typedef unsigned char uchar ; Put the data type unsigned
;char use uchar Instead of .
uchar c ; Define a unsigned char Data variable c
Be careful : There are no new data types added here , It's just another symbol for an existing data type .
(2)C Language is a strong type of language . When evaluating or calculating expressions , The data type of each variable must be consistent .
Type conversion
One 、 Use the cast character “()” Explicit conversion of data types
Two 、 The implicit conversion order is as follows :
bit→char → int → long → float
signed → unsigned
If there are several different data types involved in the operation at the same time , First, implicitly convert the low-level data type to the high-level type, and then do the operation , And the operation result is high-level data type .
边栏推荐
- Interview questions - design test cases for:: memcpy function
- L2-029 independent happiness
- OpenCV模板
- Could NOT find CUDA (missing: CUDA_INCLUDE_DIRS) (found suitable exact version “11.4“)
- 【C语言】 数据类型及意义
- [troubleshooting] common problems and solutions when installing MySQL in Windows system
- Develop the first Flink app
- C# 读写文本,生成二维码
- 如何正确执行Jedis单元测试
- Simple third-party component log desensitization
猜你喜欢
[performance optimization methodology series] VI. summary
How is MySQL data stored on disk?
第一部分—C语言基础篇_1. C语言概述
实用工具系列 - Xshell安装下载与使用
企业数字化转型,为何 SaaS 模式如此重要?
【C语言】浮点型在内存的存储
565. 数组嵌套
Case sharing | build a one-stop data development platform for hehe information based on linkis+dss
Static routing!! Static routing!! Static routing!!
第一部分—C语言基础篇_3. 运算符与表达式
随机推荐
07---布儒斯特角
v-mode
el-table 列拖拽(无须引入其他插件)
Day 6 training
【C语言】指针练习题2——笔试真题及解析
Convert video format to GIF picture format
Mutual access between components
[fishing artifact] UI library second low code tool - form part (II) sub control
SAP Fiori 的附件处理(Attachment handling)
第一部分—C语言基础篇_5. 数组和字符串
2022.7.16-----leetcode.剑指offer.041
Questions d'entrevue - concevoir des cas d'essai pour:: memcpy
MySQL view
mysql进阶(六)模糊查询的四种常见用法介绍
The inflection point of eth may be just around the corner, which is how to
Anycontrol demo demo demo
KNN分类器
[performance optimization methodology series] VI. summary
Leetcode 197 Rising temperature (July 16, 2022)
DuiLib 实现tooltip自定义鼠标提示窗口