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

  • 相关阅读:
    Java通过socket和DTU,RTU连接工业传感器通信
    没有远程桌面授权服务器可以提供许可证 相关,注册表项获得权限方法
    freertos内存pvPortMalloc 和 malloc 区别 ,以及全局变量占用情况
    自学it吧论坛
    安全学习地址
    服务器zfs文件系统修复过程记录
    第1年10月11日 android canvas
    第1年10月9日 swiftui
    第1年9月28日 Android 4.4以后,浏览器内核采用的chromium,可以支持webrtc
    第1年9月19日 ios librtmp
  • 原文地址:https://www.cnblogs.com/xiaobin-hlj80/p/4712397.html
Copyright © 2011-2022 走看看