pwm.h
#ifndef _PWM_H_
#define _PWM_H_
#define PWM_TRIS TRISCbits.TRISC2
extern void pmw_ac(unsigned char period,unsigned int duty,unsigned char presc);
#endif
pwm.c
#include <xc.h>
#include "pwm.h"
void pwm_ac(unsigned char period,unsigned int duty,unsigned char presc)
{
PWM_TRIS=0;
CCP1CON=0b00001111;
CCPR1L=duty/4;
CCP1CON|=(duty%4)<<4;
T2CON|=presc;
T2CONbits.TMR2ON=0;
PR2=period;
T2CONbits.TMR2ON=1;
}
main.c
#include <xc.h>
#include "pwm.h"
void main(void)
{
pwm_ac(255,500,16);
while(1)
{
}
}
mplabx de şu işi bir türlü bulamadım. c eksikliğimden midir bilmiyorum. şimdi projects menüsünde source files klasöründe pwm.c ile main.c bulunuyor. bir yerden okuduğum kadarı ile mplabx de header files klasörüne header dosya eklenmiyormuş. ne kadar mantıklı ama. bende pwm.h ı eklemedim. çok karıştığından diye bazı kısımları farklı source dosyalara yazayım dedim. anladım ki hala o derece bilgim yok. bu işin hikmetini anlatabilecek var mı acaba?
xc8 de 16f877a için yazıyorum.
CLEAN SUCCESSFUL (total time: 768ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/izzet/MPLABXProjects/pwm.X'
make -f nbproject/Makefile-default.mk dist/default/production/pwm.X.production.hex
make[2]: Entering directory `C:/Users/izzet/MPLABXProjects/pwm.X'
"C:\Program Files (x86)\Microchip\xc8\v1.01\bin\xc8.exe" --pass1 --chip=16F877A -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -obuild/default/production/main.p1 main.c
main.c:8: warning: function declared implicit int
"C:\Program Files (x86)\Microchip\xc8\v1.01\bin\xc8.exe" --pass1 --chip=16F877A -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -obuild/default/production/pwm.p1 pwm.c
"C:\Program Files (x86)\Microchip\xc8\v1.01\bin\xc8.exe" --chip=16F877A -G --asmlist -mdist/default/production/pwm.X.production.map --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -odist/default/production/pwm.X.production.cof build/default/production/main.p1 build/default/production/pwm.p1
Microchip MPLAB XC8 C Compiler (PRO Mode) V1.01
Copyright (C) 2012 Microchip Technology Inc.
pwm.c:5: error: conflicting declarations for variable "_pwm_ac" (main.c:8)
(908) exit status = 1
make[2]: Leaving directory `C:/Users/izzet/MPLABXProjects/pwm.X'
make[1]: Leaving directory `C:/Users/izzet/MPLABXProjects/pwm.X'
make[2]: *** [dist/default/production/pwm.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 10s)
mesaj birleştirme:: 05 Ağustos 2012, 19:18:12
.h dosyasında fonksiyon tanımını pmw şeklinde yazmışım. yarım saaten fazladır kitledi beni :(