zoukankan      html  css  js  c++  java
  • 系统节拍的使用

       我们在使用SysTick时,首先要确定时钟周期;然后才能使用它。

        SysTick的最大计数值为:2^24(2的24次方)

        超过此值,系统自动置0。

        在配置的时候,如果超过此值;不启动SysTick。

    #define SYSTICK_MAXCOUNT       ((1<<24) -1)                                    /* SysTick MaxCount                                                      */

    #if (__Vendor_SysTickConfig == 0)

    /** rief  System Tick Configuration

        This function initialises the system tick timer and its interrupt and start the system tick timer.
        Counter is in free running mode to generate periodical interrupts.

        param [in]  ticks  Number of ticks between two interrupts
        eturn          0  Function succeeded
        eturn          1  Function failed
    */
    static __INLINE uint32_t SysTick_Config(uint32_t ticks)
    {
      //if (ticks > SysTick_LOAD_RELOAD_Msk)  return (1);            /* Reload value impossible */
      if (ticks > SYSTICK_MAXCOUNT)  return (1);            /* Reload value impossible */
      SysTick->LOAD  = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;      /* set reload register */
      NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);  /* set Priority for Cortex-M0 System Interrupts */
      SysTick->VAL   = 0;                                          /* Load the SysTick Counter Value */
      SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
                       SysTick_CTRL_TICKINT_Msk   |
                       SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */
      return (0);                                                  /* Function successful */
    }

    #endif

    /*@} end of CMSIS_Core_SysTickFunctions */

    注意,在CMSIS V2.02是没有“SYSTICK_MAXCOUNT”宏定义的。

    我们在使用这个函数,之前需要作2件事情:

    1. 初始化系统时钟

    SystemCoreClockUpdate();

    2. 确定50us的时钟值

    #define PCLK            (SystemCoreClock / 4)
    #define PCLK_BENCHMARK  (PCLK / 1000)
    #define PCLK_50US       (PCLK_BENCHMARK / 5)

    主程序:

    /****************************************Copyright (c)****************************************************
    **                                 TDTC Tech Dev
    **                                     HRB
    **--------------File Info---------------------------------------------------------------------------------
    ** File name:           main.c
    ** Last modified Date: 
    ** Last Version:       
    ** Descriptions:       
    **
    **--------------------------------------------------------------------------------------------------------
    ** Created by:          TDTC
    ** Created date:        2015-07-09
    ** Version:             V0.01
    ** Descriptions:        UART Send
    **
    **--------------------------------------------------------------------------------------------------------      
    *********************************************************************************************************/
    #include "LPC17xx.h"
    //#include "uart.h"

    #define    LED          1UL << 2                                 /* P2.2       */
    #define    LED_INIT()   LPC_GPIO2->FIODIR |= LED                 /* LED INIT   */
    #define    LED_OFF()    LPC_GPIO2->FIOSET |= LED                 /* LED OFF    */
    #define    LED_ON()     LPC_GPIO2->FIOCLR |= LED                 /* LED ON     */

    #define PCLK            (SystemCoreClock / 4)
    #define PCLK_BENCHMARK  (PCLK / 1000)
    #define PCLK_50US       (PCLK_BENCHMARK / 5)

    void SysTick_Handler (void)
    {
        static uint32_t count=0;
            count++;
            if(count%2) {
                LED_ON();
            } else {
                LED_OFF();
            } 
    }

    int main(void)
    {
        SystemCoreClockUpdate();
        //UARTInit(0, 19200);
        LED_INIT();
        LED_OFF();
        SysTick_Config( PCLK_50US * 20 ); // 1ms


        while (1) {
            ;
        }
    }

    我们在系统节拍中断(SysTick_Handler)中进行闪灯, 以此激活波形。

    在Saleae逻辑分析仪中的波形图

    wave_systick

  • 相关阅读:
    入门指引之实现简单的被动回复和图来图往
    入门指引
    实现待办事项网站回顾
    使用Django 测试客户端一起测试视图,模板和URL
    使用单元测试测试简单的首页
    2 使用unitest 模块扩展功能测试
    1 准备工作
    2018 开始认真学习点python
    边学边体验django--HttpRequest 对象
    边学边体验django--表格
  • 原文地址:https://www.cnblogs.com/xiaobin-hlj80/p/4712397.html
Copyright © 2011-2022 走看看