我正在使用调试功能来检查TMR0IF标志,但不会发生。它卡在while(PIR0bits.TMR0IF ==0)上。请指教。

#define _XTAL_FREQ  64000000
#define ACM_STEP_TRIS TRISAbits.TRISA4
#define ACM_STEP LATAbits.LATA4
#define ACM_ENABLE_TRIS TRISAbits.TRISA5
#define ACM_nENABLE LATAbits.LATA5

ACM_STEP_TRIS =0;

void main(void)
{
    T0CON0bits.T0OUT   = 0;
    T0CON0bits.T016BIT = 1;   // TMR0 is a 16-bit timer
    T0CON0bits.T0OUTPS = 0;   // No prescaler
    T0CON1bits.T0CS =0b010;   //Clock source is Fosc/4
    T0CON1bits.T0ASYNC =0;    //Input to TMR0 counter is synchronized to Fosc/4
    T0CON1bits.T0CKPS =0;     //Prescaler 1:1

    while (1){

        ACM_nENABLE      =0;    // Turn on stepper motor
        __delay_ms(2);

        ACM_STEP ^=1;
        TMR0H =  0xFD;
        TMR0L =  0xE8;                // Load TMR0L
        T0CON0bits.T0EN    = 1;      //Timer Module is enabled
        while(PIR0bits.TMR0IF ==0);
        T0CON0bits.T0EN = 0;        //Turn off Timer
        PIR0bits.TMR0IF = 0;                 // Clear TF0 flag

    }
    return;
}

最佳答案

请查看以下答案:http://www.edaboard.com/showthread.php?t=197899
他们检查另一个寄存器(INTCONbits而不是PIR0bits),一切正常。

09-06 03:58