查看: 2297|回复: 1

[其他] 请问如何将LPTMR配置成1MS中断一次,时钟源为8MHZ的OSCERCLK

[复制链接]
  • TA的每日心情

    2016-10-20 11:32
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    12

    主题

    108

    帖子

    0

    高级会员

    Rank: 4

    积分
    545
    最后登录
    2022-3-1
    发表于 2016-11-7 10:44:44 | 显示全部楼层 |阅读模式
    还有如何清除中断标志,请不要再评论说看官网的例子了,谢谢。
    我知道答案 目前已有1人回答
    回复

    使用道具 举报

  • TA的每日心情

    2017-1-4 08:05
  • 签到天数: 11 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    85

    主题

    1629

    帖子

    1

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    2569

    优秀版主

    最后登录
    2019-3-28
    发表于 2016-11-7 11:39:18 | 显示全部楼层
    本帖最后由 技术范儿 于 2016-11-7 11:47 编辑
    1. /*
    2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
    3. * All rights reserved.
    4. *
    5. * Redistribution and use in source and binary forms, with or without modification,
    6. * are permitted provided that the following conditions are met:
    7. *
    8. * o Redistributions of source code must retain the above copyright notice, this list
    9. *   of conditions and the following disclaimer.
    10. *
    11. * o Redistributions in binary form must reproduce the above copyright notice, this
    12. *   list of conditions and the following disclaimer in the documentation and/or
    13. *   other materials provided with the distribution.
    14. *
    15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
    16. *   contributors may be used to endorse or promote products derived from this
    17. *   software without specific prior written permission.
    18. *
    19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
    23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
    26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    29. */

    30. #include "fsl_debug_console.h"
    31. #include "board.h"

    32. #include "fsl_lptmr.h"
    33. #include "fsl_gpio.h"

    34. #include "pin_mux.h"
    35. #include "clock_config.h"
    36. /*******************************************************************************
    37. * Definitions
    38. ******************************************************************************/
    39. #define LPTMR_LED_HANDLER LPTMR0_IRQHandler
    40. /* Get source clock for LPTMR driver */
    41. #define LPTMR_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_LpoClk)
    42. /* Define LPTMR microseconds counts value */
    43. #define LPTMR_USEC_COUNT 1000000U
    44. #define LED_INIT() LED_RED_INIT(LOGIC_LED_ON)
    45. #define LED_TOGGLE() LED_RED_TOGGLE()

    46. /*******************************************************************************
    47. * Prototypes
    48. ******************************************************************************/

    49. /*******************************************************************************
    50. * Variables
    51. ******************************************************************************/

    52. volatile uint32_t lptmrCounter = 0U;

    53. /*******************************************************************************
    54. * Code
    55. ******************************************************************************/
    56. void LPTMR_LED_HANDLER(void)
    57. {
    58.     LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
    59.     lptmrCounter++;
    60.     LED_TOGGLE();
    61. }

    62. /*!
    63. * @brief Main function
    64. */
    65. int main(void)
    66. {
    67.     uint32_t currentCounter = 0U;
    68.     lptmr_config_t lptmrConfig;

    69.     LED_INIT();

    70.     /* Board pin, clock, debug console init */
    71.     BOARD_InitPins();
    72.     BOARD_BootClockRUN();
    73.     BOARD_InitDebugConsole();

    74.     /* Configure LPTMR */
    75.     /*
    76.      * lptmrConfig.timerMode = kLPTMR_TimerModeTimeCounter;
    77.      * lptmrConfig.pinSelect = kLPTMR_PinSelectInput_0;
    78.      * lptmrConfig.pinPolarity = kLPTMR_PinPolarityActiveHigh;
    79.      * lptmrConfig.enableFreeRunning = false;
    80.      * lptmrConfig.bypassPrescaler = true;
    81.      * lptmrConfig.prescalerClockSource = kLPTMR_PrescalerClock_1;
    82.      * lptmrConfig.value = kLPTMR_Prescale_Glitch_0;
    83.      */
    84.     LPTMR_GetDefaultConfig(&lptmrConfig);

    85.     /* Initialize the LPTMR */
    86.     LPTMR_Init(LPTMR0, &lptmrConfig);

    87.     /* Set timer period */
    88.     LPTMR_SetTimerPeriod(LPTMR0, USEC_TO_COUNT(LPTMR_USEC_COUNT, LPTMR_SOURCE_CLOCK));

    89.     /* Enable timer interrupt */
    90.     LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);

    91.     /* Enable at the NVIC */
    92.     EnableIRQ(LPTMR0_IRQn);

    93.     PRINTF("Low Power Timer Example\r\n");

    94.     /* Start counting */
    95.     LPTMR_StartTimer(LPTMR0);
    96.     while (1)
    97.     {
    98.         if (currentCounter != lptmrCounter)
    99.         {
    100.             currentCounter = lptmrCounter;
    101.             PRINTF("LPTMR interrupt No.%d \r\n", currentCounter);
    102.         }
    103.     }
    104. }
    复制代码
    不知道这样是否否和LZ的胃口,具体操作了那一部分对着代码,理解手册
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-9-11 08:09 , Processed in 0.087501 second(s), 22 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表