⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer_a.c

📁 瑞萨单片机LCD控制
💻 C
📖 第 1 页 / 共 4 页
字号:
/*       Name         :      timer_a0_interrupt_clr                       */
/*       Date/Author  :      14.04.1997/ST                                */
/*       Parameter    :                                                   */
/*       Return       :                                                   */
/*                                                                        */
/**************************************************************************/
void near timer_a0_interrupt_clr (void)
{
    TA0IC = 0x00;           // ---- 0000
                            //      ||||
                            //      |||+-- Interupt priority level select bit
                            //      ||+--- Interupt priority level select bit
                            //      |+---- Interupt priority level select bit
                            //      |      000: Level 0 (interrupt disabled)
                            //      |      001: Level 1
                            //      |      010: Level 2
                            //      |      011: Level 3
                            //      |      100: Level 4
                            //      |      101: Level 5
                            //      |      110: Level 6
                            //      |      111: Level 7
                            //      +----- Interupt request bit 
                            //             0: Interrupt not requested
                            //             1: Interrupt requested
}

/**************************************************************************/
/*                                                                        */
/*       Timer A1 - Initialization for timer mode                         */
/*       The timer counts an internal count source                        */
/*       routine may be customized to the user's needs                    */
/*                                                                        */
/*       Name         :      timer_a1_init_timer_mode                     */
/*       Date/Author  :      08.04.1997/ST                                */
/*       Parameter    :                                                   */
/*       Return       :                                                   */
/*                                                                        */
/**************************************************************************/
void near timer_a1_init_timer_mode (void)
{       
    TA1MR    = 0x80;        // XX0X XX00 
                            // |||| |||+- must always be 0 in timer mode
                            // |||| ||+-- must always be 0 in timer mode
                            // |||| |+--- 0: pulse is not output at pin TA1out
                            // |||| |     1: pulse is output at pin TA1out
                            // |||| |        TA1out is automatically  output
                            // |||| +---- 0: gate function: timer counts only 
                            // ||||          when TA1in is held "L"
                            // ||||       1: gate function: timer counts only
                            // ||||          when TA1in is held "H"
                            // |||+------ 0: gate function not available
                            // |||        1: gate function available
                            // ||+------- must always be 0 in timer mode
                            // |+-------- count source selection bits:
                            // +--------- count source selection bits
                            //            00:  f1
                            //            01:  f8
                            //            10:  f32
                            //            11:  fc32

    // Clock prescaler reset flag
    // This function is only effective if fc32 is selected
    if ((TA1MR & 0xC0)==0xC0)
    {
        CPSRF = 0x80;       // 1--- ----                                   
                            // +---------- 1: clock prescaler is reset 
    }
}

/**************************************************************************/
/*                                                                        */
/*       Timer A1 - Initialization for event counter mode                 */
/*       The timer counts pulses from an external source or another       */
/*       timer's overflow.                                                */
/*       routine may be customized to the user's needs                    */
/*                                                                        */
/*       Name         :      timer_a1_init_event_counter_mode             */
/*       Date/Author  :      08.04.1997/ST                                */
/*       Parameter    :                                                   */
/*       Return       :                                                   */
/*                                                                        */
/**************************************************************************/
void near timer_a1_init_event_counter_mode (void)
{       
    TA1MR    = 0x01;        // -X0X XX01 
                            // |||| |||+- must always be 1 in event counter mode
                            // |||| ||+-- must always be 0 in event counter mode
                            // |||| |+--- 0: pulse is not output at pin TA1out
                            // |||| |     1: pulse is output at pin TA1out at
                            // |||| |        overflow/underflow
                            // |||| |        TA1out is automatically output
                            // |||| +---- 0: counts ext. signal's falling edge
                            // ||||       1: counts ext. signal's rising edge
                            // ||||       valid only if ext. trigger signal is
                            // ||||       selected by event/trigger select bit
                            // |||+------ 0: counts up or down according to UDF
                            // |||           UDF bit 0 : downcount activated
                            // |||           UDF bit 1 : upcount activated
                            // |||        1: counts up or down according to 
                            // |||           TA1out input signal
                            // |||           TA1out "L": downcount activated
                            // |||           TA1out "H": upcount activated
                            // |||           TA1out must configured as input
                            // ||+------- must always be 0 in event counter mode
                            // |+-------- 0: count operation reload type
                            // |          1: count operation free-run type
                            // +--------- invalid in event counter mode

    UDF     &= ~(0x02);     // ---- --X-
                            //         +- 0: timer A1 down count
                            //            1: timer A1 up count

    TRGSR   &= ~(0x01);     // ---- --XX
    TRGSR   |= 0x02;        //        |+- timer A1 event/trigger select bits
                            //        +-- timer A1 event/trigger select bits
                            //            00: input on TA1in (TA1in must be input)
                            //            01: overflow of timer B2
                            //            10: overflow of timer A0
                            //            11: overflow of timer A2

}

