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 ();
}
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 ();
}