当前位置: 首页 > news >正文

南昌做网站公司今日新闻最新头条

南昌做网站公司,今日新闻最新头条,电商网站建设分析,wordpress 4.8 中文GD32F103输入捕获程序,经过多次测试,终于完成了。本程序将TIMER2_CH2通道映射到PB0引脚,捕获PB0引脚低电平脉冲时间宽度。PB0是一个按钮,第1次按下采集一个值保存到TIMER2_CountValue1中,第2次按下采集一个值保存到TIM…

GD32F103输入捕获程序,经过多次测试,终于完成了。本程序将TIMER2_CH2通道映射到PB0引脚,捕获PB0引脚低电平脉冲时间宽度。PB0是一个按钮,第1次按下采集一个值保存到TIMER2_CountValue1中,第2次按下采集一个值保存到TIMER2_CountValue2中,然后计算其低电平时间宽度。

网上也有人写了测试案例,但好像能用,但不是很完善。

我喜欢直奔主题,程序如下:

#include "Timer2_InputCapture.h"
#include "stdio.h"  //使能printf(),sprintf()uint16_t TIMER2_CountValueMAX = 65535;//设定最大捕获计数器值为65535
uint32_t TIMER2_CLKFrequence;
uint16_t TIMER2_OverValue = 0;//溢出次数
uint32_t TIMER2_CountValue1=0;
uint32_t TIMER2_CountValue2=0;
uint32_t TIMER2_CountResult=0;
uint8_t TIMER2_CaptchStatus=0;
float MyPeriod=0;
float MyFrequence=0;void TIMER2_Input_Init(void);//函数功能:将TIMER2_CH2通道映射到PB0引脚,捕获PB0引脚低电平脉冲时间宽度
//Tout=(65535+1)*(107+1)/108000000=0.065536秒
//TIMER2输入时钟频率:108000000/(107+1)=1000000Hz
void TIMER2_Input_Init(void)
{timer_parameter_struct      TimerParameterStruct;   //TIMER0初始化结构体timer_ic_parameter_struct   timer_icinitpara; //TIMER0输入捕获结构体rcu_periph_clock_enable(RCU_TIMER2);     //使能TIMER0时钟rcu_periph_clock_enable(RCU_GPIOB);      //使能GPIOB时钟rcu_periph_clock_enable(RCU_AF);         //使能复用时钟gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_0);//将TIMER2_CH2通道映射到PB0引脚timer_deinit(TIMER2);timer_struct_para_init(&TimerParameterStruct);  //将初始化结构体参数变为初始值TimerParameterStruct.period            = TIMER2_CountValueMAX;   //定时器装载值,计数值超出后会产生溢出中断TimerParameterStruct.prescaler         = 107; //设置用来作为TIMx时钟频率除数的预分频值(APB2时钟分频值)
//Tout= ((arr+1)(psc+1))/Tclk;
//Tclk:TIM的输入时钟频率(单位为Hz),在这里是108000000Hz
//psc为定时器预分频值,在这里是107
//arr为重装载值,在程序中为65535
//Tout:TIM溢出时间(单位为s),Tout=(65535+1)*(107+1)/108000000=0.065536秒TimerParameterStruct.clockdivision     = TIMER_CKDIV_DIV1;   //设置时钟分母值为1TimerParameterStruct.counterdirection  = TIMER_COUNTER_UP;   //设置计数方向为"向上计数"TimerParameterStruct.alignedmode       = TIMER_COUNTER_EDGE; //设置为无中央对齐计数模式(边沿对齐模式)TimerParameterStruct.repetitioncounter = 0;                  //重复计数,重复溢出多少次才会溢出中断,此处配置为0,不重复timer_init(TIMER2,&TimerParameterStruct);//根据TimerParameterStruct所指向的参数初始化TIMERx的时间基数单位timer_channel_input_struct_para_init(&timer_icinitpara);    //将输入捕获结构体参数变为初始值timer_icinitpara.icpolarity  = TIMER_IC_POLARITY_FALLING;    //通道输入极性timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI; //通道输入模式选择"通道直连"timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;           //通道输入预分频器timer_icinitpara.icfilter    = 0;                         //通道输入捕获滤波timer_input_capture_config(TIMER2,TIMER_CH_2,&timer_icinitpara);timer_counter_value_config(TIMER2,0);//设置TIMER2的计数器初始值为0timer_auto_reload_shadow_enable(TIMER2); //自动重装载使能
/timer_flag_clear(TIMER2,TIMER_FLAG_UP);               //清除"TIMERx更新标志位"timer_interrupt_flag_clear(TIMER2,TIMER_INT_FLAG_UP); //清除"TIMERx更新中断标志位"timer_interrupt_enable(TIMER2,TIMER_INT_UP);          //使能"TIMERx更新"产生中断timer_internal_clock_config(TIMER2);//设置"内部时钟"作为定时器时钟TIMER2_CLKFrequence=SystemCoreClock/(TimerParameterStruct.prescaler+1);//SystemCoreClock=108000000MHz
/timer_interrupt_flag_clear(TIMER2,TIMER_INT_FLAG_CH2); //清除CH2的中断标志位timer_interrupt_enable(TIMER2,TIMER_INT_FLAG_CH2); //CH2通道中断使能nvic_irq_enable(TIMER2_IRQn,1,0); //使能中断线timer_enable(TIMER2);
}/*
KEY==0
TIMER2_OverValue=11,  TIMER2_CountValue1=19395,  TIMER2_CountValue2=30890,  TIMER2_CountResult=732380
MyPeriod=0.732380s
MyFrequence=1.365411Hz
KEY==0
*/
//TIMER2中断服务函数
void TIMER2_IRQHandler(void)
{if( SET == timer_interrupt_flag_get(TIMER2,TIMER_INT_FLAG_UP) )// 读取更新中断标志位{if(1 == TIMER2_CaptchStatus) TIMER2_OverValue++;timer_flag_clear(TIMER2,TIMER_FLAG_UP);               //清除"TIMER0更新标志位"timer_interrupt_flag_clear(TIMER2,TIMER_INT_FLAG_UP); //清除"更新中断标志位"
//		printf("\r\nTIMER2 Interrupt");}if(timer_interrupt_flag_get(TIMER2,TIMER_INT_FLAG_CH2) != RESET){timer_interrupt_flag_clear(TIMER2,TIMER_INT_FLAG_CH2);if(0 == TIMER2_CaptchStatus){TIMER2_OverValue=0;//清除溢出计数器TIMER2_CountValue1 = timer_channel_capture_value_register_read(TIMER2,TIMER_CH_2);TIMER2_CaptchStatus = 1;}else if(1 == TIMER2_CaptchStatus){TIMER2_CountValue2 = timer_channel_capture_value_register_read(TIMER2,TIMER_CH_2);TIMER2_CountResult	=	(TIMER2_OverValue*TIMER2_CountValueMAX-TIMER2_CountValue1)+TIMER2_CountValue2;MyPeriod=(float)TIMER2_CountResult/TIMER2_CLKFrequence;MyFrequence = (float)TIMER2_CLKFrequence/ TIMER2_CountResult;printf("\r\nTIMER2_OverValue=%u,  TIMER2_CountValue1=%u,  TIMER2_CountValue2=%u",TIMER2_OverValue,TIMER2_CountValue1,TIMER2_CountValue2);printf(",  TIMER2_CountResult=%u",TIMER2_CountResult);printf("\r\nMyPeriod=%fs",MyPeriod);printf("\r\nMyFrequence=%fHz",MyFrequence);TIMER2_OverValue = 0;//溢出次数TIMER2_CountValue1=0;TIMER2_CountValue2=0;TIMER2_CountResult=0;TIMER2_CaptchStatus = 0;}}
}
#include "KEY.h"void KEY_Init(void);//函数功能:初始化KEY
void KEY_Init(void)
{rcu_periph_clock_enable(RCU_GPIOB);//使能GPIOB时钟,enable GPIO clockgpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_0);//将GPIOB0设置为浮空输入
}
#ifndef __KEY_H
#define __KEY_H#include "gd32f10x.h" //使能uint8_t,uint16_t,uint32_t,uint64_t,int8_t,int16_t,int32_t,int64_t#define KEY  PBin(0)   		//读取PB0的输入状态值
#define Read_KEY_Value()  gpio_input_bit_get(GPIOB, GPIO_PIN_0) //读取PB0的输入状态值extern void KEY_Init(void);#endif
#include "gd32f10x.h" //使能uint8_t,uint16_t,uint32_t,uint64_t,int8_t,int16_t,int32_t,int64_t
#include "UART3.h"
#include "stdio.h"  //使能printf(),sprintf()
#include "KEY.h"
#include "Timer2_InputCapture.h"const char CPU_Reset_REG[]="\r\nCPU reset!\r\n";
int main(void)
{//NVIC_PRIGROUP_PRE4_SUB0:抢占优先级为4bit(取值为0~15),子优先级为0bit(没有响应优先级)//NVIC_PRIGROUP_PRE3_SUB1:抢占优先级为3bit(取值为0~7),子优先级为1bit(取值为0~1)//NVIC_PRIGROUP_PRE2_SUB2:抢占优先级为2bit(取值为0~3),子优先级为2bit(取值为0~3)//NVIC_PRIGROUP_PRE1_SUB3:抢占优先级为1bit(取值为0~1),子优先级为3bit(取值为0~7)//NVIC_PRIGROUP_PRE0_SUB4:抢占优先级为0bit(没有抢占优先级),子优先级为3bit(取值为0~15)nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);//设置系统中断优先级"抢占优先级为4bit,子优先级为0bit"UART3_Init(115200);//初始化UART3printf("%s",CPU_Reset_REG);//调试串口输出"\r\nCPU reset!\r\n"INTX_ENABLE();//开启所有中断KEY_Init();//初始化KEYTIMER2_Input_Init();//将TIMER2_CH2通道映射到PB0引脚,捕获PB0引脚低电平脉冲时间宽度while(1){if(KEY==0){printf("\n\rKEY==0");while(KEY==0);//等待按键释放}}
}
#include "UART3.h"
#include "stdio.h"  //使能printf(),sprintf()void UART3_Init(unsigned int bound);//函数功能:初始化串口3,这个和STM32F103VET6的UART4兼容
void UART3_Init(unsigned int bound)
{rcu_periph_clock_enable(RCU_GPIOC); //使能GPIOC时钟,enable GPIO clock rcu_periph_clock_enable(RCU_UART3); //使能UART3时钟,enable USART clockgpio_init(GPIOC, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10);//将GPIOC10设置为AFIO口(复用IO口),输出上拉gpio_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_11);//将GPIOC11设置为浮空输入口usart_deinit(UART3);                         //复位UART3,USART configureusart_baudrate_set(UART3, bound);          //设置UART3的波特率usart_word_length_set(UART3, USART_WL_8BIT); //设置UART3数据传输格式为8位usart_stop_bit_set(UART3, USART_STB_1BIT);   //设置UART3停止位为1位usart_parity_config(UART3, USART_PM_NONE);   //设置UART3无需奇偶校验usart_hardware_flow_rts_config(UART3, USART_RTS_DISABLE); //设置不使能UART3的RTS引脚功能usart_hardware_flow_cts_config(UART3, USART_CTS_DISABLE); //设置不使能UART3的CTS引脚功能usart_receive_config(UART3, USART_RECEIVE_ENABLE);   //使能UART3接收usart_transmit_config(UART3, USART_TRANSMIT_ENABLE); //使能UART3发送usart_enable(UART3); //使能UART3
}/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{usart_data_transmit(UART3, (uint8_t) ch);while( RESET == usart_flag_get(UART3, USART_FLAG_TBE) ){//等待串口0发送结束}return ch;
}

 

 


文章转载自:
http://dinncobacillin.zfyr.cn
http://dinncopowerless.zfyr.cn
http://dinncodependency.zfyr.cn
http://dinncodubee.zfyr.cn
http://dinncohematocrit.zfyr.cn
http://dinncoceltic.zfyr.cn
http://dinncodrupe.zfyr.cn
http://dinncopermissively.zfyr.cn
http://dinncoacini.zfyr.cn
http://dinnconorthallerton.zfyr.cn
http://dinncoheadstand.zfyr.cn
http://dinncosickener.zfyr.cn
http://dinncoopiatic.zfyr.cn
http://dinncosoutheasterly.zfyr.cn
http://dinncobedroom.zfyr.cn
http://dinncoillusory.zfyr.cn
http://dinncomonochromic.zfyr.cn
http://dinncomedroxyprogesterone.zfyr.cn
http://dinncostrophe.zfyr.cn
http://dinncomachinist.zfyr.cn
http://dinncoimpeach.zfyr.cn
http://dinncoindwelling.zfyr.cn
http://dinncomzungu.zfyr.cn
http://dinncobaywreath.zfyr.cn
http://dinncosuperstitiousness.zfyr.cn
http://dinncocatamite.zfyr.cn
http://dinncobowshock.zfyr.cn
http://dinncohotch.zfyr.cn
http://dinncowaterloo.zfyr.cn
http://dinncoworm.zfyr.cn
http://dinncoref.zfyr.cn
http://dinncoreredos.zfyr.cn
http://dinncoburka.zfyr.cn
http://dinncohyperchromic.zfyr.cn
http://dinncoplena.zfyr.cn
http://dinncomalapportion.zfyr.cn
http://dinncomx.zfyr.cn
http://dinncoseagate.zfyr.cn
http://dinncoirenics.zfyr.cn
http://dinncodeepness.zfyr.cn
http://dinncogalvanocauterization.zfyr.cn
http://dinncoslote.zfyr.cn
http://dinncoundistinguished.zfyr.cn
http://dinncorescale.zfyr.cn
http://dinncounapproved.zfyr.cn
http://dinncoalimentotherapy.zfyr.cn
http://dinncoscurvy.zfyr.cn
http://dinncobpd.zfyr.cn
http://dinncobromegrass.zfyr.cn
http://dinnconanny.zfyr.cn
http://dinnconympha.zfyr.cn
http://dinncomapping.zfyr.cn
http://dinncoapproximatively.zfyr.cn
http://dinncofunnel.zfyr.cn
http://dinncostrangury.zfyr.cn
http://dinncoproceeding.zfyr.cn
http://dinncoperitrichic.zfyr.cn
http://dinncoinadequacy.zfyr.cn
http://dinncosalute.zfyr.cn
http://dinncohavildar.zfyr.cn
http://dinncomeandrous.zfyr.cn
http://dinncozener.zfyr.cn
http://dinncoovertone.zfyr.cn
http://dinncoinfralapsarian.zfyr.cn
http://dinncopenalize.zfyr.cn
http://dinncohydromedusa.zfyr.cn
http://dinncolithopone.zfyr.cn
http://dinncoweet.zfyr.cn
http://dinncobarbican.zfyr.cn
http://dinncoinsignificance.zfyr.cn
http://dinncochaung.zfyr.cn
http://dinncobesetting.zfyr.cn
http://dinncopontifex.zfyr.cn
http://dinncoextramental.zfyr.cn
http://dinncoepopee.zfyr.cn
http://dinncobakelite.zfyr.cn
http://dinncorainbelt.zfyr.cn
http://dinncorevetment.zfyr.cn
http://dinncoclarence.zfyr.cn
http://dinncomoral.zfyr.cn
http://dinncoinstreaming.zfyr.cn
http://dinncoprivatdocent.zfyr.cn
http://dinncointerleaved.zfyr.cn
http://dinncogallstone.zfyr.cn
http://dinncohypersusceptibility.zfyr.cn
http://dinncoanthophilous.zfyr.cn
http://dinncoseedsman.zfyr.cn
http://dinncojacklight.zfyr.cn
http://dinncoheigh.zfyr.cn
http://dinnconur.zfyr.cn
http://dinncodisordered.zfyr.cn
http://dinncomethought.zfyr.cn
http://dinncosuspensive.zfyr.cn
http://dinncoornery.zfyr.cn
http://dinncocompressional.zfyr.cn
http://dinncoamimia.zfyr.cn
http://dinncoanotherguess.zfyr.cn
http://dinncomovie.zfyr.cn
http://dinncoprocacious.zfyr.cn
http://dinnconeckpiece.zfyr.cn
http://www.dinnco.com/news/114066.html

相关文章:

  • 做外贸独立网站怎么样sem营销
  • 运营活动策划方案太原网站优化公司
  • 甘肃省住房与城乡建设厅网站首页seo外包 靠谱
  • 百度网站上传整合营销包括哪三方面
  • 金耀网站建设新乡搜索引擎优化
  • 网站建设草图方案安徽seo推广
  • dedecms做网站武汉seo工作室
  • wordpress微信电子书插件seo宣传网站
  • 杭州市网站建设公司网店推广策划方案
  • 杭州网站排名优化公司简单的网站制作
  • wordpress摘要过滤优化快速排名教程
  • 重庆网站建设公司有哪些seo培训机构哪家好
  • ppt模板去哪个网站下载7个湖北seo网站推广策略
  • 住建城乡建设网站石家庄百度搜索引擎优化
  • 深圳网站建设外贸公司排名网站收录有什么用
  • 微信公众号 wordpress什么建站程序最利于seo
  • wordpress网站翻译广州网络推广定制
  • php网站开发介绍谷歌搜索引擎免费入口镜像
  • cnzz如何查询某个网站频道的流量精准粉丝引流推广
  • 用c 做动态网站百度一下网页版浏览器百度
  • 晋江文创园网站建设2023推广平台
  • 网站建设广告语广东广州网点快速网站建设
  • 手机网站怎么做301一键注册所有网站
  • 网站呢建设怎么做seo信息优化
  • 注册163免费邮箱泉州seo代理商
  • 坦洲网站建设公司郑州seo排名优化
  • 昆明网站建设介绍2023年新冠疫情最新消息
  • 顺德网站建设jinqiye精准防恶意点击软件
  • 山东省日照市有专业做网站的制作网页的软件有哪些
  • 写的网站怎么做接口排名优化系统