#include <p33fxxxx.h>
#include <timer.h>

// To Do : 宣告Timer1的中斷服務函式,並指定為no_auto_psv。
void __attribute__( ( interrupt , auto_psv ) ) _T1Interrupt( void )
{
    // To Do : 清除Timer1中斷旗標。
    IFS0bits.T1IF = 0;

    // 改變IO Port狀態(Toggle)。
    LATBbits.LATB5 = !LATBbits.LATB5;
}
/*
// To Do : 定義自己的Default中斷服務函式,並指定為auto_psv。
void __attribute__( ( interrupt , auto_psv ) ) _DefaultInterrupt( void )
{
    while( 1 );
}

// To Do : 定義Stack Error Trap Service Routine,並指定為auto_psv。
void __attribute__( ( interrupt , auto_psv ) ) _StackError( void )
{
    while( 1 );
}
*/
int main()
{
    // 將IO Port設定成數位輸出,並指定I/O Port狀態。
    TRISBbits.TRISB5 = 0;
    LATBbits.LATB5 = 0;

    // 使用MPLAB C30 Timer Function對Timer1進行設定。
    OpenTimer1( T1_ON & T1_IDLE_CON & 

    T1_GATE_OFF & T1_PS_1_256 &

     T1_SYNC_EXT_OFF & T1_SOURCE_INT 

    , 7000 ); // 累加值,控制中斷時間

    // To Do : 使用MPLAB C30 Timer Function啟用Timer1中斷,並指定其中斷優先權。
    ConfigIntTimer1( T1_INT_ON & T1_INT_PRIOR_4 );

    while( 1 );
}

arrow
arrow
    全站熱搜

    黃彥霖 發表在 痞客邦 留言(3) 人氣()