理解 MSBFIRST(最高有效位)和 LSBFIRST(最低有效位)

在本文中,先解释 MSB(最高有效位)和 LSB(最低有效位)的概念,以及 MSBFIRST 和 LSBFIRST。然后展示了 MSBFIRST 和 LSBFIRST 的使用如何影响移位寄存器的输出。

Understanding MSBFIRST (Most Significant Bit) and LSBFIRST (Least Significant Bit)

理解 MSBFIRST(最高有效位)和 LSBFIRST(最低有效位)

理解 MSBFIRST(最高有效位)和 LSBFIRST(最低有效位)

In this article, we explain the concepts of MSB (Most Significant Bit) and LSB (Least Significant Bit), along with MSBFIRST and LSBFIRST. Finally, we provide a demonstration of how the use of MSBFIRST and LSBFIRST affects the outputs of shift registers.
在本文中,我们解释了 MSB(最高有效位)和 LSB(最低有效位)的概念,以及 MSBFIRST 和 LSBFIRST。最后,我们展示了 MSBFIRST 和 LSBFIRST 的使用如何影响移位寄存器的输出。

MSB and LSB

最高有效位和最低有效位

The MSB, or Most Significant Bit, refers to a specific bit in a binary number. The Most Significant Bit, holds the higher weight or value in the binary representation. It is also known as the left-most bit or higher-order bit. In contrast, the LSB, or Least Significant Bit, refers to the lowest value bit in a number, making it the right-most bit or the low-order bit.
最高有效位(MSB)是指二进制数中的一个特定位。最高有效位在二进制表示中具有更高的权重或值,也被称为最左边的位或高位。相反,最低有效位(LSB)是指一个数中值最低的位,因此它是最右边的位或低位。

理解 MSBFIRST(最高有效位)和 LSBFIRST(最低有效位)

MSBFIRST and LSBFIRST

In the serial transfer of data in electronics, when transmitting a binary number, we usually have to decide about whether to start the transfer from the leftmost or rightmost bit. This is referred to as MSBFIRST and LSBFIRST.
在电子学中,进行数据的串行传输时,当我们传输一个二进制数时,通常需要决定是从最左边的位还是最右边的位开始传输。这被称为 MSBFIRST 和 LSBFIRST。

For example, consider the shiftOut function in Arduino, which transfers a byte of data one bit at a time. The function includes a parameter (bitOrder) that allows us to specify whether the byte should be sent starting from its MSB or LSB.
例如,考虑 Arduino 中的 shiftOut 函数,它一次传输一个字节的数据,每次一位。该函数包含一个参数(bitOrder),允许我们指定是从字节的最高有效位还是最低有效位开始发送。

shiftOut(dataPin, clockPin, bitOrder, value)

Configuring this parameter becomes more important when working with various digital components, such as shift registers. For instance, transferring a byte to a shift register starting from its Most Significant Bit will yield a different result compared to starting from its Least Significant Bit.
当使用各种数字元件(如移位寄存器)时,配置此参数变得更加重要。例如,从最高有效位开始将一个字节传输到移位寄存器,与从最低有效位开始传输,结果会有所不同。

74HC595 Shift Register with MSBFIRST and LSBFIRST

74HC595 移位寄存器与 MSBFIRST 和 LSBFIRST

In this section, we explore two distinct examples of utilizing the shiftOut function with MSBFIRST and LSBFIRST parameters to write a binary number to the 74HC595 shift register. The same principles apply across all other shift register models.
在本节中,我们探讨了两个使用 shiftOut 函数与 MSBFIRST 和 LSBFIRST 参数将二进制数写入 74HC595 移位寄存器的不同示例。这些原理适用于所有其他移位寄存器型号。

In the code below, we write the 8 - bit binary number ‘01001010’ to the shift register with MSBFIRST configuration:
在下面的代码中,我们将 8 位二进制数 ‘01001010’ 以 MSBFIRST 配置写入移位寄存器:

Shift Register - MSBFIRST Example#define SERIAL_PIN 4
#define LATCH 3
#define CLOCK_PIN 2

void setup() {
  pinMode(SERIAL_PIN, OUTPUT);
  pinMode(LATCH, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT);

  digitalWrite(LATCH, LOW);
  shiftOut(SERIAL_PIN, CLOCK_PIN, MSBFIRST, B01001010);
  digitalWrite(LATCH, HIGH);
}

