AVRStudio 6 delay函數(shù)錯誤的解決方法
之前一直用winavr作為avr開發(fā)工具,AVRstudio 5以后的版本直接包含了GCCAVR工具鏈,開發(fā)環(huán)境也變化比較大,總體還是非常給力的,所以一直跟著版本更新,原來的程序直接拷貝編譯無法通過,出現(xiàn)最多的是這個錯誤:
錯誤 __builtin_avr_delay_cycles expects an integer constant.
經(jīng)過查找發(fā)現(xiàn)是頭文件版本更新所致。delay.h文件214行說明如下:
Note: The new implementation of _delay_us(double __us) with
__builtin_avr_delay_cycles(unsigned long) support is not backward compatible.
User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay.
Also, the backward compatible
algorithm will be chosen if the code is compiled in a freestanding
environment (GCC option c -ffreestanding), as the math functions
required for rounding are not available to the compiler then.
這樣解決方法就明顯了,新的定義和之前的不兼容,因此調(diào)用頭文件之前加入define __DELAY_BACKWARD_COMPATIBLE__ 即可。
最后還是得感慨下AVR已經(jīng)落伍了,沒啥優(yōu)勢了,以后的項目8位的AVR不用考慮了,仿真器還那么貴,唉。