Home > Common Problem > body text

What does sbit mean?

(*-*)浩
Release: 2019-07-22 11:30:12
Original
8622 people have browsed it

sbit is a bit variable that defines a special function register. Both bit and sbit are variable types extended by C51.

What does sbit mean?

Typical application is: sbit P0_0=P0^0;//That is, define P0_0 as the first bit of the P0 port for bit operations. (Recommended learning: PHP video tutorial)

bit is similar to int char, except that char=8 bits and bit=1 bit. They are all variables, and the compiler assigns addresses during the compilation process.

Usage

In C language, if you write P1.0 directly, the C compiler will not recognize it, and P1.0 is not a legal C language variable. name, so we have to give it another name. The name here is P1_0, but is P1_0 the same as P1.0? You think so, but the C compiler doesn't think so, so they must be connected. The Keil C keyword sbit is used here to define it. There are three ways to use sbit:

The first method: sbit bit variable Name = address value

The second method: sbit bit variable name = SFR name ^ variable bit address value

The third method: sbit bit variable name = SFR address value ^ variable bit address Value

For example, the following three methods can be used to define OV in PSW:

sbit OV=0xd2 (1) Description: 0xd2 is the bit address value of OV

sbit OV =PSW^2 (2) Note: PSW must be defined with sfr first

sbit OV=0xD0^2 (3) Note: 0xD0 is the address value of PSW

, so sbit is used here P1_0=P1^0; is defined to use the symbol P1_0 to represent the P1.0 pin. If you want, you can also give it a name like P10, as long as you change it in the following program.

sbit must be defined at the outermost level, which means it must be defined as an external variable. sbit defines the bit of the SFR (Special Function Register)

sbit is the corresponding bit A bit in the addressable space, bit addressable area: 20H~2FH. Once a definition like sbit xxx = REGE^6 is used, this sbit quantity determines the address. sbit is mostly used in registers to facilitate operations on a certain bit of the register.

The sbit bit register is a bit-addressable absolute address target. The compiler will not change the location after definition.

For more PHP related technical articles, please visit the PHP Graphic Tutorial column to learn!

The above is the detailed content of What does sbit mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!