为什么pic18f46k40 Timer0溢出不会发生

时间:2018-03-19 09:31:24

标签: c

我正在使用调试功能检查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;
}

1 个答案:

答案 0 :(得分:0)

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