无论用什么方法,始终不仅捕获中断,不知道为什么? 谢谢!
/*********************************************
*脉宽测量初始化
**********************************************/
void PWM_CAP_Init(void)
{
CCP1CON = 0x05; //每6个上升沿捕获一次
T1CON = 0x00; //TMR1ON = 1;
PEIE = 1; //允许一切外部中断
//PIR1 = 1; //
CCP1IE = 1;
TRISC5 = 1; //RC5设置为输入模式
TMR1ON = 1; //SET TIMER1 OFF
// RC5 = 1;
GIE = 1;
//INTCON=0X0D0;//SET GIE=1, PIEE=1,TOIE=1; SET INT
}
/*********************************************
*系统初始化
**********************************************/
void iniport(void) //ioprt booll
{
//SET I/O START
// OSCCON=0x47; //使用on mcu clock 1MHZ
//OSCCON=0x63; //使用on mcu clock 4MHZ
OSCCON=0x68; //外部时钟
WDTCON=0X15; //open wothdog
PORTA=0X00;
PORTB=0X00;
PORTC=0X21; //上拉
ANSEL=0X00; //SET AN7 INTPU //0x08
ANSELH=0X01;
TRISA=0X3f; //SET RA<0:5> INPUT RA<6:7>OUTPUT
ADCON1=0X40; //SET FRK COOK 1/4
ADFM=0; // AD DATA LIFT |
ADCON0=0X20; //SET AD AD DATA TO LIFT AN7 INPUT
ADON=1; //SET AD END
ADIE=0; //SET AD INI CLOSE
TRISB=0X0ff; //SET ALL RB OUTPUT
TRISC=0X78; //SET RC<6:4:5:3>INPUT -ALL OUTPUT;
//SET I/O END
OPTION=0X0F; //SET PS<2:0>TO WDT
//INTCON=0X0D0;//SET GIE=1, PIEE=1,TOIE=1; SET INT
//IOCA=0X04;
//TMR1IE=1;
//T1CON=0X00; //SET TIMER1 1:4T1CK
//TMR1L=0X00;
//TMR1H=0x00;
//TMR1ON=1; //SET TIMER1 OFF
PWM_CAP_Init();
RC0=1;
P_test=0;
V_test=0;
}
/*********************************************
*捕获中断
**********************************************/
void interrupt cplint(void)
{
if(TMR1IF==1)
{
TMR1IF=0;
RC1 = ~RC1;
//RC0 = 0;
}
if(CCP1IF==1)
{
CCP1IF = 0;
RC2=~RC2;
if(EXT_interrupt==0)
{
EXT_interrupt = 1;
Frq_FirstValue = CCPR1H;
Frq_FirstValue = Frq_FirstValue*256 + CCPR1L;;
//Frq_FirstValue = CCPR1H*256 + CCPR1L;
RC1 = 0;
RC0 = 0;
}
else
{
EXT_interrupt = 0;
Frq_SecondValue = CCPR1H;
Frq_SecondValue = Frq_SecondValue*256 + CCPR1L;;
//Frq_FirstValue = CCPR1H*256 + CCPR1L;
Frq_Refresh = 1; //通知主程序,采集到一个完整的周期,频率可以更新
RC1 = 1;
RC0 = 1;
}
}
}
|