/**************************************************************************/
/*                                                                        */
/*       Timer A1 - Initialization for one shot timer mode                */
/*       The timer counts once                                            */
/*       routine may be customized to the user's needs                    */
/*                                                                        */
/*       Name         :      timer_a1_init_one_shot_timer_mode            */
/*       Date/Author  :      08.04.1997/ST                                */
/*       Parameter    :                                                   */
/*       Return       :                                                   */
/*                                                                        */
/**************************************************************************/
void near timer_a1_init_one_shot_timer_mode (void)
{       
    TA1MR    = 0xD2;        // XX0X XX10 
                            // |||| |||+- must always be 0 in one-shot timer mode
                            // |||| ||+-- must always be 1 in one-shot timer mode
                            // |||| |+--- 0: pulse is not output at pin TA1out
                            // |||| |     1: pulse is output at pin TA1out
                            // |||| |        TA1out is automatically output
                            // |||| +---- 0: ext. trigger falling edge of
                            // ||||          TA1in input signal
                            // ||||       1: ext. trigger rising edge of
                            // ||||          TA1in input signal
                            // ||||       TA1in must be configured as input
                            // ||||       TA1in must be selected by 
                            // ||||       event/trigger select bit
                            // |||+------ 0: trigger is one-shot start flag (ONSF)
                            // |||        1: trigger is selected by event/trigger
                            // |||           select bits
                            // ||+------- must always be 0 in one-shot timer mode
                            // |+-------- count source select bits
                            // +--------- count source select bits
                            //            00:  f1
                            //            01:  f8
                            //            10:  f32
                            //            11:  fc32

    ONSF    &= ~(0x02);     // ---- --0-
                            //        +-- timer A1 one-shot start flag

    TRGSR   &= ~(0x01);     // ---- --XX
    TRGSR   |= 0x02;        //        |+- timer A1 event/trigger select bits
                            //        +-- timer A1 event/trigger select bits
                            //            00: input on TA1in (TA1in must be input)
                            //            01: overflow of timer B2
                            //            10: overflow of timer A0
                            //            11: overflow of timer A2

    // Clock prescaler reset flag
    // This function is only effective if fc32 is selected
    if ((TA1MR & 0xC0)==0xC0)
    {
        CPSRF = 0x80;       // 1--- ----                                   
                            // +---------- 1: clock prescaler is reset 
    }
}

/**************************************************************************/
/*                                                                        */
/*       Timer A1 - Initialization for pwm mode                           */
/*       The timer outputs pulses of a given width                        */
/*       routine may be customized to the user's needs                    */
/*                                                                        */
/*       Name         :      timer_a1_init_pwm_mode                       */
/*       Date/Author  :      08.04.1997/ST                                */
/*       Parameter    :                                                   */
/*       Return       :                                                   */
/*                                                                        */
/**************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -