PIC and XC8 Compiler issue

Terryl picture Terryl · Dec 24, 2013 · Viewed 12.1k times · Source

Im sure Im missing something simple, and obvious, but I am tired of searching for the answer. Im using a PIC16F688 and XC8 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);

Answer

Alleen Wang picture Alleen Wang · Aug 25, 2014

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);
}