資源簡介
stm32夏普紅外模塊測距,輸出到LCD上面。
代碼片段和文件信息
#include?“delay.h“
#include?
#include?
////////////////////////////////////////////////////////////////////////////////// ?
//本程序只供學(xué)習(xí)使用,未經(jīng)作者許可,不得用于其它任何用途
//Mini?STM32開發(fā)板
//使用SysTick的普通計數(shù)模式對延遲進(jìn)行管理
//包括delay_usdelay_ms
//正點(diǎn)原子@ALIENTEK
//技術(shù)論壇:www.openedv.com
//修改日期:2010/5/27
//版本:V1.2
//版權(quán)所有,盜版必究。
//Copyright(C)?正點(diǎn)原子?2009-2019
//All?rights?reserved
//********************************************************************************
//V1.2修改說明
//修正了中斷中調(diào)用出現(xiàn)死循環(huán)的錯誤
//防止延時不準(zhǔn)確采用do?while結(jié)構(gòu)!
////////////////////////////////////////////////////////////////////////////////// ?
static?unsigned?char?fac_us=0;//us延時倍乘數(shù)
static?unsigned?short?int?fac_ms=0;//ms延時倍乘數(shù)
//初始化延遲函數(shù)
//SYSTICK的時鐘固定為HCLK時鐘的1/8
//SYSCLK:系統(tǒng)時鐘
void?delay_init(unsigned?char?SYSCLK)
{
// SysTick->CTRL&=0xfffffffb;//bit2清空選擇外部時鐘??HCLK/8
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //選擇外部時鐘??HCLK/8
fac_us=SYSCLK/8; ????
fac_ms=(unsigned?short?int)fac_us*1000;
} ????
//延時nms
//注意nms的范圍
//SysTick->LOAD為24位寄存器所以最大延時為:
//nms<=0xffffff*8*1000/SYSCLK
//SYSCLK單位為Hznms單位為ms
//對72M條件下nms<=1864?
void?delay_ms(unsigned?short?int?nms)
{ ? ?? ??
unsigned?long?int?temp; ???
SysTick->LOAD=(unsigned?long?int)nms*fac_ms;//時間加載(SysTick->LOAD為24bit)
SysTick->VAL?=0x00;???????????//清空計數(shù)器
SysTick->CTRL=0x01?;??????????//開始倒數(shù)??
do
{
temp=SysTick->CTRL;
}
while(temp&0x01&&!(temp&(1<<16)));//等待時間到達(dá)???
SysTick->CTRL=0x00;???????//關(guān)閉計數(shù)器
SysTick->VAL?=0X00;???????//清空計數(shù)器 ?? ????
}???
//延時nus
//nus為要延時的us數(shù). ???? ???
void?delay_us(unsigned?long?int?nus)
{
unsigned?long?int?temp; ???? ?
SysTick->LOAD=nus*fac_us;?//時間加載 ?? ?
SysTick->VAL=0x00;????????//清空計數(shù)器
SysTick->CTRL=0x01?;??????//開始倒數(shù)? ?
do
{
temp=SysTick->CTRL;
}
while(temp&0x01&&!(temp&(1<<16)));//等待時間到達(dá)???
SysTick->CTRL=0x00;???????//關(guān)閉計數(shù)器
SysTick->VAL?=0X00;???????//清空計數(shù)器 ?
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-08-12?13:28??hongwai\
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\
?????文件???????51511??2013-07-22?15:36??hongwai\Libraries\CMSIS\CMSIS?END?USER?LICENCE?AGREEMENT.pdf
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\ST\
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Include\
?????文件??????237739??2013-07-22?15:36??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Include\stm32f0xx.h
?????文件????????2220??2013-07-22?15:36??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Include\system_stm32f0xx.h
?????文件???????17060??2013-07-22?15:36??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Release_Notes.html
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\TrueSTUDIO\
?????文件????????8721??2013-07-22?15:36??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\TrueSTUDIO\startup_stm32f0xx.s
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\arm\
?????文件???????10646??2013-07-22?15:36??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\arm\startup_stm32f0xx.s
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\gcc_ride7\
?????文件????????8515??2013-07-22?15:36??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\gcc_ride7\startup_stm32f0xx.s
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\iar\
?????文件???????11163??2013-07-22?15:36??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\iar\startup_stm32f0xx.s
?????文件???????12412??2013-07-22?15:36??hongwai\Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\system_stm32f0xx.c
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Documentation\
?????文件???????13643??2013-07-22?15:36??hongwai\Libraries\CMSIS\Documentation\CMSIS-SVD_Schema_1_0.xsd
?????文件??????127419??2013-07-22?15:36??hongwai\Libraries\CMSIS\Documentation\CMSIS_CM4_SIMD.htm
?????文件???????65406??2013-07-22?15:36??hongwai\Libraries\CMSIS\Documentation\CMSIS_Core.htm
?????文件????????9956??2013-07-22?15:36??hongwai\Libraries\CMSIS\Documentation\CMSIS_DebugSupport.htm
?????文件???????17863??2013-07-22?15:36??hongwai\Libraries\CMSIS\Documentation\CMSIS_History.htm
?????文件??????123676??2013-07-22?15:36??hongwai\Libraries\CMSIS\Documentation\CMSIS_Logo_Final.jpg
?????文件???????67286??2013-07-22?15:36??hongwai\Libraries\CMSIS\Documentation\CMSIS_System_View_Desc
?????目錄???????????0??2013-07-27?16:13??hongwai\Libraries\CMSIS\Include\
............此處省略541個文件信息
評論
共有 條評論