Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
C++ 赋值数组时函数不返回_C++_Arduino_Embedded_Arduino Due - Fatal编程技术网

C++ 赋值数组时函数不返回

C++ 赋值数组时函数不返回,c++,arduino,embedded,arduino-due,C++,Arduino,Embedded,Arduino Due,所以我遇到了一个奇怪的问题,在无限循环中,调用的函数没有返回,因此停止了循环 每次循环循环时,LED都会闪烁: while (true) { loop.set(1); hwlib::wait_ms(100); loop.set(0); hwlib::wait_ms(100); // turns led on and off with 100ms delay hwlib::wait_ms(250); // arduino wait's 250ms before c

所以我遇到了一个奇怪的问题,在无限循环中,调用的函数没有返回,因此停止了循环

每次循环循环时,LED都会闪烁:

 while (true) {
        loop.set(1); hwlib::wait_ms(100); loop.set(0); hwlib::wait_ms(100); // turns led on and off with 100ms delay
        hwlib::wait_ms(250); // arduino wait's 250ms before continuing 

        ipass.show(); // if this function is commented out the loop continues. If it is called the loop stalls here.
    }
function show()中包含以下代码。 当我注释掉for循环中的所有内容时,函数调用将按其应该的方式返回。当我将数组赋值行保留在那里时,代码暂停

void layer::show() {
    for (int i = 0; i < 8; i++) {
        pos_data = { 0 };

        pos_data[ i ] = 1;
        neg_data = matrix[ i ];

        for (int j = 0; j < 8; j++) {
            if (neg_data[j] == 0) { neg_data[j] = 1; } 
            else if (neg_data[j] == 1) { neg_data[j] = 0; }
        }

        write_registers();
        hwlib::wait_ms(5);
    }
}
layer.cpp

#include "hwlib.hpp"
#include "layer.hpp"
#include "vector.hpp"
#include "shift_register.hpp"

layer::layer( int layer_id, hwlib::pin_out &pos_pin, hwlib::pin_out &neg_pin, hwlib::pin_out &output_enable ):
    layer_id( layer_id ),
    pos_reg( shift_register( pos_pin, output_enable )), 
    neg_reg( shift_register( neg_pin, output_enable ))
{
    pos_reg.disable();
    neg_reg.disable();
}

layer::layer(): 
    layer_id( -1 ), pos_reg( shift_register() ), neg_reg( shift_register() )
{}

void layer::show() {
    for (int i = 0; i < 8; i++) {
        pos_data = { 0 };

        pos_data[ i ] = 1;
        neg_data = matrix[ i ];

        for (int j = 0; j < 8; j++) {
            if (neg_data[j] == 0) { neg_data[j] = 1; } 
            else if (neg_data[j] == 1) { neg_data[j] = 0; }
        }

        write_registers();
        hwlib::wait_ms(5);
    }
}

void layer::clock( int amount, int delay ) {
    auto clock = hwlib::target::pin_out( hwlib::target::pins::d4 );
    for ( int i = 0; i < amount; i ++) {
        clock.set( 1 );
        hwlib::wait_ms( delay / 2 );
        clock.set( 0 );
        hwlib::wait_ms( delay / 2 );
    }
}

void layer::set_coordinate( vector v, unsigned int value ) {
    // Transate coordinate system vector to array vector
    matrix[ 7-v.y ][ v.x ] = value;
}

void layer::write_registers() {
    pos_reg.disable(); neg_reg.disable();
    for (int i = 0; i < 8; i++) {
        pos_reg.set( pos_data [ 7-i ] );
        neg_reg.set( neg_data [ 7-i ] );
        clock();
    }
    clock();
    pos_reg.enable(); neg_reg.enable();
}

void layer::offer_data( unsigned int index ) {

}
#ifndef LAYER_HPP
#define LAYER_HPP

#include "hwlib.hpp"
#include "shift_register.hpp"
#include "vector.hpp"
#include <array>

class layer {
private:
    int layer_id;
    std::array<int, 8> pos_data;
    std::array<int, 8> neg_data;
    shift_register pos_reg;
    shift_register neg_reg;
    std::array< std::array< int, 8>, 8> matrix;
public:
    layer( int layer_id, hwlib::pin_out &pos_pin, hwlib::pin_out &neg_pin, hwlib::pin_out &output_enable );
    layer();
    void set_coordinate( vector v, unsigned int value );
    void offer_data( unsigned int index );
    void show();
    void clock( int amount = 1, int delay = 0 );
    void write_registers();
};

#endif //LAYER_HPP
#包括“hwlib.hpp”
#包括“layer.hpp”
#包括“vector.hpp”
#包括“移位寄存器.hpp”
layer::layer(int layer_id,hwlib::pin_out&pos_pin,hwlib::pin_out&neg_pin,hwlib::pin_out&output_enable):
层id(层id),
pos_寄存器(移位寄存器(pos_引脚,输出启用)),
负寄存器(移位寄存器(负引脚,输出启用))
{
pos_reg.disable();
负注册禁用();
}
图层::图层()
层id(-1)、位置寄存器(移位寄存器()、负寄存器(移位寄存器())
{}
void层::show(){
对于(int i=0;i<8;i++){
pos_data={0};
pos_数据[i]=1;
neg_数据=矩阵[i];
对于(int j=0;j<8;j++){
如果(neg_数据[j]==0){neg_数据[j]=1;}
如果(neg_数据[j]=1){neg_数据[j]=0;}
}
写入寄存器();
hwlib::wait_ms(5);
}
}
无效层::时钟(整数金额,整数延迟){
自动时钟=hwlib::target::pin_out(hwlib::target::pins::d4);
对于(int i=0;i
layer.hpp

#include "hwlib.hpp"
#include "layer.hpp"
#include "vector.hpp"
#include "shift_register.hpp"

layer::layer( int layer_id, hwlib::pin_out &pos_pin, hwlib::pin_out &neg_pin, hwlib::pin_out &output_enable ):
    layer_id( layer_id ),
    pos_reg( shift_register( pos_pin, output_enable )), 
    neg_reg( shift_register( neg_pin, output_enable ))
{
    pos_reg.disable();
    neg_reg.disable();
}

layer::layer(): 
    layer_id( -1 ), pos_reg( shift_register() ), neg_reg( shift_register() )
{}

void layer::show() {
    for (int i = 0; i < 8; i++) {
        pos_data = { 0 };

        pos_data[ i ] = 1;
        neg_data = matrix[ i ];

        for (int j = 0; j < 8; j++) {
            if (neg_data[j] == 0) { neg_data[j] = 1; } 
            else if (neg_data[j] == 1) { neg_data[j] = 0; }
        }

        write_registers();
        hwlib::wait_ms(5);
    }
}

void layer::clock( int amount, int delay ) {
    auto clock = hwlib::target::pin_out( hwlib::target::pins::d4 );
    for ( int i = 0; i < amount; i ++) {
        clock.set( 1 );
        hwlib::wait_ms( delay / 2 );
        clock.set( 0 );
        hwlib::wait_ms( delay / 2 );
    }
}

void layer::set_coordinate( vector v, unsigned int value ) {
    // Transate coordinate system vector to array vector
    matrix[ 7-v.y ][ v.x ] = value;
}

void layer::write_registers() {
    pos_reg.disable(); neg_reg.disable();
    for (int i = 0; i < 8; i++) {
        pos_reg.set( pos_data [ 7-i ] );
        neg_reg.set( neg_data [ 7-i ] );
        clock();
    }
    clock();
    pos_reg.enable(); neg_reg.enable();
}

void layer::offer_data( unsigned int index ) {

}
#ifndef LAYER_HPP
#define LAYER_HPP

#include "hwlib.hpp"
#include "shift_register.hpp"
#include "vector.hpp"
#include <array>

class layer {
private:
    int layer_id;
    std::array<int, 8> pos_data;
    std::array<int, 8> neg_data;
    shift_register pos_reg;
    shift_register neg_reg;
    std::array< std::array< int, 8>, 8> matrix;
public:
    layer( int layer_id, hwlib::pin_out &pos_pin, hwlib::pin_out &neg_pin, hwlib::pin_out &output_enable );
    layer();
    void set_coordinate( vector v, unsigned int value );
    void offer_data( unsigned int index );
    void show();
    void clock( int amount = 1, int delay = 0 );
    void write_registers();
};

#endif //LAYER_HPP
\ifndef层\u水电站
#定义图层\u水电站
#包括“hwlib.hpp”
#包括“移位寄存器.hpp”
#包括“vector.hpp”
#包括
类层{
私人:
int-layer_-id;
std::数组pos_数据;
std::数组负_数据;
移位寄存器位置寄存器;
移位寄存器负寄存器;
std::array,8>矩阵;
公众:
层(int-layer_-id,hwlib::pin_-out&pos_-pin,hwlib::pin_-out&neg_-pin,hwlib::pin_-out&output_-enable);
层();
void set_坐标(向量v,无符号整数值);
无效报价单数据(无符号整数索引);
void show();
无效时钟(整数金额=1,整数延迟=0);
无效写_寄存器();
};
#endif//LAYER_水电站

pos_数据是如何声明的?@Frank I用layer.hpp更新了帖子。那里调用非标准函数的代码太多了,您没有显示源代码。你需要专注于生成一个-一个小的自包含的代码示例,其他人可以使用它来获得相同的症状。当你在调试器中启动它时,检查程序挂起在哪一行。除此之外,C++喜欢屠杀堆栈。将
l1
分配为静态,以便查看使用了多少RAM。它可能只是一个8位CRAP MCU上使用C++引起的堆栈溢出。“连续重排”不需要内存。你的假设没有根据;最好不要让他们,让别人决定什么可能是错误的。