Picproje Elektronik Sitesi

DERLEYİCİLER => Hi-Tech => Konuyu başlatan: NaMcHo - 08 Ağustos 2010, 22:08:28

Başlık: #include "delay.h" Sorunu (Çözüldü)
Gönderen: NaMcHo - 08 Ağustos 2010, 22:08:28
Merhabalar,
Ekran görüntüsü : http://www.4shared.com/photo/UNInEHFs/1_online.html
Hi-Tech Software dosyası altında : DSPICC,HI-TIDE,PICC,PICC-18,PICC32 bunlar var.

C:\Program Files (x86)\HI-TECH Software\DSPICC\STD\9.60\samples\delay
Burdaki delay C Source File daki kod
/*
*   Delay functions for HI-TECH C on the dsPIC
*
*   Functions available:
*      DelayUs(x)   Delay x microseconds
*      DelayMs(x)   Delay x milliseconds
*
*   Note that there are range limits:
*
*   DelayUs(x)   8/XTAL_FREQ <= x <= 65540/XTAL_FREQ
*     (with the default 20 (MHz) XTAL_FREQ,   1 <= x <= 3277)
*
*   DelayMs(x)   8/(XTAL_FREQ-4) <= n <= 32774/(XTAL_FREQ-4)
*     (with the default 20 (MHz) XTAL_FREQ,   1 <= x <= 2048)
*
*   1 <= XTAL_FREQ <= 65540
*
*   To use these functions it is only necessary to include this file.
*
*   Set the crystal frequency in MHz on the dsPICC commmand line,
*   e.g.
*   dspicc -DXTAL_FREQ=4
*
*   or
*   dspicc -DXTAL_FREQ=40
*
*   Note that this is the crystal frequency; it is divided by 4 to
*   give the CPU clock
*
*/

#ifndef __delay_h
#define __delay_h

#include <dspic.h>

#ifndef   XTAL_FREQ
#define   XTAL_FREQ   20   /* Crystal frequency, in MHz */
#endif

#if XTAL_FREQ < 1   /* actual lower limit is 8.0/499 - see __Dm */
#error XTAL_FREQ must be no smaller than 1 (MHz)
#endif
#if XTAL_FREQ > 32000   /* actual upper limit is 65540 - see __Dm */
#error XTAL_FREQ must be no greater than 32000 (MHz)
#endif

#define __CYCLE_FREQ ((XTAL_FREQ)/4)

/* n + 2 cycles
   0 <= n <= 16383 */
#define __DELAY_SHORT(n) do { \
   asm("repeat #" ___mkstr(n)); \
   asm("clrwdt");               \
} while(0)

/* n microseconds
   8/XTAL_FREQ <= n <= 65540/XTAL_FREQ */
#define DelayUs(n) __DELAY_SHORT((n)*__CYCLE_FREQ-2)

/* The first-stage delay needs to leave time at end of
   n half-milliseconds for loop and other overhead.

   These values determine maximum and minimum values for XTAL_FREQ. */
#define __Dm 1
#define __Dn (500-__Dm)

/* 2 + (n+1)(__Dn*__CYCLE_FREQ + 1) cycles
   0 <= n <= 16383 */
#define __DELAY_LONG(n) do { \
   asm("do #" ___mkstr(n) ",2"); \
   DelayUs(__Dn);                \
   asm("nop");                   \
} while (0)

/* n milliseconds
   8/(__Dm*XTAL_FREQ-4) <= n <= 32774/(__Dm*XTAL_FREQ-4) */
#define DelayMs(n) do { \
   __DELAY_LONG((n)*2-1);                                 \
   __DELAY_SHORT((n)*2*(__Dm*__CYCLE_FREQ - 1) - 4); \
} while (0)

#endif /* __delay_h */

C:\Program Files (x86)\HI-TECH Software\PICC\9.70\samples\delay
Burdada main diye bir C Source File var onun icindeki kod ise

#include <htc.h>   // Required to interface with delay routines

#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate __delay_us() and __delay_ms()
#define _XTAL_FREQ 4000000
#endif

/** demonstration of various built-in delay mechanisms */
void main(void){
   while(1){
      NOP();
      _delay(1000);      // delay for 1000 instruction cycles
      CLRWDT();
      __delay_us(400);   // delay for 400 microseconds
      CLRWDT();
      __delay_ms(2);      // delay for 2 milliseconds
      CLRWDT();
   }
}

main dosyasını delay.c diye değiştirip,diğer DSPICC altındaki delay dosyasınıda direk alıp projemin icine attım.aldığım hata ekran görüntüsündekidir.

Sorunu çözdüm : C:\Program Files (x86)\HI-TECH Software\PICC-18\PRO\9.64\samples\std\delay bende surdaymıs gerekli 2 delay dosyası
Ve surekli DELAYMS() yazıyordum DelayMs() yazmak gerekiyormus. :)