资源简介

用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个文件信息

评论

共有 条评论