Re: MPLAB X build faIled問題

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

__DELAY_MS
, __DELAY_US, __DELAYWDT_US, __DELAYWDT_MS
Synopsis
__delay_ms
(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
Description
It is often more convenient to request a delay in time
-based terms, rather than in cycle
counts
. The macros __delay_ms(x) and __delay_us(x) are provided to meet this
need
. 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程式碼,試試看改寫到你的程式內
設定好震盪器頻率(_XTAL_FREQ)
可以參考compiler的使用手冊 差不多在349頁

可以這樣用

#define _XTAL_FREQ 8000000
#define delays_time 5
while(1){
//code
__delay_ms(delays_time);
//code
}

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

來自: http://www.microchip.com.tw/newbb/viewtopic.php?forum=18&topic_id=22526&post_id=79175