感谢各位的耐心解答,在下已经通过楼上发的网址里找到了官方例程,成功使用IC/输入捕捉模块实现了功能。
下面贴出官方文档编号和在下的代码
官方代码编号CE058
int Input_caputre3(void)
{
T3CON = 0x8030;
IC3CON = 0;
IC3CONbits.ICTMR = 0; //Select Timer3 as the IC3 Time base
IC3CONbits.ICSIDL = 0;
IC3CONbits.ICI = 0b0; //每个捕捉事件中断一次
IC3CONbits.ICM = 0b1; //Capture mode, every edge (rising and falling)
IPC9bits.IC3IP = 3; // Setup IC3 interrupt priority level
IFS2bits.IC3IF = 0; // Clear IC3 Interrupt Status Flag
IEC2bits.IC3IE = 1; // Enable IC3 interrupt
return 1;
}
int Input_caputre1(void)
{
T3CON = 0x8030; // 1:256 internal clock, start T3.
IPC0bits.IC1IP = 1; // Setup Input Capture 1 interrupt for desired priority
// level (this example assigns level 1 priority)
IFS0bits.IC1IF = 0; // Clear the IC1 interrupt status flag
IEC0bits.IC1IE = 1; // Enable IC1 interrupts
IC1CON = 0x0000; // Turn off Input Capture 1 Module
IC1CONbits.ICSIDL = 0; // Input capture module will continue to operate in CPU Idle mode
IC1CONbits.ICTMR = 0; // TMR3 contents are captured on capture event
IC1CONbits.ICI = 0; // Interrupt on every capture event
IC1CONbits.ICM = 1; // Capture mode, every edge (rising and falling)
}
void __attribute__((__interrupt__,no_auto_psv))_IC1Interrupt(void)
{
unsigned int t1;
IFS0bits.IC1IF = 0;
t1=IC1BUF;
LATF=(PORTF ^ 0xff);
//IC1flag = 1;
}
void __attribute__((__interrupt__,no_auto_psv))_IC3Interrupt(void)
{
unsigned int t1;
IFS2bits.IC3IF = 0;
t1=IC3BUF;
LATF=(PORTF ^ 0xff);
}
|
@galjewf :应该没问题,就是捕捉四次中断 ,但是你又才读两次,可能造成输入捕捉溢出,溢出之后就不会产生中断了。
@zxq1131 :对,是应该仿真的,虽然我又开了一个关于仿真错误的帖子。也就是说我这个软件代码的配置是正确的咯?
你可以软件仿真,看有没有进入中断。而且我看你的备注是每4次捕获中断一次,而且是4次上升沿捕获一次,也就是要16次才能进入中断啊