2011-03-28 98 views
2

我试图在PIC 16LF1827上使用捕获模块,但ISR从不输入。我从一个基本的下降沿中断(工作)开始,然后添加到定时器1配置(仍在工作)中,然后禁用IOC中断并配置/启用相关的CCP中断(从不输入ISR)。代码如下:注释部分是最初的基本IOC设置。PIC捕获模式不触发中断

我已经用MPLab调试器验证过ISR未进入,并通过将其挂接到逻辑分析仪并观察RB1来确认这一点。

#include "htc.h" 

//config1 
//internal osc, no wdt, use power-up timer, enable reset 
// no code protection, brown-out-reset enabled, clkout is gpio, 
// internal-external switchover off, failsafe clock monitor off 
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON 
    & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON 
    & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF); 

//config2 (following MPLab's complaints when running debugger) 
//low-voltage programming off, debug on, brown-out reset at 2.7 v 
// stack over/under flow triggers reset, no 4x pll, 
// no flash write protection 
__CONFIG(LVP_OFF & DEBUG_ON & BORV_27 
    & STVREN_ON & PLLEN_OFF & WRT_OFF); 

void interrupt isr(void){ 
    //bounce pin 1 
    LATB ^= 0b10; 
    LATB ^= 0b10; 
    if(IOCIF && IOCBF0){ 
     IOCBF0 = 0; 
     IOCIF = 0; 
    } 
    if (CCP1IF){ 
     CCP1IF = 0; 
    } 
} 

void main(void){ 
    //configure internal oscillator: 
    //PLL = 0, source = from config 1, frequency = 4 mhz 
    //0b0: SPLLEN_OFF 
    OSCCONbits.SPLLEN = 0b0; 
    //0b00: use config word 1 
    OSCCONbits.SCS = 0b00; 
    //0b1101: 4 mhz frequency 
    OSCCONbits.IRCF = 0b1101; 

    //configure peripherals 
    //PORT A: LEDs (output), digital 
    TRISA = 0x00; 
    ANSELA = 0; 
    //PORT B: digital, 0 = input, 1 = output, rest don't care 
    TRISB = 0b11111101; 
    ANSELB = 0; 

    //configure timer 1 (not needed for basic IOC) 
    //source = instruction clock, prescale = 1:1, disable LP osc, do synchronize (DC) 
    //0b00: instruction clock 
    T1CONbits.TMR1CS = 0b00; 
    //0b00: 1:1 
    T1CONbits.T1CKPS = 0b00; 
    //0b0: lp osc off 
    T1OSCEN = 0b0; 
    //0b0: synch (ignored) 
    nT1SYNC = 0b0; 

    //interrupts 
    /* 
    //IOC enabled on falling edge for port B 0 
    IOCBN0 = 0b00000001; 
    IOCIE = 1; 
    */ 

    //Capture on falling edge for port B 0 
    //notes in 23.1 of DS: disable interrupt, set operating mode, clear flag, enable interrupt 
    CCP1IE = 0b0; 
    //0b100: every falling edge 
    CCP1CONbits.CCP1M = 0b100; 
    CCP1IF = 0b0; 
    CCP1IE = 0b1; 
    //enable peripheral interrupts, global interrupts 
    PEIE = 1; 
    GIE = 1; 

    //start timer 1 
    TMR1ON = 1; 
    while(1){ 
     //Toggle led 0 
     LATA ^= 0b1; 
    } 
} 

我正在使用在MPLab中运行的HI-TECH C编译器(lite)。

任何建议将不胜感激。如果我是屠夫术语,我很抱歉,这是我在PIC上的第一个项目。

+0

Doug,虽然StackOverflow非常好,但请务必在专门的PIC论坛上反映您的问题:HI-TECH论坛http://forum.htsoft.com/all/postlist.php/Cat/0/Board/pic ,Microchip论坛http://www.microchip.com/forums。 – 2011-03-28 22:47:08

回答

1

您将TRISB1的设置作为输出。根据数据表,捕获引脚需要配置为输入。对于GPIO引脚,将TRIS位设置为0是输出,1是输入。

编辑:原谅最初的愚蠢答案,因为我没有意识到你正在使用PORTB1作为你的范围的GPIO指标。

所以最初你使用PORTB0作为你的捕获引脚正确(使用IOC)?捕获模块使用不同的GPIO端口作为输入(PORTB3用于CCP1)。您是否将连接移至PORTB3以获取捕获源?

编辑:经过一些更多看PIC的数据表,我注意到CCP1的GPIO引脚可以从PORTB3移到PORTB0,但我没有看到如何设置APFCON0.CCP1SEL位的任何参考。这将是别的东西来检查。

+1

好吧,我误读了数据表:我查看了引脚图,看到CCP1和RB0在同一引脚上,但未注意到脚注。将APFCON0.CCP1SEL设置为1解决了问题。非常感谢! – 2011-03-29 15:46:26