void loop() { }

In this configuration, the shift register’s outputs will have the leftmost digit of the binary number ‘01001010’ in the Q7 output, with its rightmost digit at the Q0 output after the transfer.
在这种配置中,移位寄存器的输出将在 Q7 输出端有二进制数 ‘01001010’最左边的数字,在传输后其最右边的数字将在 Q0 输出端。

理解 MSBFIRST(最高有效位)和 LSBFIRST(最低有效位)

Similarly, the code snippet below, illustrates writing the binary number ‘01001010’ to the shift register, but this time with LSBFIRST configuration:
类似地,下面的代码片段展示了将二进制数 ‘01001010’ 写入移位寄存器,但这次使用 LSBFIRST 配置:

Shift Register - LSBFIRST Example#define SERIAL_PIN 4
#define LATCH 3
#define CLOCK_PIN 2

void setup() {
  pinMode(SERIAL_PIN, OUTPUT);
  pinMode(LATCH, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT);

  digitalWrite(LATCH, LOW);
  shiftOut(SERIAL_PIN, CLOCK_PIN, LSBFIRST, B01001010);
  digitalWrite(LATCH, HIGH);
}

void loop() { }

With LSBFIRST, we will have a different outcome, the shiftOut function will begin to transfer the number to the shift register by beginning from its rightmost digit. This way, the rightmost digit of the number ‘01001010’ will be located in the Q7 output, while its leftmost digit will appear at the Q0 output after the transfer.
使用 LSBFIRST 时,结果会有所不同,shiftOut 函数将从数字的最右边的数字开始,将数字传输到移位寄存器。这样,数字 ‘01001010’最右边的数字将位于 Q7 输出端,而其最左边的数字将在传输后出现在 Q0 输出端。

理解 MSBFIRST(最高有效位)和 LSBFIRST(最低有效位)


- 本文内容来自网络,如有侵权,请联系本站处理。

07-09   阅读(0)   评论(0)
 标签: 创客 Arduino

涨知识
74HC595

74HC595是一个8位串行输入、并行输出的位移缓存器。并行输出为三态输出。

评论:
相关文章
Arduino 和 TB6612FNG 驱动直流电机

TB6612是一款双路H桥型的直流电机驱动芯片,可以驱动两个直流电机并且控制其转速与方向,输入电压在3V~12V,因此在集成化、小型化的电机控制系统中,它可以作为理想的电机驱动器件。


Arduino-ESP32 Preferences库使用详解

Arduino-ESP32项目提供的Preferences库是一个专为ESP32设计的非易失性存储解决方案,它替代了传统的Arduino EEPROM库,提供了更强大、更可靠的数据存储功能。




Arduino 8×8 共阳极LED点阵显示(74HC595)

本文主要介绍8×8 共阳极LED点阵显示实验,分别是:介绍74HC595点阵模块、点阵显示指定行列LED、点阵显示汉字。


Arduino 上使用红外遥控器

日常生活中我们会接触到各式各样的遥控器,电视机、空调、机顶盒等都有专用的遥控器,很多智能手机也在软硬件上对红外遥控做了支持,可以集中遥控绝大部分家用电器。本篇介绍红外遥控相关原理及应用,通过红外遥控器控制 Uno 板载 LED 灯。


Arduino 驱动 8×8 LED点阵屏

LED点阵屏由LED发光二极管组成,通过控制LED亮灭来显示文字、图片、动画、视频等,被广泛应用于公共场合做信息展示,如广告屏、公告牌等。


ESP32 使用DAC模拟输出完成两路呼吸灯

ESP32的DAC函数可以实现真正的模拟输出。


在 ESP32 上使用 LEDC (PWM)

ESP32 没有Arduino输出 PWM 的 analogWrite(pin, value) 方法,取而代之的 ESP32 有一个 LEDC 来实现PWM功能。


《米思齐实战手册:Arduino图形化编程指南》

本书由少年创学院联合创始人兼院长、知名创客程晨撰写,以Arduino作为硬件平台,介绍了使用米思齐(Mixly)软件进行程序开发的方法。

搜索
小鹏STEM教研服务

专属教研服务系统,助您构建STEM课程体系,打造一站式教学环境。