【问题标题】:microchip MPLAB X IDE v2.15 "can't generate code for this expression"microchip MPLAB X IDE v2.15“无法为此表达式生成代码”
【发布时间】:2014-09-09 23:16:40
【问题描述】:

我正在尝试编译一段简单的代码,但我遇到了一个错误“无法为这个表达式生成代码”。 我适应了来自“http://www.barrysoft.it/blog/midi-with-pic-ausart.html”的代码

有人能告诉我这个问题吗?

MPLAB X IDE v2.15 xc8 v1.32

midi.c:

 void midi_init(void)
 {
 /* MIDI uses 31250 baud/s serial speed */
 uart_init(19, 1, 0, 0 );        //<--- 
 }

midi.c:31: error: (712) can't generate code for this expression

uart.c:

 void uart_init(unsigned char spbrg, unsigned bit brgh, unsigned bit sync, unsigned bit parity)
 {

    // Setup the baud rate
    SPBRG = spbrg;

 // High speed baud rate
 BRGH = brgh;        ////

 // Synch or Async
 SYNC = sync;        ////

 // 8bit transmission
 TX9 = parity;        ////

 // Enable serial output
 SPEN = 1;

 // Enable UART out
 TXEN = 1;
 }

uart.c:29: error: (712) can't generate code for this expression

uart.c:32: error: (712) can't generate code for this expression

uart.c:35: error: (712) can't generate code for this expression

uart.h:

void uart_init(unsigned char spbrg, unsigned bit brgh,unsigned bit sync,unsigned bit parity);

无法解析标识符位,这似乎是 MPLAB IDE 错误,可以将其关闭。

【问题讨论】:

    标签: ide microcontroller microchip mplab


    【解决方案1】:

    这可能是编译器处理数据宽度低于处理器原生宽度的问题。

    一个简单的解决方法是使用宏而不是函数。这是可行的,因为您让编译器按照它认为合适的方式处理类型转换和文字数据,而不是强制它将位变量提交到内存位置(用于函数调用)。

    在 uart.h 中:

    #define uart_init( spbrg, brgh, sync, parity ) \
        SPBRG = spbrg;\
        BRGH = brgh;\
        SYNC = sync;\
        TX9 = parity;\
        SPEN = 1;\
        TXEN = 1
    

    *请注意,我故意省略了最后一行的 ';'这样宏就可以像函数一样被调用了。

    在 midi.c 中:没有变化...

    uart_init(19, 1, 0, 0 ); 
    

    【讨论】:

    • 我想了一个办法,但是这个信息非常有用,谢谢。
    猜你喜欢
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多