3055 views|8 replies

411

Posts

9

Resources
The OP
 

How is "u8 Dat2:7;" written in the structure? What does it mean? [Copy link]

Look at the following program. What is the writing method of "u8 Dat2: 7;" and what does it mean? How can the structure be assigned values in this way?

typedef struct {
// u32 Dat : 23;
// u32 S : 1;
u8 Dat0;
u8 Dat1;
u8 Dat2 : 7;
u8 S : 1;
} sDF09;

This post is from stm32/stm8

Latest reply

Really, I rarely use this method.   Details Published on 2022-5-30 21:39
 

5303

Posts

454

Resources
2
 

Baidu: Bit Domain

This post is from stm32/stm8
 
 

6742

Posts

2

Resources
3
 

This is how many places this variable occupies of this variable type.

u32 Dat:23, Dat occupies 23 of the 32 bits.

This post is from stm32/stm8
 
 

2549

Posts

0

Resources
4
 

The main reason is that the space of current MCU is relatively large, so it is rare to save this amount of space, unless it is a large project.

This post is from stm32/stm8

Comments

真的,我實際上很少使用這種方式了  Details Published on 2022-5-30 21:39
 
 
 

224

Posts

0

Resources
5
 

It is a bit segment. Sometimes, you don't need a complete byte to store information, just a few binary bits. This is really not commonly used.

This post is from stm32/stm8
 
 
 

7422

Posts

2

Resources
6
 

Bit fields and register operations are very convenient in many places.

This post is from stm32/stm8
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

26

Posts

0

Resources
7
 

Bitfield operations.

Advantages: convenient operation.

Normally, the smallest data type in C language is char, which is a byte. If you want to operate the bits in the byte, you need to shift, carry or bitwise AND operations, which is troublesome to use. Therefore, C language adds bit field syntax, which can add a name to each bit field for easy operation.

For example

typedef

{

uint8_t power_valid: 1;

uint8_t power_mode : 4;

uint8_t gear_position :3;

}status_t;

Disadvantages: Reduced portability. Once the chip bit order is different, all bit field definitions need to be adjusted.

The bit order is the definition of the bit arrangement, which is divided into MSB (Most Significant Bit) and LSB (Most Significant Bit), that is, whether to put the highest bit first (the bit order is from high to low) or the lowest bit first (the bit order is from low to high). For example, for a byte in physical memory, if its value is binary 1000 0000, MSB will interpret it as 0x80, and LSB will interpret it as 0x01. If you directly use shift, bitwise AND, bitwise OR and other operators to operate, this problem will not occur.

This post is from stm32/stm8
 
 
 

10

Posts

1

Resources
8
 

I've learned a lot! It's very creative. As a student, I like it very much and benefited a lot from the practice.

This post is from stm32/stm8
 
 
 

114

Posts

6

Resources
9
 
Digital Leaf published on 2022-4-20 14:01 The main reason is that the space of MCU is relatively large now, so it is rare to save this amount of space, unless it is a large project

Really, I rarely use this method.

This post is from stm32/stm8
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Studying Things to Gain Knowledge 05: Dimensions and Elementary Functions

What is dimension? It is usually taught in middle school physics courses and again in university physics courses. Howev ...

【McQueen Trial】Comparison of the accuracy of several ultrasonic sensor programs of McQueen

Purpose Compare the test accuracy of several ultrasonic sensors to provide a reference for everyone's use. Methods Write ...

[Project source code] Digital tube companion - binary to BCD

This article and design code were written by FPGA enthusiast Xiao Meige. Without the author's permission, this article ...

Design of real-time image test device based on LVDS technology

Design of real-time image test device based on LVDS technology

C language uses binary tree to parse polynomials and evaluate

It mainly realizes the analysis of polynomial data calculation. If there is a need to make a simple calculator based on ...

LPS27HHTW MEMS Pressure Sensor

The LPS27HHTW MEMS pressure sensor is an ultra-compact piezoresistive absolute pressure sensor that can be used as a dig ...

Raspberry Pi Bluetooth Basics - Use of bluezero library

This post was last edited by lb8820265 on 2021-8-8 22:50 There are many libraries for operating Bluetooth in Linux s ...

CC2500 Migration Instructions

Be applicable : Applicable to TI chip CC2500 full series modules How to transplant ? The parts to be ported are in rf_ ...

Embedded Qt-Make a stopwatch

This post was last edited by DDZZ669 on 2022-8-7 15:55 Previous article: Embedded Qt - Write and run your first ARM-Qt ...

Successfully deployed deep learning gait recognition algorithm on Allwinner V853 platform

Xin Zhe, a student from the Communication Research Group of Beijing Institute of Technology, successfully transplanted t ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list