Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Delay routines for HI-TECH PICC ?

Status
Not open for further replies.

agnivesh

Member level 2
Joined
Apr 24, 2004
Messages
45
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
UK
Activity points
549
picc delay

I've just started programming PIC mcu's using HI-TECH PICC. Right now I'm struggling to find a way of inserting precise delays in my code.

a) say if I need precise 10ms intervals in my c code, what should I do ?

b) I haven't found a way to tell picc compiler about my crystal frequency, where can i put that info and it doesn't require that info then how will it calculate, the different timer settings, if in case I use timer interrupt method.

c) is there any prebuilt precise delay routines available for picc ?

d) do I need to tell the compiler about my crystal frequency before starting the compiling ?

In nutshell, I am confused about how PICC compiler handles the precise delay routines ?
 

hi-tech delay

a) use already written delay routines or write your own
b) under "CPP Pre-defined symbols" add -DXTAL_FREQ=4MHZ (for 4MHZ crystal)
c) I dunno how precise these two attached routines are, but if you're gonna need very precise delays, write your own code for delays
d) look at b)

remember to put these two files in the same directory as your source files.

Usage: DelayUs(13); or DelayMs(115); :)

regards,
rfmw

----------------------------------------------
/* Filename: Delay.c
* 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
}
-----------------------------------------


-----------------------------------------
/* Filename: Delay.h
* 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 XTAL_FREQ
#define XTAL_FREQ 4MHZ /* Crystal frequency in MHz */
#endif

#define MHZ *1000L /* 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);
---------------------------------------------------
 

hitech c delay

Hello.

When i include these two files to my code i get

Error [237] E:\Project Szkola\Ksiazka\delay.c; 12. function "_DelayMs" redefined

Does anybody know how to get rid of that error??


Thanks in advance.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top