int m ;int txt1[10],txt2[10],txt3[10];
int time1=0,time2=0;
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB4_bit;
void main()
{
CMCON=7;
TRISC=255;
TRISB=0;
PORTC=0;
PORTB=0;
T1CON=0B00000101;
INTCON=0B11000000;
PIR1=0;
TMR1L=0;
TMR1H=0;
LCD_INIT();
LCD_CMD(_LCD_CLEAR);
LCD_CMD(_LCD_CURSOR_OFF);
while(1){
CCP1CON=0B00000101;
PIE1=0B00000101;
if(CCP1IF==1){
time1=CCPR1L+(256*CCPR1H);
TMR1IF_BIT=0;
CCP1IF_BIT=0;
}
CCP1CON=0B00000100;
PIE1=0B00000101;
if(CCP1IF_BIT==1){
time2=CCPR1L+(256*CCPR1H);
TMR1IF_BIT=0;
CCP1IF_BIT=0;
}
inttostr(time1,txt3);
inttostr(time2,txt2);
m=time2-time1;
inttostr(m,txt1);
LCD_OUT(1,1,txt3);//view the time of rising edges
LCD_OUT(1,7,txt2);//view the time of falling edges
LCD_OUT(2,1,txt1);// view the positive part of the pulse time
delay_ms(100);
}
}