Hi guys , I am trying to measures the period and the high time of rectangular waveform using capture mode and display them on a 2x16 lcd . I am using ccp1 as input .
But although the program is build succeeded the screen doesn’t display anything .
I am working with pic18f452 and pic18f4520 I use mplap ide v8.63 and c18 lite v3,36.
The period of the waveform can be adjusted between 1,5ms and 3ms and it is between 3 and 5 volts .
This is the code I’m working on .
I know this subject is been discussed again but I am stuck here for more than two weeks and I have try anything I can think. i have add the diagram of my circuit
But although the program is build succeeded the screen doesn’t display anything .
I am working with pic18f452 and pic18f4520 I use mplap ide v8.63 and c18 lite v3,36.
The period of the waveform can be adjusted between 1,5ms and 3ms and it is between 3 and 5 volts .
This is the code I’m working on .
Code:
#include "p18f452.h"// Include files and definitions for the Processor
#include<xlcd.h>// Include function definitions for the External LCD Library library
#include<delays.h>// Include function definitions for built in Delay routines
#include <stdio.h>
#include <timers.h>
#include<stdlib.h>// Include function definitions for string manupulation Library
#include<capture.h>//Include function definitions for the Capture library
//#include <stdlib.h> /**********tin aferesa epeidi ekane problima sto itoa. Kanonika auti einai bibliothiki poy exei to idoa mesa tin ebala otan ebla ton ADC kodika Den ipirxe prin. Douleue sosta xvris ayti*/
#pragma config LVP=OFF
#pragma config OSC=HS
#pragma config WDT=OFF// Use internal Oscillator, Watchdog off, LVP off
#pragma config DEBUG = ON
unsigned int result,hightime,totaltime,dutycycle;//Variables used
unsigned char start=1;
unsigned char highlow,end;
unsigned char data[]="Thigh";
unsigned char data1[]="totaltime";
char str1[5];
char str2[5];
void DelaySTRING(void);
void Send(void);// Function for sending data to serial port
void chk_isr(void);// ISR Handler
void hi_prioriint(void)// ISR Routine
{
_asm
GOTO chk_isr
_endasm
}
#pragma interrupt chk_isr
void chk_isr(void)
{
if(PIR1bits.CCP1IF)
{
if(start==1)
{
WriteTimer1(00);//Start timer 1 for maximum count
OpenCapture1( CAPTURE_INT_ON & //Initialize CCP for HtoL
C1_EVERY_FALL_EDGE );
start=0;
highlow=1;
PIR1bits.CCP1IF=0;// Enable interrupt again
}
else
{
if(highlow==1)
{
hightime = ReadCapture1();// Read contents of capture registers
OpenCapture1( CAPTURE_INT_ON & //Initialize CCP for LtoH
C1_EVERY_RISE_EDGE );
highlow=0;
end=1;
PIR1bits.CCP1IF=0;
}
else
if(end==1)
{
totaltime=ReadCapture1();// Read contents of Capture registers
CloseTimer1();// Close timer 1
Send();// Send the measured time values to the serial port
}
}
}
}
void main(void)
{
// OSCCON=0x60;//Internal 4MHz oscillator
ADCON1=0x7f;//Make all pins Digital
//Initiazlize the capture moudule(ccp) for LtoH
OpenCapture1( C1_EVERY_RISE_EDGE
& CAPTURE_INT_ON );
OpenTimer1( TIMER_INT_OFF &//configure Timer1 for ccp
T1_16BIT_RW &// Can also use Timer3
T1_SOURCE_INT & // Timer1 clock source is internal
T1_SOURCE_CCP &// Make Timer1 source for CCP module
T1_PS_1_1);// No prescaler for timer1
INTCONbits.PEIE=1;// Enable peripheral interrupts
INTCONbits.GIEH=1;// Enable all interrupts
while(1);// wait here
}
void Send(void)// For sending the times
{
OpenXLCD( EIGHT_BIT & LINES_5X7 );// Use 8 bit Data, 5x7 pixel Matrix per character
while( BusyXLCD());// Wait till LCD finishes executing command
WriteCmdXLCD( CURSOR_ON);// Turn cursor ON
while( BusyXLCD() );// Wait till LCD finishes executing command
WriteCmdXLCD( 0x80);// Force curson to the begining of 1st line
while( BusyXLCD() );
WriteCmdXLCD( SHIFT_DISP_LEFT );//Shift Cursor Display Left
while( BusyXLCD());// Wait till LCD finishes executing command
putsXLCD(data);// Write the String data to the LCD
while( BusyXLCD());// Wait till LCD finishes executing command
WriteCmdXLCD( 0xC0);// Force curson to the begining of 2nd line
while( BusyXLCD() );
ultoa(hightime,str1);// convert integer in to string
putsXLCD(str1);
while( BusyXLCD());
WriteCmdXLCD(0b00000001);// Clear Display
while( BusyXLCD() );
WriteCmdXLCD( SHIFT_DISP_LEFT );//Shift Cursor Display Left
while( BusyXLCD());// Wait till LCD finishes executing command
ultoa(totaltime,str2);// convert integer in to string
putsXLCD(str2);
while( BusyXLCD() );
while( BusyXLCD() );
CloseCapture1();// Close CCP Module
INTCONbits.GIE=0;//Disbale interrupts
while(1);// wait here
}
void DelayFor18TCY(void)
{
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
}
void DelayPORXLCD(void)
{
Delay1KTCYx(75);
}
void DelayXLCD(void)
{
Delay1KTCYx(25);
}
void DelaySTRING(void)
{
Delay10KTCYx(456);//450//1562
}
//the cature part of the code was add by wonderboy in an other thread
I know this subject is been discussed again but I am stuck here for more than two weeks and I have try anything I can think. i have add the diagram of my circuit