資源簡介
用STM8s003單片機實現定時器2通道1輸入捕獲功能,TIM2 _CH1口輸入方波,用輸入捕獲功能測試輸入波形的周期并計算頻率。并通過串口發送出來。

代碼片段和文件信息
#include?“iostm8s103F3.h“
#include?“capture.h“
#include?“led.h“
#include?“uart.h“
#include?“stdio.h“
extern?_Bool?IsOk_Flag;
extern?unsigned?long?cycle;
extern?unsigned?long?frequency;
void?SysClkInit(?void?)
{
????CLK_SWR?=?0xe1;???????//HSI為主時鐘源??16MHz?CPU時鐘頻率
????CLK_CKDIVR?=?0x00;????//CPU時鐘0分頻,系統時鐘0分頻
}
void?main(?void?)
{
?
????SysClkInit();
????__asm(?“sim“?);???????????????????????//禁止中斷
????Uart1_Init(?9600?);
????TIM2_Capture1_Init();
????__asm(?“rim“?);???????????????????????//開啟中斷
????while(?1?)
????{
??????
????????if(?IsOk_Flag?)
????????{
????????????IsOk_Flag?=?0;
????????????printf(?“prd=%ld?us??fre?=?%ld?Hz\r\n“?cycle?frequency?);
??????????
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-08-07?09:29??STM8S_TIM2_Capture\
?????文件????????2397??2018-05-15?14:52??STM8S_TIM2_Capture\BuildLog.log
?????文件????????9966??2019-08-07?09:29??STM8S_TIM2_Capture\capture.dep
?????文件???????16039??2018-05-15?16:50??STM8S_TIM2_Capture\capture.ewd
?????文件???????58666??2019-08-06?17:45??STM8S_TIM2_Capture\capture.ewp
?????文件??????160677??2019-08-06?11:11??STM8S_TIM2_Capture\capture.ewt
?????文件?????????161??2019-08-06?08:51??STM8S_TIM2_Capture\capture.eww
?????目錄???????????0??2019-08-07?09:12??STM8S_TIM2_Capture\Debug\
?????目錄???????????0??2019-08-07?09:29??STM8S_TIM2_Capture\Debug\Exe\
?????文件???????12534??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Exe\CAPTURE.hex
?????文件???????82828??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Exe\CAPTURE.out
?????目錄???????????0??2019-08-07?09:29??STM8S_TIM2_Capture\Debug\List\
?????文件???????26213??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\List\CAPTURE.map
?????目錄???????????0??2019-08-07?09:29??STM8S_TIM2_Capture\Debug\Obj\
?????文件???????16541??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Obj\capture.o
?????文件??????269129??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Obj\capture.pbd
?????文件??????269129??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Obj\capture.pbd.browse
?????文件?????????258??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Obj\capture.pbd.linf
?????文件??????227233??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Obj\capture.pbi
?????文件???????11545??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Obj\capture.pbi.xcl
?????文件????????6194??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Obj\led.o
?????文件??????224885??2019-08-07?09:13??STM8S_TIM2_Capture\Debug\Obj\led.pbi
?????文件???????11541??2019-08-07?09:13??STM8S_TIM2_Capture\Debug\Obj\led.pbi.xcl
?????文件????????7915??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Obj\main.o
?????文件??????265565??2019-08-07?09:14??STM8S_TIM2_Capture\Debug\Obj\main.pbi
?????文件???????11533??2019-08-07?09:14??STM8S_TIM2_Capture\Debug\Obj\main.pbi.xcl
?????文件???????17606??2019-08-07?09:21??STM8S_TIM2_Capture\Debug\Obj\uart.o
?????文件??????226861??2019-08-07?09:13??STM8S_TIM2_Capture\Debug\Obj\uart.pbi
?????文件???????11542??2019-08-07?09:13??STM8S_TIM2_Capture\Debug\Obj\uart.pbi.xcl
?????目錄???????????0??2019-08-07?09:29??STM8S_TIM2_Capture\HardWare\
?????文件????????2274??2019-08-07?09:21??STM8S_TIM2_Capture\HardWare\capture.c
............此處省略26個文件信息
評論
共有 條評論