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

📄 timer_a.c

📁 瑞萨单片机LCD控制
💻 C
📖 第 1 页 / 共 4 页
字号:
/**************************************************************************/
/**MITSUBISHI**MITSUBISHI**MITSUBISHI**MITSUBISHI**MITSUBISHI**MITSUBISHI**/
/**************************************************************************/
/**************************************************************************/
/*  DISCLAIMER:                                                           */
/*  We (MITSUBISHI ELECTRIC B.V.) do not warrant that the Software is     */
/*  free from claims by a third party of copyright, patent, trademark,    */
/*  trade secret or any other intellectual property infringement.         */
/*                                                                        */
/*  Under no circumstances are we liable for any of the following:        */
/*                                                                        */
/*  1. third-party claims against you for losses or damages;              */
/*  2. loss of, or damage to, your records or data; or                    */
/*  3. economic consequential damages (including lost profits or          */
/*     savings) or incidental damages, even if we are informed of         */
/*     their possibility.                                                 */
/*                                                                        */
/*  We do not warrant uninterrupted or error free operation of the        */
/*  Software. We have no obligation to provide service, defect            */
/*  correction, or any maintenance for the Software. We have no           */
/*  obligation to supply any Software updates or enhancements to you      */
/*  even if such are or later become available.                           */
/*                                                                        */
/*  IF YOU DOWNLOAD OR USE THIS SOFTWARE YOU AGREE TO THESE TERMS.        */
/*                                                                        */
/*  THERE ARE NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING THE            */
/*  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A               */
/*  PARTICULAR PURPOSE.                                                   */
/**************************************************************************/
/**************************************************************************/
/*                                                                        */
/*       Timer A Initialization and Service-Routines for the M3060        */
/*       Remarks: timer_value = (Xin*time_solution/clock_select)-1        */
/*                For example: time_solution = 1ms                        */
/*                             Xin = 10MHz                                */
/*                             clock_select = 8 (source=f8)               */
/*                                                                        */
/*                         =>  timer_value = 1249d                        */
/*                                                                        */
/*       Name         :      TIMER_A.C                                    */
/*       Date/Author  :      08.04.1997/ST                                */
/*       Change       :                                                   */
/*               (Date)  (Author)  (Description)                          */
/*                                                                        */
/**************************************************************************/

#define public extern
#include    "sfr_3061.h"
#undef public

#define public
#include    "timer_a.h"
#undef public


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

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

/**************************************************************************/
/*                                                                        */
/*       Timer A0 - 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_a0_init_event_counter_mode             */
/*       Date/Author  :      08.04.1997/ST                                */
/*       Parameter    :                                                   */
/*       Return       :                                                   */
/*                                                                        */
/**************************************************************************/
void near timer_a0_init_event_counter_mode (void)
{       
    TA0MR    = 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 TA0out
                            // |||| |     1: pulse is output at pin TA0out at
                            // |||| |        overflow/underflow
                            // |||| |        TA0out 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 
                            // |||           TA0out input signal
                            // |||           TA0out "L": downcount activated
                            // |||           TA0out "H": upcount activated
                            // |||           TA0out 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     |= 0x01;        // ---- ---X
                            //         +- 0: timer A0 down count
                            //            1: timer A0 up count

    ONSF    |= 0xC0;        // XX-- ----
                            // |+-------- timer A0 event/trigger select bits
                            // +--------- timer A0 event/trigger select bits
                            //            00: input on TA0in (TA0in must be input)
                            //            01: overflow of timer B2
                            //            10: overflow of timer A4
                            //            11: overflow of timer A1

}

/**************************************************************************/
/*                                                                        */
/*       Timer A0 - Initialization for one shot timer mode                */
/*       The timer counts once                                            */
/*       routine may be customized to the user's needs                    */
/*                                                                        */
/*       Name         :      timer_a0_init_one_shot_timer_mode            */
/*       Date/Author  :      08.04.1997/ST                                */
/*       Parameter    :                                                   */
/*       Return       :                                                   */
/*                                                                        */
/**************************************************************************/
void near timer_a0_init_one_shot_timer_mode (void)
{       
    TA0MR    = 0xC2;        // 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 TA0out
                            // |||| |     1: pulse is output at pin TA0out
                            // |||| |        TA0out is automatically output
                            // |||| +---- 0: ext. trigger falling edge of
                            // ||||          TA0in input signal
                            // ||||       1: ext. trigger rising edge of
                            // ||||          TA0in input signal
                            // ||||       TA0in must be configured as input
                            // ||||       TA0in 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    |= 0x80;        // XX-- ---0
    ONSF    &= ~(0x01);     // ||      +- timer A0 one-shot start flag
                            // |+-------- timer A0 event/trigger select bits

⌨️ 快捷键说明

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