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

📄 stm32f10x_tim.lst

📁 ek-stm32f开发板测试程序,LCD+LED+按键
💻 LST
📖 第 1 页 / 共 5 页
字号:
    407          * Description    : Fills each TIM_InitStruct member with its default value.
    408          * Input          : - TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure
    409          *                    which will be initialized.
    410          * Output         : None
    411          * Return         : None
    412          *******************************************************************************/
    413          void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct)
    414          {
    415            /* Set the default configuration */
    416            TIM_ICInitStruct->TIM_ICMode = TIM_ICMode_ICAP;
    417            TIM_ICInitStruct->TIM_Channel = TIM_Channel_1;
    418            TIM_ICInitStruct->TIM_ICPolarity = TIM_ICPolarity_Rising;
    419            TIM_ICInitStruct->TIM_ICSelection = TIM_ICSelection_DirectTI;
    420            TIM_ICInitStruct->TIM_ICPrescaler = TIM_ICPSC_DIV1;
    421            TIM_ICInitStruct->TIM_ICFilter = TIM_ICFilter_Mask;
    422          }
    423          
    424          /*******************************************************************************
    425          * Function Name  : TIM_Cmd
    426          * Description    : Enables or disables the specified TIM peripheral.
    427          * Input          : - TIMx: where x can be 2, 3 or 4 to select the TIMx peripheral.
    428          *                  - Newstate: new state of the TIMx peripheral.
    429          *                    This parameter can be: ENABLE or DISABLE.
    430          * Output         : None
    431          * Return         : None
    432          *******************************************************************************/
    433          void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState)
    434          {
    435            /* Check the parameters */
    436            assert(IS_FUNCTIONAL_STATE(NewState));
    437            
    438            if (NewState != DISABLE)
    439            {
    440              /* Enable the TIM Counter */
    441              TIMx->CR1 |= CR1_CEN_Set;
    442            }
    443            else
    444            {
    445              /* Disable the TIM Counter */
    446              TIMx->CR1 &= CR1_CEN_Reset;
    447            }
    448          }
    449          
    450          /*******************************************************************************
    451          * Function Name  : TIM_ITConfig
    452          * Description    : Enables or disables the TIMx interrupts.
    453          * Input          : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
    454          *                  - TIM_IT: specifies the TIM interrupts sources to be enabled
    455          *                    or disabled.
    456          *                    This parameter can be any combination of the following values:
    457          *                       - TIM_IT_Update: Timer update Interrupt
    458          *                       - TIM_IT_CC1: Capture Compare 1 Interrupt
    459          *                       - TIM_IT_CC2: Capture Compare 2 Interrupt
    460          *                       - TIM_IT_CC3: Capture Compare 3 Interrupt
    461          *                       - TIM_IT_CC4: Capture Compare 4 Interrupt
    462          *                       - TIM_IT_Trigger: Trigger Interrupt
    463          *                  - Newstate: new state of the specified TIMx interrupts.
    464          *                    This parameter can be: ENABLE or DISABLE.
    465          * Output         : None
    466          * Return         : None
    467          *******************************************************************************/
    468          void TIM_ITConfig(TIM_TypeDef* TIMx, u16 TIM_IT, FunctionalState NewState)
    469          {
    470            /* Check the parameters */
    471            assert(IS_TIM_IT(TIM_IT));
    472            assert(IS_FUNCTIONAL_STATE(NewState));
    473            
    474            if (NewState != DISABLE)
    475            {
    476              /* Enable the Interrupt sources */
    477              TIMx->DIER |= TIM_IT;
    478            }
    479            else
    480            {
    481              /* Disable the Interrupt sources */
    482              TIMx->DIER &= (u16)(~TIM_IT);
    483            }
    484          }
    485          
    486          /*******************************************************************************
    487          * Function Name  : TIM_DMAConfig
    488          * Description    : Configures the TIMx抯 DMA interface.
    489          * Input          : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
    490          *                  - TIM_DMABase: DMA Base address.
    491          *                    This parameter can be one of the following values:
    492          *                       - TIM_DMABase_CR1, TIM_DMABase_CR2, TIM_DMABase_SMCR,
    493          *                         TIM_DMABase_DIER, TIM_DMABase_SR, TIM_DMABase_EGR,
    494          *                         TIM_DMABase_CCMR1, TIM_DMABase_CCMR2, TIM_DMABase_CCER,
    495          *                         TIM_DMABase_CNT, TIM_DMABase_PSC, TIM_DMABase_ARR,
    496          *                         TIM_DMABase_CCR1, TIM_DMABase_CCR2, TIM_DMABase_CCR3,
    497          *                         TIM_DMABase_CCR4, TIM_DMABase_DCR.
    498          *                  - TIM_DMABurstLength: DMA Burst length.
    499          *                    This parameter can be one value between:
    500          *                    TIM_DMABurstLength_1Byte and TIM_DMABurstLength_18Bytes.
    501          * Output         : None
    502          * Return         : None
    503          *******************************************************************************/
    504          void TIM_DMAConfig(TIM_TypeDef* TIMx, u16 TIM_DMABase, u16 TIM_DMABurstLength)
    505          {
    506            u32 tmpdcr = 0;
    507          
    508            /* Check the parameters */
    509            assert(IS_TIM_DMA_BASE(TIM_DMABase));
    510            assert(IS_TIM_DMA_LENGTH(TIM_DMABurstLength));
    511            
    512            tmpdcr = TIMx->DCR;
    513          
    514            /* Reset the DBA and the DBL Bits */
    515            tmpdcr &= DCR_DMA_Mask;
    516          
    517            /* Set the DMA Base and the DMA Burst Length */
    518            tmpdcr |= TIM_DMABase | TIM_DMABurstLength;
    519          
    520            TIMx->DCR = (u16)tmpdcr;
    521          }
    522          
    523          /*******************************************************************************
    524          * Function Name  : TIM_DMACmd
    525          * Description    : Enables or disables the TIMx抯 DMA Requests.
    526          * Input          : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
    527          *                  - TIM_DMASources: specifies the DMA Request sources.
    528          *                    This parameter can be any combination of the following values:
    529          *                       - TIM_DMA_CC1: Capture Compare 1 DMA source
    530          *                       - TIM_DMA_CC2: Capture Compare 2 DMA source
    531          *                       - TIM_DMA_CC3: Capture Compare 3 DMA source
    532          *                       - TIM_DMA_CC4: Capture Compare 4 DMA source
    533          *                       - TIM_DMA_Trigger: Trigger DMA source
    534          *                  - Newstate: new state of the DMA Request sources.
    535          *                    This parameter can be: ENABLE or DISABLE.
    536          * Output         : None
    537          * Return         : None
    538          *******************************************************************************/
    539          void TIM_DMACmd(TIM_TypeDef* TIMx, u16 TIM_DMASource, FunctionalState Newstate)
    540          {
    541            u32 tmpdier = 0;
    542            
    543            /* Check the parameters */
    544            assert(IS_TIM_DMA_SOURCE(TIM_DMASource));
    545            assert(IS_FUNCTIONAL_STATE(Newstate));
    546          
    547            tmpdier = TIMx->DIER;
    548          
    549            if (Newstate != DISABLE)
    550            {
    551              /* Enable the DMA sources */
    552              tmpdier |= TIM_DMASource;
    553            }
    554            else
    555            {
    556              /* Disable the DMA sources */
    557              tmpdier &= (u16)(~TIM_DMASource);
    558            }
    559            TIMx->DIER = (u16)tmpdier;
    560          }
    561          
    562          /*******************************************************************************
    563          * Function Name  : TIM_InternalClockConfig
    564          * Description    : Configures the TIMx interrnal Clock
    565          * Input          : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
    566          * Output         : None
    567          * Return         : None
    568          *******************************************************************************/
    569          void TIM_InternalClockConfig(TIM_TypeDef* TIMx)
    570          {
    571            /* Disable slave mode to clock the prescaler directly with the internal clock */
    572            TIMx->SMCR &=  SMCR_SMS_Mask;
    573          }
    574          /*******************************************************************************
    575          * Function Name  : TIM_ITRxExternalClockConfig
    576          * Description    : Configures the TIMx Internal Trigger as External Clock
    577          * Input          : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
    578          *                  - TIM_ITRSource: Trigger source.
    579          *                    This parameter can be one of the following values:
    580          *                       - TIM_TS_ITR0: Internal Trigger 0
    581          *                       - TIM_TS_ITR1: Internal Trigger 1
    582          *                       - TIM_TS_ITR2: Internal Trigger 2
    583          *                       - TIM_TS_ITR3: Internal Trigger 3
    584          * Output         : None
    585          * Return         : None
    586          *******************************************************************************/
    587          void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, u16 TIM_InputTriggerSource)
    588          {
    589            /* Check the parameters */
    590            assert(IS_TIM_INTERNAL_TRIGGER_SELECTION(TIM_InputTriggerSource));
    591          
    592            /* Select the Internal Trigger */
    593            TIM_SelectInputTrigger(TIMx, TIM_InputTriggerSource);
    594          
    595            /* Select the External clock mode1 */
    596            TIMx->SMCR |= TIM_SlaveMode_External1;
    597          }
    598          /*******************************************************************************
    599          * Function Name  : TIM_TIxExternalClockConfig
    600          * Description    : Configures the TIMx Trigger as External Clock
    601          * Input          : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
    602          *                  - TIM_TIxExternalCLKSource: Trigger source.
    603          *                    This parameter can be one of the following values:
    604          *                       - TIM_TS_TI1F_ED: TI1 Edge Detector
    605          *                       - TIM_TS_TI1FP1: Filtered Timer Input 1
    606          *                       - TIM_TS_TI2FP2: Filtered Timer Input 2
    607          *                  - TIM_ICPolarity: specifies the TIx Polarity.
    608          *                    This parameter can be:
    609          *                       - TIM_ICPolarity_Rising
    610          *                       - TIM_ICPolarity_Falling
    611          *                   - ICFilter : specifies the filter value.
    612          *                     This parameter must be a value between 0x0 and 0xF.
    613          * Output         : None
    614          * Return         : None
    615          *******************************************************************************/
    616          void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, u16 TIM_TIxExternalCLKSource,
    617                                          u16 TIM_ICPolarity, u8 ICFilter)
    618          {
    619            /* Check the parameters */
    620            assert(IS_TIM_TIX_TRIGGER_SELECTION(TIM_TIxExternalCLKSource));
    621            assert(IS_TIM_IC_POLARITY(TIM_ICPolarity));
    622            assert(IS_TIM_IC_FILTER(ICFilter));
    623          
    624            /* Configure the Timer Input Clock Source */
    625            if (TIM_TIxExternalCLKSource == TIM_TIxExternalCLK1Source_TI2)
    626            {
    627              TI2_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter);
    628            }
    629            else
    630            {

⌨️ 快捷键说明

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