c - 将结构传递给 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]);
但是,编译后出现以下错误:
- #error cpstm8 ..\src\memory\flash.c:38(36+2) 无效的间接操作数
- #error cpstm8 ..\src\memory\flash.c:38(38) 参数类型不兼容
- #error cpstm8 ..\src\memory\flash.c:38(24+11) led_pattern undefined
这对我来说真的很困惑,我也尝试将指向结构的指针传递给函数,但我得到了同样的错误。任何帮助是极大的赞赏。我是编程新手,需要你的帮助。
先感谢您。最好的问候, Vouria
解决方案
我找到了答案。要在其他文件中使用结构数组,.C
我需要在该.C
文件中使用extern
.
推荐阅读
- php - PHP注册表单发布方法不起作用
- pattern-matching - Elixir:如果地图包含至少一个整数键,则模式匹配函数
- rest - 如何清除 ALM 12.5x REST API 在 HPQC 中打开的连接?
- java - Displaying JButton over DrawingComponent
- ios - 如何使用画外音点击位于另一个视图下方的视图
- android - 如何在 Android Studio 中更改按钮的文本,当它被点击时
- cassandra - 在 cassandra 3.11 生产集群上更改键空间以切换到 NetworkTopologyStrategy
- matlab - num2str((rng'* (sp(t)-sa(t))) + sa(t),'%2.2g')
- prolog - Why doesn't this clpfd query terminate until I add a redundant constraint?
- node.js - 角http错误状态0