用的PIC16F877A,程序不知道哪里出错了,找茬了一天了。求指导; 
CCP1输入捕获方式,用D端口的指示灯指示接收到的数据。指示灯用电阻上拉的。 
程序如下:请指导下。 
#include<pic.h> 
//__CONFIG(0xFF32); 
 
void ccp1_init()  //capture mode 
{ 
        T1CON = 0x00;                //no postscale and no prescale 
        CCP1CON = 0x04;         //capture mode and falling edge 
        TMR1L = 0x00; //timer1 count from TMR1 to 0xffff 
        TMR1H = 0x00; 
        GIE = 1; 
        PEIE = 1; 
        CCP1IE = 1; 
        CCP1IF = 0; 
} 
 
volatile unsigned int countl = 0;   //捕获的时间 
volatile unsigned char leadcode_ok = 0; //引导码OK 
volatile unsigned char time_start = 0;  //解码开始 
volatile unsigned char i = 0;  
volatile unsigned char ir_code[4] = {0,0,0,0}; // 红外接收到的4个数据 
 
void main()                  
{  
        TRISD = 0x00;                          //portd 输出  LED端口 
        PORTD = 0xff; 
        TRISC = 0xff;                        // CCP1 输入,对应红外输入 
        ccp1_init();                                 
        while (1)         
        { 
                ; 
        }         
} 
 
void interrupt ccp1(void) 
{ 
        if(CCP1IF && CCP1IE ) 
        { 
                CCP1IE = 0; 
                if(time_start == 0) 
                {  
                        TMR1H = 0; 
                        TMR1L = 0 ; 
                        TMR1ON = 1; 
                        time_start = 1; 
                }         
                else 
                { 
                        TMR1ON = 0; 
                        countl = TMR1H*256+TMR1L; 
                        TMR1H = 0; 
                        TMR1L = 0; 
                        TMR1ON = 1; 
                        if((countl >12500)&&(countl <14500)&&(leadcode_ok == 0)) 
                        { 
                                leadcode_ok = 1;         
                                i = 0; 
                        } 
                        else 
                        { 
                                if((countl >2000)&&(countl <2500)&&(leadcode_ok==1)) //bit 1 
                                { 
                                        ir_code[i/8] = ir_code[i/8]<<1+1; 
                                        i++; 
                                }  
                                else                                 
                                if((countl >1000)&&(countl <1300)&&(leadcode_ok==1))   //bit 0 
                                { 
                                        ir_code[i/8] = ir_code[i/8] <<1 ; 
                                        i++; 
                                } 
                                else  
                                { 
                                        time_start = 0; 
                                        leadcode_ok = 0; 
                                        i = 0;                                         
                                }                         
                        } 
                        if(i==32) 
                                { 
                                        i = 0; 
                                        time_start = 0; 
                                        leadcode_ok = 0; 
                                        PORTD = ~ir_code[3]; //用指示灯输出 红外数据 
                                } 
                } 
                TMR1IF = 0; 
                CCP1IF = 0; 
                CCP1IE = 1; 
        }         
}         
 
 |   
     
  
 |