www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當前位置:首頁 > 單片機 > 單片機
[導讀] 1,開發(fā)環(huán)境 1,適用芯片:STM32F4全部芯片 2,固件庫:STM32F4xx_DSP_StdPeriph_Lib_V1.8.0 3,IDE:MDK5172,驅(qū)動源碼 Delay.h文件/*************************************************************

1,開發(fā)環(huán)境

1,適用芯片:STM32F4全部芯片

2,固件庫:STM32F4xx_DSP_StdPeriph_Lib_V1.8.0

3,IDE:MDK517


2,驅(qū)動源碼

Delay.h文件

/****************************************************************

* Copyright (C) 2016, XinLi, all right reserved.

* File name: Delay.h

* Date: 2016.03.22

* Description: Delay Driver

*****************************************************************/

#ifndef __DELAY_H

#define __DELAY_H

/****************************************************************

* Header include

*****************************************************************/

#include "stm32f4xx.h"

/****************************************************************

* Macro definition

*****************************************************************/

/****************************************************************

* Type definition

*****************************************************************/

/****************************************************************

* Structure definition

*****************************************************************/

#ifdef __cplusplus

extern "C" {

#endif /* __cplusplus */

/****************************************************************

* Variable declaration

*****************************************************************/

/****************************************************************

* Function declaration

*****************************************************************/

void Delay_us(uint64_t nus);

void Delay_ms(uint64_t nms);

void Delay_s(uint64_t ns);

#ifdef __cplusplus

}

#endif /* __cplusplus */

#endif /* __DELAY_H */


Delay.c文件

/****************************************************************

* Copyright (C) 2016, XinLi, all right reserved.

* File name: Delay.c

* Date: 2016.03.22

* Description: Delay Driver

*****************************************************************/

/****************************************************************

* Header include

*****************************************************************/

#include "Delay.h"

/****************************************************************

* Global variables

*****************************************************************/

/****************************************************************

* Function declaration

*****************************************************************/

static void Delay_Init(void);

/****************************************************************

* Function definition

*****************************************************************/

/****************************************************************

* Function: Delay_Init

* Description: Delay Configuration.

* Input:

* Output:

* Return:

*****************************************************************/

static void Delay_Init(void)

{

static uint8_t first = 0;

if(first == 0)

{

first = 1;

SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);

SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Disability SysTick counter */

}

}

/****************************************************************

* Function: Delay_us

* Description: Microsecond delay.

* Input: nus

* Output:

* Return:

*****************************************************************/

void Delay_us(uint64_t nus)

{

uint32_t temp = 0;

uint64_t nms = 0;

Delay_Init();

if(nus == 0)

{

return;

}

nms = nus / 1000;

nus = nus % 1000;

if(nms > 0)

{

Delay_ms(nms);

}

if(nus > 0)

{

SysTick->LOAD = SystemCoreClock / 8000000 * nus; /* Time load (SysTick-> LOAD is 24bit) */

SysTick->VAL = 0x000000; /* Empty counter */

SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; /* Start the countdown */

do

{

temp = SysTick->CTRL;

}

while(temp&0x01 && !(temp&(1<<16))); /* Wait time is reached */

SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Close Counter */

SysTick->VAL = 0x000000; /* Empty counter */

}

}

/****************************************************************

* Function: Delay_ms

* Description: Millisecond delay.

* Input: nms

* Output:

* Return:

*****************************************************************/

void Delay_ms(uint64_t nms)

{

uint32_t temp = 0;

Delay_Init();

if(nms == 0)

{

return;

}

while(nms > 500)

{

SysTick->LOAD = SystemCoreClock / 8000 * 500; /* Time load (SysTick-> LOAD is 24bit) */

SysTick->VAL = 0x000000; /* Empty counter */

SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; /* Start the countdown */

do

{

temp = SysTick->CTRL;

}

while(temp&0x01 && !(temp&(1<<16))); /* Wait time is reached */

SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Close Counter */

SysTick->VAL = 0x000000; /* Empty counter */

nms -= 500;

}

SysTick->LOAD = SystemCoreClock / 8000 * nms; /* Time load (SysTick-> LOAD is 24bit) */

SysTick->VAL = 0x000000; /* Empty counter */

SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; /* Start the countdown */

do

{

temp = SysTick->CTRL;

}

while(temp&0x01 && !(temp&(1<<16))); /* Wait time is reached */

SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Close Counter */

SysTick->VAL = 0x000000; /* Empty counter */

}

