PIC and XC8 Compiler issue
Solution 1
They are right, the problem was experienced by older versions of the IDE's. I have found it helpful to use:
while(1){
//Invert LED state
LED = !LED;
//Delay ~1 second (4MHz Internal Clock)
_delay(1000000); //specify clock cycles directly
}
To solve the problem.
Solution 2
Please include "htc.h"
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <htc.h>
#define _XTAL_FREQ 20000000
int main(int argc, char** argv) {
_delay_ms(4);
return (EXIT_SUCCESS);
}
Solution 3
What does it mean "it does not accept the command"? Compiler cannot find function _delay_ms()
? Maybe you should use proper name with two underscores __delay_ms()
?
Moreover, why you do not close main function with }
? It is only a typo in your post or in your real code?
Terryl
Hello, I am a mechanical engineer by trade, but have always been interested in coding and software. I think it is silly to "specialize". To make really great things, a knowledge of how all the pieces fit is necessary! I am interested in all types of coding too. Embedded and Control coding first and foremost, but also web and general software as well. Cheers
Updated on June 04, 2022Comments
-
Terryl almost 2 years
Im sure Im missing something simple, and obvious, but I am tired of searching for the answer. Im using a
PIC16F688
andXC8
compiler.The compiler user manual says that there is a
delay function __delay_ms()
. It says that_XTAL_FREQ
must be defined.Here is my code, but it does not accept the command. What is wrong?
#include <stdio.h> #include <stdlib.h> #define _XTAL_FREQ 20000000 #include<xc.h> int main(int argc, char** argv) { _delay_ms(4); return (EXIT_SUCCESS);