首页 > 解决方案 > 将结构传递给 Cosmic 编译器和 STM8 中的函数时出现“无效的间接操作数”错误

问题描述

我正在使用 Cosmic 编译器和 ST Visual Develop 为 stm8 编写固件。我使用 astruct 如下:

typedef enum
{
    lcBlack = 0,
    lcRed,
    lcGreen,
    lcOrange
}
led_color_t;

    PUBLIC typedef enum
{
    lppEmpty,
    lppStartup,
    lpp_volt_off,
    lpp_volt_warn,
    lpp_volt_over,
    lpp_volt_under,
    lpp_volt_drop,
    lppPause,
    lppHY,
    lppMLZ,
    lppTD,
    lppOnOK,
    lppOff,
    lppLixilTestTouch
}
led_name_t;


typedef struct
{
    uint8_t             enable;
    led_name_t      led_name;
    led_color_t     led_color;
    uint8_t             prio;
    uint16_t            t_on_0;
    uint16_t            t_off_0;
    uint8_t             cnt_0;
    uint16_t            t_on_1;
    uint16_t            t_off_1;
    uint8_t             cnt_1;
    uint16_t            t_1;
    uint16_t            t_2;
}
led_patt_t;

然后我定义并初始化一个结构数组,如下所示:

 led_patt_t led_pattern[73] = {
{0, lppEmpty,           lcBlack,       0,      0,       0,      0,      0,       0,      0,      0,       0},
{0, lppStartup,           lcRed,     255,    100,     100,     10,      0,       0,      0,      0,     500},
{1, lpp_volt_off,         lcRed,     210,    100,     100,      2,      0,       0,      0,      0,    1100},
{1, lpp_volt_warn,        lcRed,     210,    150,     150,      2,      0,       0,      0,      0,    1300} 
... };

接下来我需要定义一个使用结构数组成员的函数,如下所示:

result_t led_pattern_request (led_patt_t led_patt){       
{
    
led_private.pattern_current.color[0]            = led_patt.led_color;
led_private.pattern_current.color[1]            = led_patt.led_color;
led_private.pattern_current.priority            = led_patt.prio;
led_private.pattern_current.time_on_25ms[0]     = (uint8_t)led_patt.t_on_0;
.
.
.
}

在哪里

led_data_t led_private;

然后在我的 main 中,我将上述函数调用如下:

led_pattern_request (led_pattern[17]);

但是,编译后出现以下错误:

这对我来说真的很困惑,我也尝试将指向结构的指针传递给函数,但我得到了同样的错误。任何帮助是极大的赞赏。我是编程新手,需要你的帮助。

先感谢您。最好的问候, Vouria

标签: cstm8

解决方案


我找到了答案。要在其他文件中使用结构数组,.C我需要在该.C文件中使用extern.


推荐阅读