This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430FR2355:从另一个头文件访问 main.h 中的枚举类型?

Guru**** 2387080 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1163236/msp430fr2355-accessing-enum-type-in-main-h-from-another-header-file

器件型号:MSP430FR2355

您好...

我在 main.h 中具有以下 typedef (它是易失性的、状态与 i2c ISR 相关联、后者也在 main 中)。

typedef __vo enum {I2CIDLE, I2CWRITE, I2CREAD, I2CRESTART, I2CSTOP, I2CNACK} i2cCause;

然后、我在 main.h 中包含的另一个 h 文件中有一个函数

void positionLCDCursor(uint8_t row, uint8_t column)
{
    extern uint8_t lcd_rgb_data[];
    extern __vo enum i2cCause i2cstate;
    extern uint8_t *pI2CStream;

    uint8_t line;
    lcd_rgb_data[0] = 0x80;
    line = (row == 1)? 0x80 : (row == 2)? 0x40 :(row == 3)? 0x14 : 0x54;
    lcd_rgb_data[1] = line | column;

    i2cstate = I2CWRITE;
    sendI2C_data(pI2CStream, 2, LCD_12C_ADDRESS);
}

由于无法识别 I2CWRITE 行,代码将无法生成...请参阅下面的错误:

"../driver/source/lcd.c", line 22: error #20: identifier "I2CWRITE" is undefined
"../driver/source/lcd.c", line 22: error #138: expression must be a modifiable lvalue

有人能告诉我如何解决这个问题吗?  将 i2cstate 变量移动到驱动程序是没有意义的,因为它与 main 中的上层 ISR 相关联..... 即使如此、如果我尝试将其移动到驱动程序 h 文件、我也会遇到另一个错误。

"../driver/source/lcd.c", line 22: error #138: expression must be a modifiable lvalue

谢谢

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Steve、

    这似乎是一个范围问题、当您的枚举位于 main 中但未包含在头文件中时、头文件不知道从何处获取此枚举。 如果您希望在该文件之外找到变量/函数的声明/初始化、则需要使用 extern 关键字。

    错误位于第22行、但您的帖子中未包含第22行。 您能否在 LCD.c 中发送相关函数的屏幕截图

    此致、

    Luke

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    你好,Luke。。。

    是的,这是一个外部的问题...我四处移动了东西,一切都在工作...

    谢谢你