Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用具有LSBFIRST位顺序的shiftOut()将数据发送到Arduino中的MAX7219_Arduino - Fatal编程技术网

使用具有LSBFIRST位顺序的shiftOut()将数据发送到Arduino中的MAX7219

使用具有LSBFIRST位顺序的shiftOut()将数据发送到Arduino中的MAX7219,arduino,Arduino,我有以下代码: #define MAX7219_Data_IN 11 #define MAX7219_Chip_Select 9 #define MAX7219_Clock 13 void shift(byte send_to_address, byte send_this_data) { digitalWrite(MAX7219_Chip_Select, LOW); shiftOut(MAX7219_Data_IN, MAX7219_Clock, MSBFIRST, se

我有以下代码:

#define MAX7219_Data_IN 11
#define MAX7219_Chip_Select  9
#define MAX7219_Clock 13

void shift(byte send_to_address, byte send_this_data) 
{
    digitalWrite(MAX7219_Chip_Select, LOW);
    shiftOut(MAX7219_Data_IN, MAX7219_Clock, MSBFIRST, send_to_address);
    shiftOut(MAX7219_Data_IN, MAX7219_Clock, MSBFIRST, send_this_data);
    digitalWrite(MAX7219_Chip_Select, HIGH);
}

void init_max7219() //Setup of MAX7219 chip
{
    shift(0x0f, 0x00); //display test register - test mode off
    shift(0x0c, 0x01); //shutdown register - normal operation
    shift(0x0b, 0x07); //scan limit register - display digits 0 thru 7
    shift(0x0a, 0x0f); //intensity register - max brightness
    shift(0x09, 0x00); //decode mode register - No decode
}

void setup()
{
    pinMode(MAX7219_Data_IN, OUTPUT);
    pinMode(MAX7219_Chip_Select, OUTPUT);
    pinMode(MAX7219_Clock, OUTPUT);
    digitalWrite(MAX7219_Clock, LOW);
    init_max7219(); //init MAX2719 chip

    shift(1, B01110111);
}

void loop() { }

我使用shiftOut()将数据发送到MAX7219。我首先将MSB作为位序参数传递。它很好用。我使用Unoadusim并按预期将字母A置于位置1。但我在使用LSBFIRST时遇到问题:

void shift(byte send_to_address, byte send_this_data) 
{
    digitalWrite(MAX7219_Chip_Select, LOW);
    shiftOut(MAX7219_Data_IN, MAX7219_Clock, LSBFIRST, send_to_address);
    shiftOut(MAX7219_Data_IN, MAX7219_Clock, LSBFIRST, send_this_data);
    digitalWrite(MAX7219_Chip_Select, HIGH);
}

七个区段指示器上不显示任何内容。如何首先正确使用最低有效位?

为了首先使用LSBF,您需要更改传递给shiftOut的值。例如,将0x0f(B00001111)更改为0xf0(11110000),将0x0c(000011100)更改为0x30(00110000),以便最低有效位为第一位

#define MAX7219_Data_IN 11
#define MAX7219_Chip_Select  9
#define MAX7219_Clock 13

void shift(byte send_to_address, byte send_this_data) 
{
    digitalWrite(MAX7219_Chip_Select, LOW);
    shiftOut(MAX7219_Data_IN, MAX7219_Clock, LSBFIRST, send_to_address);
    shiftOut(MAX7219_Data_IN, MAX7219_Clock, LSBFIRST, send_this_data);
    digitalWrite(MAX7219_Chip_Select, HIGH);
}

void init_max7219() //Setup of MAX7219 chip
{
    shift(0xf0, 0x00); //display test register - test mode off
    shift(0x30, 0x80); //shutdown register - normal operation
    shift(0xd0, 0xe0); //scan limit register - display digits 0 thru 7
    shift(0x50, 0xf0); //intensity register - max brightness
    shift(0x90, 0x00); //decode mode register - No decode
}

void setup()
{
    pinMode(MAX7219_Data_IN, OUTPUT);
    pinMode(MAX7219_Chip_Select, OUTPUT);
    pinMode(MAX7219_Clock, OUTPUT);
    digitalWrite(MAX7219_Clock, LOW);
    init_max7219(); //init MAX2719 chip

    shift(0x80, B11101110);
}

void loop() { }

为了使用LSBFIRST,您需要更改传递给shiftOut的值。例如,将0x0f(B00001111)更改为0xf0(11110000),将0x0c(000011100)更改为0x30(00110000),以便最低有效位为第一位

#define MAX7219_Data_IN 11
#define MAX7219_Chip_Select  9
#define MAX7219_Clock 13

void shift(byte send_to_address, byte send_this_data) 
{
    digitalWrite(MAX7219_Chip_Select, LOW);
    shiftOut(MAX7219_Data_IN, MAX7219_Clock, LSBFIRST, send_to_address);
    shiftOut(MAX7219_Data_IN, MAX7219_Clock, LSBFIRST, send_this_data);
    digitalWrite(MAX7219_Chip_Select, HIGH);
}

void init_max7219() //Setup of MAX7219 chip
{
    shift(0xf0, 0x00); //display test register - test mode off
    shift(0x30, 0x80); //shutdown register - normal operation
    shift(0xd0, 0xe0); //scan limit register - display digits 0 thru 7
    shift(0x50, 0xf0); //intensity register - max brightness
    shift(0x90, 0x00); //decode mode register - No decode
}

void setup()
{
    pinMode(MAX7219_Data_IN, OUTPUT);
    pinMode(MAX7219_Chip_Select, OUTPUT);
    pinMode(MAX7219_Clock, OUTPUT);
    digitalWrite(MAX7219_Clock, LOW);
    init_max7219(); //init MAX2719 chip

    shift(0x80, B11101110);
}

void loop() { }