Re: MPLAB X build faIled問題

作者 a16450 於 2019年01月13日 17:28:06

(x) // request a delay in milliseconds
__delay_us(x) // request a delay in microseconds
__delaywdt_ms(x) // request a delay in milliseconds
__delaywdt_us(x) // request a delay in microseconds
It is often more convenient to request a delay in time
-based terms, rather than in cycle
. The macros __delay_ms(x) and __delay_us(x) are provided to meet this
. These macros convert the time-based request into instruction cycles that can be
used with _delay
(n). In order to achieve this, these macros require the prior definition
of preprocessor macro _XTAL_FREQ
, which indicates the system frequency. This
macro should equate to the oscillator frequency
(in hertz) used by the system. Note that
this macro only controls the behavior of these delays
and does not affect the device
execution speed
On PIC18 devices only, you can use the alternate WDT-form of these functions, which
uses the CLRWDT instruction
as part of the delay code. See the _delaywdt function.
The macro argument must be a constant expression. An error will result if these macros
are used without defining the oscillator frequency symbol
, the delay period requested
is too large
, or the delay period is not a constant.

這是xc8 compiler內建的delay程式碼,試試看改寫到你的程式內
可以參考compiler的使用手冊 差不多在349頁


#define _XTAL_FREQ 8000000
#define delays_time 5

以上就是delay 5ms時間但是你震盪器一定要設定對