/****************************************************************

* Function: Delay_s

* Description: Second delay.

* Input: ns

* Output:

* Return:

*****************************************************************/

void Delay_s(uint64_t ns)

{

while(ns > 0)

{

Delay_ms(1000);

ns--;

}

}



本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

北京——2024年10月29日 亞馬遜云科技日前宣布,通過與光環(huán)新網(wǎng)與西云數(shù)據(jù)的緊密合作,在亞馬遜云科技(北京)區(qū)域和(寧夏)區(qū)域推出Amazon Lambda SnapStart功能,將基于Java Lambda函數(shù)的...

關(guān)鍵字: 函數(shù) 數(shù)據(jù)處理

北京2024年10月29日 /美通社/ -- 亞馬遜云科技日前宣布,通過與光環(huán)新網(wǎng)與西云數(shù)據(jù)的緊密合作,在亞馬遜云科技(北京)區(qū)域和(寧夏)區(qū)域推出Amazon Lambda SnapStart功能,將基于Java La...

關(guān)鍵字: START 亞馬遜 PS 函數(shù)

關(guān)于數(shù)據(jù)分析與可視化,以下介紹Pandas讀取數(shù)據(jù)以及保存數(shù)據(jù)的方法,畢竟我們很多時候需要讀取各種形式的數(shù)據(jù),以及將我們需要將所做的統(tǒng)計分析保存成特定的格式。

關(guān)鍵字: 函數(shù) Panda

深圳2024年8月15日 /美通社/ -- 近日,知名量化交易平臺水母量化正式推出了突破性的輪動交易策略回測功能,目前已進入公測階段。該功能實現(xiàn)了從策略設(shè)計、歷史回測到實盤自動交易一體化流程,幫用戶解決了策略驗證難、交易...

關(guān)鍵字: 編程 仿真 函數(shù) 開源

Python由荷蘭數(shù)學和計算機科學研究學會的吉多·范羅蘇姆于1990年代初設(shè)計,作為一門叫做ABC語言的替代品。 Python提供了高效的高級數(shù)據(jù)結(jié)構(gòu),還能簡單有效地面向?qū)ο缶幊獭?/p> 關(guān)鍵字: python 函數(shù) 對象編程

測試數(shù)據(jù)綜合分析的絕佳工具,深受工程師和研究員歡迎

關(guān)鍵字: 后處理分析軟件 向?qū)?/a> 函數(shù)

由上圖中可以知道進程地址空間中最頂部的段是棧,代碼中調(diào)用函數(shù)、定義局部變量(但不包含static修飾的變量)或聲明的類的實例等等都要使用棧空間,當函數(shù)執(zhí)行完(也就是程序執(zhí)行超過了這個函數(shù)的作用范圍的時候),操作系統(tǒng)會把該...

關(guān)鍵字: 進程地址 局部變量 函數(shù)

星標/置頂?公眾號,硬核文章第一時間送達!鏈接|?https://zhuanlan.zhihu.com/p/274473971題很多,先上題后上答案,便于大家思考問題點:1、C和C的特點與區(qū)別?2、C的多態(tài)3、虛函數(shù)實現(xiàn)...

關(guān)鍵字: 騰訊 函數(shù) 進程 AI

程序接口是操作系統(tǒng)為用戶提供的兩類接口之一,編程人員在程序中通過程序接口來請求操作系統(tǒng)提供服務。面向過程語言最基本的單元是過程和函數(shù)。

關(guān)鍵字: 程序接口 過程 函數(shù)

星標「嵌入式大雜燴」,一起進步!鏈接:https://www.cnblogs.com/jozochen/p/8541714.html一、問題復現(xiàn)穩(wěn)定復現(xiàn)問題才能正確的對問題進行定位、解決以及驗證。一般來說,越容易復現(xiàn)的問...

關(guān)鍵字: 嵌入式開發(fā) 函數(shù) 代碼 寄存器
關(guān)閉