C语言控制51单片机 sbit 与 sfr 的用法(keil扩展指令 )

本文详细介绍了51单片机中SFR与SBIT指令的使用方法及其作用,包括如何定义特殊功能寄存器及可位寻址的位地址,并解释了这些指令的格式及实例应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. SBIT Assembler Statement

(keil 中 help 的说明)

Arguments sbit sfr_symbol = bit-address;

Description The sbit statement defines a special function register bit:

  • Where

    *sfr_symbol is the name of the Special Function Register (SFR) symbol to define.
    bit-address is the address of the SFR bit in the format address^bit_position.*

The sbit statement allows you to define SFR bit data in a consistent manner with the Cx51 compiler. With this statement you may use a generic SFR register definition file for the Cx51 compiler and the Ax51 assembler.

Example
sbit P0_0 = P0^0;
sbit P0_1 = 0x90^1;

理解

sbit 用于特殊功能寄存器中可位寻址的位地址。类似于C语言中的宏定义,对选定位地址进行某特殊功能的命名。

格式为:sbit 命名功能 = 位地址

2. SFR Assembler Statement

Arguments sfr sfr_symbol = address;

Description The sfr statement defines a special function register:

  • Where

*sfr_symbol is the name of the Special Function Register (SFR) symbol to define.
address is the address of the SFR.*

The sfr statement allows you to define SFR data in a consistent manner with the Cx51 compiler. With this statement you may use a generic SFR register definition file for the Cx51 compiler and the Ax51 assembler.

Example
sfr P0 = 0x80;
sfr P1 = 0x90;

理解

sfr 定义特殊功能寄存器中的字节。类似于C语言中的宏定义,对选定字节地址进行某特殊功能的命名。

格式为:sfr 功能命名 = 地址(位地址首位)

3. 51中可位寻址区域

1)位寻址区
字节地址范围为 20H~2FH,
这16个单元(共计128位)的每一位都有一个对应位地址,
位地址范围为 00H~7FH。

2)SFR区
字节地址范围为80H~FFH,
字节地址30H~7FH为数据缓冲区,用户RAM区,
位地址范围紧接上述位寻址区位地址范围,SFR区位地址范围为 80H~FFH。

  • 注:凡是SFR中字节地址能被8整除的单元均能位寻址。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值