EMBEDDED FOR US
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Delay function error in MPLAB X using hitech ccompiler PICC 9.83 plugin

2 posters

Go down

Delay function error in MPLAB X using hitech ccompiler PICC 9.83 plugin Empty Delay function error in MPLAB X using hitech ccompiler PICC 9.83 plugin

Post  Skyfall Thu Aug 16, 2012 1:35 am

Delay function error in MPLAB X using hitech ccompiler PICC 9.83 plugin gives error tell me what to do the code as under:

#include<htc.h>
#include<pic.h>


void main(void){

__delay_ms(50); //delay 50 ms
for(;;); //do forever
}

error: after compilation unable to resolve identifier


could anyone help!!!
Skyfall
Skyfall

Posts : 4
Join date : 2012-08-16
Location : india

Back to top Go down

Delay function error in MPLAB X using hitech ccompiler PICC 9.83 plugin Empty Delay function error in MPLAB X using hitech ccompiler PICC 9.83 plugin

Post  Admin Thu Aug 16, 2012 2:18 am

do this add below code to main.c

Code:


#include<PIC16F72.h>
#include"htc.h"
#include "delay.h"


void main(void) {
    DelayMs(50);  //delay

while(1);
}


make a header file delay.h and copy below code into it:

Code:


/*
 *   Delay functions for HI-TECH C on the PIC
 *
 *   Functions available:
 *      DelayUs(x)   Delay specified number of microseconds
 *      DelayMs(x)   Delay specified number of milliseconds
 *
 *   Note that there are range limits: x must not exceed 255 - for xtal
 *   frequencies > 12MHz the range for DelayUs is even smaller.
 *   To use DelayUs it is only necessary to include this file; to use
 *   DelayMs you must include delay.c in your project.
 *
 */

/*   Set the crystal frequency in the CPP predefined symbols list in
   HPDPIC, or on the PICC commmand line, e.g.
   picc -DXTAL_FREQ=4MHZ
   
   or
   picc -DXTAL_FREQ=100KHZ
   
   Note that this is the crystal frequency, the CPU clock is
   divided by 4.

 *   MAKE SURE this code is compiled with full optimization!!!

 */
#ifndef DelayUs            //-- Stop Multipule entrys of this code!!!
 #ifndef   XTAL_FREQ
  #define   XTAL_FREQ   4MHZ      /* Crystal frequency in MHz */
 #endif

 #define   MHZ   *1000         /* number of kHz in a MHz */
 #define   KHZ   *1         /* number of kHz in a kHz */

 #if   XTAL_FREQ >= 12MHZ
  #define   DelayUs(x)   { unsigned char _dcnt; \
           _dcnt = (x)*((XTAL_FREQ)/12MHZ); \
           while(--_dcnt != 0) \
              continue; }
 #else

  #define   DelayUs(x)   { unsigned char _dcnt; \
           _dcnt = (x)/(12MHZ/(XTAL_FREQ))|1; \
           while(--_dcnt != 0) \
              continue; }
 #endif

extern void DelayMs(unsigned char);
#endif


make a source file delay.c and copy below code into it:

Code:


/*
 *   Delay functions
 *   See delay.h for details
 *
 *   Make sure this code is compiled with full optimization!!!
 */

#include   "delay.h"

void
DelayMs(unsigned char cnt)
{
#if   XTAL_FREQ <= 2MHZ
   do {
      DelayUs(996);
   } while(--cnt);
#endif

#if    XTAL_FREQ > 2MHZ   
   unsigned char   i;
   do {
      i = 4;
      do {
         DelayUs(250);
      } while(--i);
   } while(--cnt);
#endif
}


Admin
Admin
Admin

Posts : 49
Join date : 2012-08-15
Location : Mumbai,INDIA

http://embeddedforus.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum