CCP Programming Errors

Thread Starter

Ash424

Joined Apr 25, 2012
4
Hi! Can anyone help me with this code, im getting a some errors. Im using CCP to capture time and use it in the equation: cosine (94*capturedtime), then display the result on LCD. I have very basic knowledge in programming and this code is all my work.. Any suggestions would be helpful.. Thanks

Code:
#include <p18f452.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "capture.h"
#include "timers.h"
#define LCD_RS PORTbits.RB0
#define LCD_RW PORTbits.RB1
#define LCD_E PORTbits.RB2
#define LCD_DATA PORTD

unsigned int INCAPResult;
unsigned char config1= 0x00,timer_value= 0x00;

void main(void)
{
TRISA = 0x00;
TRISC = 0xff;
TRISD = 0x00;
TRISB = 0x00;

PORTD = 0;
LCD_INIT();
lcd_Cmd(_LCD_CLEAR);
lcd_Cmd(_LCD_CURSOR_OFF);
lcd_Out(1,1,"PWR FACTOR METER");
lcd_Out(2,5,"PF=");
lcd_char(2,8,0x200);
Delay_ms(2000);



SetTmrCCPSrc (T1_SOURCE_CCP);
config1 = CAP_EVERY_RISE_EDGE | CAPTURE_INT_OFF;
OpenCapture1(config1);
OpenTimer1(0);

while(!PIR1bits.CCP1IF);


INCAPResult = cos ( 94* ReadCapture1());

CloseCapture1 ();

}
 

Thread Starter

Ash424

Joined Apr 25, 2012
4
When I try to build the program using MPlab, it gives me a Syntax error at the end of the program saying "Preprocessor symbol `__DEBUG' is defined", even when I remove the delay the error still there,, what I'm I doing wrong??

unsigned int Cur_Cap_Val;
unsigned char INCAPResult,config1= 0x00,timer_value= 0x00;

void main(void)
{
TRISA = 0x00;
TRISC = 0xff;
TRISD = 0x00;
TRISB = 0x00;

PORTD = 0;

LCD_INIT();
lcd_Cmd(_LCD_CLEAR);
lcd_Out(1,1,"PWR FACTOR METER");
lcd_Out(2,5,"PF=");
lcd_char(2,8,0x200);

Delay_ms(2000);


SetTmrCCPSrc (T1_SOURCE_CCP);
config1 = CAP_EVERY_RISE_EDGE | CAPTURE_INT_OFF;
OpenCapture1(config1);
OpenTimer1(0);

while(!PIR1bits.CCP1IF);

INCAPResult = ReadCapture1();

CloseCapture1 ();

while(1)
{

Cur_Cap_Val = cos (94* INCAPRresult)

Delay_ms(1000)
}
}
 

ErnieM

Joined Apr 24, 2011
8,377
You're seeing "Preprocessor symbol `__DEBUG' is defined" because you are building a debug hex file, as opposed to a release version. Debug versions are only necessary if you are doing in circuit debugging.

There are two ways to change the build type: If the Project Manager tooltab is up there is a dropdown box for "Debug" or "Release". Or, on the protect menu select Build Configurations and change to "Release."
 

Thread Starter

Ash424

Joined Apr 25, 2012
4
Thank you.. I did as you said and changed it from "Debug" to "Release", so I'm not facing that error anymore. However, I got after that a few Syntax and Prototype errors, so I read a few tutorials on programming to remove them, but I still ended up with a Syntax error at the LCD interface part.


#include <p18f452.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <capture.h>
#include <timers.h>

sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

unsigned char cur_cap_val,cap_val=0,config1=0,timer_value=0;

void main(void)
{
TRISA = 0x00;
TRISC = 0xff;
TRISD = 0x00;
TRISB = 0x00;

PORTD = 0;

LCD_INIT();

Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_Out(1,1,"PWR FACTOR METER");
Lcd_Out(2,5,"PF=");
Lcd_Out(2,8,cur_cap_val);

Delay_ms(2000);


SetTmrCCPSrc (T1_SOURCE_CCP);
config1 = (CAP_EVERY_RISE_EDGE & CAPTURE_INT_OFF);
OpenCapture1(config1);
OpenTimer1(0);

while(!PIR1bits.CCP1IF);

cap_val = ReadCapture1();

CloseCapture1 ();

while(1)
{

cur_cap_val = cos (94*(cap_val));

Delay_ms(1000);
}
return 0;
}
 

ErnieM

Joined Apr 24, 2011
8,377
Syntax errors need be traced down starting with the very first one, as it is frequently found fixing one error cures several following errors.

When asking for help you need let us know what the error report line and comment was.
 

Thread Starter

Ash424

Joined Apr 25, 2012
4
Sorry,:confused: I didn't know that.. I get this message:

Release build of project `C:\Users\Faucett\Desktop\ASH\test 2\test 2.mcp' started.
Tue May 01 08:26:32 2012
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F452 "ex7.c" -fo="ex7.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\Users\Faucett\Desktop\ASH\test 2\ex7.c:10:Error: syntax error
Halting build on first failure as requested.
----------------------------------------------------------------------
Release build of project `C:\Users\Faucett\Desktop\ASH\test 2\test 2.mcp' failed.
Tue May 01 08:26:32 2012
----------------------------------------------------------------------

I thought its because I'm using "Release" and I should change it to "Debug" this time, but when I did change it gave me the first message "Debug is defined", I don't know what I'm missing... Thank you for your time.
 
Top