51 single chip microcomputer----sbit

Publisher:智慧启迪Latest update time:2015-10-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
sbit: defines the bit variable of the special function register.

Typical application: sbit P0_0=P0^0; // defines P0_0 as the first bit of port P0 for bit operation.

Usage:​

In C language, if you write P1.0 directly, the C compiler cannot recognize it, and P1.0 is not a legal C language variable name, so you have to give it another name, here it is called P1_0, but is P1_0 the same as P1.0? You think so, but the C compiler doesn't think so, so you have to establish a connection between them. Here, the Keil C keyword sbit is used to define it. There are three uses of 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

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 first using sfr

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

Therefore, here we use sbit P1_0=P1^0; to define the symbol P1_0 to represent the P1.0 pin. If you want, you can also use a name like P10, as long as you change it accordingly in the following program.

sbit and bit:

​sbit must be defined at the outermost, that is, it must be defined as an external variable. sbit defines the bit of SFR (special function register)

sbit is more like a type definition than a variable definition.

sbit: just an illustrative note

A bit can be defined externally or internally.

Reference link: http://baike.baidu.com/link?url=R_fzVbhmSpnJIcMdnyH1kJFNiJRW2wMLb-zjl9gr-Ht779OltInqwjJpibGxATyR7pLLTOMI4EQLNLaOCKZ1iK​

Reference address:51 single chip microcomputer----sbit

Previous article:51 single chip microcomputer——_crol_
Next article:Design and implementation of an intelligent street lamp energy-saving controller

Recommended ReadingLatest update time:2024-11-16 04:21

The difference between bit and sbit
Introduction: bit and sbit are both variable types extended by C51. 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. Unless you specify, the address is random. This address is the entire addressable space
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号