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

📄 configtimer23.c

📁 无线龙ZigBee模块CC1010的接收-发送程序。
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                            CHIPCON CC1010                    *
 *      ***   + +   ***                 HAL - ConfigTimer23                  *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 *                                                                           *
 *****************************************************************************
 * Author:              ROH                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 *                                                                           *
 * $Log: ConfigTimer23.c,v $
 * Revision 1.1  2002/10/14 13:04:30  tos
 * Initial version in CVS.
 *
 *                                                                           *
 ****************************************************************************/

#include <chipcon/hal.h>


//----------------------------------------------------------------------------
// ulong halConfigTimer23(...);
//
//  Description:
//      This function configures timer 2 or 3 (depending on the value given in
//      _option_ as either an interrupt timer (an interrupt is generated at
//      certain intervals in time, as specified by _period) or a pulse width 
//      modulator (PWM).
//      If _period_ is specified as 0, then, in timer mode the timeout peiod will
//      be set to the maximum possible, and in PWM mode the period will be
//      set as long as possible. Using the PWM mode of timer 2/3 overrides the
//      normal operation of ports P3.4/P3.5 and can thus not be used in conjunction
//      with timer 0/1 configured as counters. The duty cycle is set to 50% (128/255)
//      initially in PWM mode.
//      The timer/PWM must be started with macro TIMERx_RUN(TRUE).
//描述: 
//    这一功能配置计时器2或3(取决于在_option_作为定时器中断所给定的值(中断的产生
//是由_period规定的一定的时间间隔, )或脉冲宽度调制器( PWM ) 。 
//    如果_period_被指定为0 ,然后在定时器模式超时将peiod 设置为最大可能值,并在PWM模式下period将
//设置的时间尽可能的长。利用定时器2/3的PWM模式覆盖正常运作的端口P3.4/P3.5,因此,可以不一起使用
//定时器0/1配置做为计数器。占空比设置为50% (128/255) 初始是在PWM模式。 
//计时器/脉宽调制器必须由宏TIMERx_RUN(TRUE)启动。
//
//  Arguments:
//      byte options
//          Options indicating which timer to configure and how. Different  (Options指示配置哪一个计时器及怎样配置)
//          constants for _option_ is defined below.(为_option_设置的各个常量在下面定义)
//      ulong period
//          The desired period between interrupts in microseconds. In PWM mode(理想的中断在微秒间)
//          the duty cycle will be set as close to 50% as possible. This duty  (在PWM模式下,占空比将被设置成接近50%)
//          cycle can be changed (in an ISR or at any other time) by using the (在ISR或其他任何时刻,占空比都可以通过利用)
//          appropriate PWMx_SET_DUTY_CYCLE(...) macro. If _period_            (宏PWMx_DUTY_CYCLE(...)进行修改)
//          is 0, then the maximum period possible will be set. The period can (如果_period_值为0,将会设置成最大的间隔值)
//          also be adjusted dynamically with the PWMx_SET_PERIOD(...) macro.  (间隔值也可以调整,建议使用宏PWMx_SET_PERIOD(...))
//      word clkFreq
//          The XOSC clock frequency in kHz.(Xosc 时钟频率(KHz))
//
//  Return value:
//      ulong
//          The actual period in microseconds or zero if the desired period is
//          too high.(如果period的值太大,则返回0或微秒)
//----------------------------------------------------------------------------
ulong halConfigTimer23(byte options, ulong period, word clkFreq) {
    byte tx, txpre, mode;// typedef unsigned char byte
                         // typedef unsigned short word
						 // typedef unsigned long ulong
    period = (period*clkFreq+127500)/255000;
    if (period)
        period--;
    mode=0;
    if (options&TIMER23_PWM) {
        // PWM mode selected
        if (period&0xFFFFFF00)     // >255
            return 0;
        txpre=(byte)period;
        tx=128;
        mode=1;
    } else {
        // Timer mode selected        
        if (period&0xFFFF0000)      // >63535
            return 0;
        txpre=(byte)((word)period>>8);
        tx=(byte)period;
    }
  
    if (options&TIMER3) {
        // Timer 3 selected
        if (options&TIMER23_INT_TIMER) {
            EXIF&=~0x80;    // Clear interrupt flag
            ET3=1;          // Enable timer interrupt
            EA=1;           // Enable global interrupt
        }
        T3PRE=txpre;
        T3=tx;
        TCON2=(TCON2&~0x0C)|(mode<<2);
    } else {
        // Timer 2 selected
        if (options&TIMER23_INT_TIMER) {
            EXIF&=~0x20;    // Clear interrupt flag
            ET2=1;          // Enable timer interrupt
            EA=1;           // Enable global interrupt
        }
        T2PRE=txpre;
        T2=tx;            
        TCON2=(TCON2&~0x03)|mode;
    }
    period=(period+1)*255000/clkFreq;
    return period;
}

⌨️ 快捷键说明

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