WFLY 2.4G 遥控器接收机 STM32F1x开发
程序员文章站
2024-02-21 21:05:17
...
一、遥控器和接收头类型
1.1 天地飞 WFT06X-A 2.4GHz 6通道遥控器
商品规格:六通道2.4G
1.2 WFR06S 2.4G 6通接收机
■产品规格:
频 段: 2.400GHz-2.483GHz
灵 敏 度: -97dBm
地面直线距离:大于700米
解码方式: PPM/PCMS 1024/PCMS 4096
电 源: 4.8-6V
尺 寸: 34.85×21×11.3mm
重 量: 5.8g
关于PPM解码方式,可以查看这篇文章。
https://www.docin.com/p-1556658364.html
1.3 对频说明:
1)发射机调到对频状态
2)接收机通电,长安SET键,灯闪硕进入对频状态,灯熄灭,对频成功!
那么如何对频呢?
一般流传的方法是:先摁住遥控器上的SET按钮,打开遥控器电源开关,遥控器上LED灯变红色并闪亮;再摁住接收器上LINK 按钮并打开接收电源开关,接收和遥控器的LED灯变绿并常亮。则对频成功。
1.4 模块线的连接
接收头连接单片机 | 接收头有 3 排引脚 |
---|---|
3 排引脚顺序 | 电源 - ,5V电源 + (正负接反,接收头就炸了),6个信号引脚 |
信号引脚 1 | PB 6 |
信号引脚 2 | PB 7 |
信号引脚 3 | PB 8 |
信号引脚 4 | PB 9 |
信号引脚 5 | PA 2 |
信号引脚 6 | PA 3 |
串口调试模块 | |
---|---|
5V | 5V |
TXD | PA10 |
RXD | PA9 |
GND | GND |
ST-LINK | |
---|---|
SWCLK | 缺口靠左-左排-上至下-第5 个针 |
SWDIO | 缺口靠左-左排-上至下-第4 个针 |
GND | 缺口靠左-右排-上至下-最后1个针 |
3.3v | 缺口靠左-右排-上至下-第2 个针 |
1.5 遥控器通道, tempup1, tempup2, tempup3 - - - 等值的测量范围,如图所示
二、程序开发
2.1 主函数程序
#include "stm32f10x.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "wlfy.h"
extern u32 tempup1; //通道 1 捕获总高电平的时间
extern u32 tempup2; //通道 2 捕获总高电平的时间
extern u32 tempup3; //通道 3 捕获总高电平的时间
extern u32 tempup4; //通道 4 捕获总高电平的时间
extern u32 tempup5; //通道 5 捕获总高电平的时间
extern u32 tempup6; //通道 6 捕获总高电平的时间
int main(void)
{
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
TIM4_Cap_Init(0xffff,72-1);
TIM5_Cap_Init(0xffff,72-1);
uart_init(9600);
while(1)
{
printf("tempup 1 is %d \r\n",tempup1);
printf("tempup 2 is %d \r\n",tempup2);
printf("tempup 3 is %d \r\n",tempup3);
printf("tempup 4 is %d \r\n",tempup4);
printf("tempup 5 is %d \r\n",tempup5);
printf("tempup 6 is %d \r\n",tempup6);
printf("\r\n");
printf("\r\n");
printf("\r\n");
printf("\r\n");
delay_ms(2000);
}
}
2.2 遥控器 通信程序
关于遥控器到底如何控制你要控制的东西,根据tempup1、tempup2、tempup3 - - -的值,自己另行编程序
.h头文件
#include "sys.h"
void TIM4_Cap_Init(u16 arr, u16 psc);
void TIM5_Cap_Init(u16 arr, u16 psc);
.c文件
#include "wlfy.h"
u8 TIM4CH1_CAPTURE_STA = 0; //通道1输入捕获标志,高两位做捕获标志,低6位做溢出标志
u16 TIM4CH1_CAPTURE_UPVAL;
u16 TIM4CH1_CAPTURE_DOWNVAL;
u8 TIM4CH2_CAPTURE_STA = 0; //通道2输入捕获标志,高两位做捕获标志,低6位做溢出标志
u16 TIM4CH2_CAPTURE_UPVAL;
u16 TIM4CH2_CAPTURE_DOWNVAL;
u8 TIM4CH3_CAPTURE_STA = 0; //通道3输入捕获标志,高两位做捕获标志,低6位做溢出标志
u16 TIM4CH3_CAPTURE_UPVAL;
u16 TIM4CH3_CAPTURE_DOWNVAL;
u8 TIM4CH4_CAPTURE_STA = 0; //通道4输入捕获标志,高两位做捕获标志,低6位做溢出标志
u16 TIM4CH4_CAPTURE_UPVAL;
u16 TIM4CH4_CAPTURE_DOWNVAL;
u8 TIM5CH3_CAPTURE_STA = 0; //通道5输入捕获标志,高两位做捕获标志,低6位做溢出标志
u16 TIM5CH3_CAPTURE_UPVAL;
u16 TIM5CH3_CAPTURE_DOWNVAL;
u8 TIM5CH4_CAPTURE_STA = 0; //通道6输入捕获标志,高两位做捕获标志,低6位做溢出标志
u16 TIM5CH4_CAPTURE_UPVAL;
u16 TIM5CH4_CAPTURE_DOWNVAL;
// 最后在做遥控器控制时,只要根据这六个 tempupx 的值,进行程序编写就好了。
// 和遥控器信号连接时,具体数值看上面的图 ;;在断开连接时,通道3的值在 1018 左右;其它的值都是 1520 左右;
// 可以用这个特征,判断是信号连接还是中断
u32 tempup1 = 0; //捕获总高电平的时间
u32 tempup2 = 0; //捕获总高电平的时间
u32 tempup3 = 0; //捕获总高电平的时间
u32 tempup4 = 0; //捕获总高电平的时间
u32 tempup5 = 0;
u32 tempup6 = 0;
u32 tim4_T1;
u32 tim4_T2;
u32 tim4_T3;
u32 tim4_T4;
u32 tim5_T3;
u32 tim5_T4;
int pwmout1, pwmout2, pwmout3, pwmout4,pwmout5,pwmout6; //输出占空比
//定时器4通道1输入捕获配置
TIM_ICInitTypeDef TIM4_ICInitStructure;
TIM_ICInitTypeDef TIM5_ICInitStructure;
void TIM4_Cap_Init(u16 arr, u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //使能TIM4时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能GPIOB时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8| GPIO_Pin_9; //PB6,7,8,9 清除之前设置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PB6,7,8,9 输入
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9);//PB6,7,8,9 下拉
//初始化定时器4 TIM4
TIM_TimeBaseStructure.TIM_Period = arr; //设定计数器自动重装值
TIM_TimeBaseStructure.TIM_Prescaler = psc; //预分频器
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位
//初始化TIM4输入捕获参数 通道1
TIM4_ICInitStructure.TIM_Channel = TIM_Channel_1; //CC1S=01 选择输入端 IC1映射到TI1上
TIM4_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM4_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1上
TIM4_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM4_ICInitStructure.TIM_ICFilter = 0x00; //IC1F=0000 配置输入滤波器 不滤波
TIM_ICInit(TIM4, &TIM4_ICInitStructure);
//初始化TIM4输入捕获参数 通道2
TIM4_ICInitStructure.TIM_Channel = TIM_Channel_2; //CC1S=01 选择输入端 IC1映射到TI1上
TIM4_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM4_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1上
TIM4_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM4_ICInitStructure.TIM_ICFilter = 0x00; //IC1F=0000 配置输入滤波器 不滤波
TIM_ICInit(TIM4, &TIM4_ICInitStructure);
//初始化TIM4输入捕获参数 通道3
TIM4_ICInitStructure.TIM_Channel = TIM_Channel_3; //CC1S=01 选择输入端 IC1映射到TI1上
TIM4_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM4_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1上
TIM4_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM4_ICInitStructure.TIM_ICFilter = 0x00; //IC1F=0000 配置输入滤波器 不滤波
TIM_ICInit(TIM4, &TIM4_ICInitStructure);
//初始化TIM4输入捕获参数 通道4
TIM4_ICInitStructure.TIM_Channel = TIM_Channel_4; //CC1S=01 选择输入端 IC1映射到TI1上
TIM4_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM4_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1上
TIM4_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM4_ICInitStructure.TIM_ICFilter = 0x00; //IC1F=0000 配置输入滤波器 不滤波
TIM_ICInit(TIM4, &TIM4_ICInitStructure);
//中断分组初始化
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; //TIM4中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //先占优先级1级
//NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //从优先级0级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
TIM_ITConfig(TIM4, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4,
ENABLE); //不允许更新中断,允许CC1IE,CC2IE,CC3IE,CC4IE捕获中断
TIM_Cmd(TIM4, ENABLE); //使能定时器4
}
void TIM5_Cap_Init(u16 arr, u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE); //使能TIM5时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能GPIOA时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 ; //PA2,3 清除之前设置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA2,3 输入
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA, GPIO_Pin_2 | GPIO_Pin_3);//PA2,3 下拉
//初始化定时器5 TIM5
TIM_TimeBaseStructure.TIM_Period = arr; //设定计数器自动重装值
TIM_TimeBaseStructure.TIM_Prescaler = psc; //预分频器
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位
//初始化TIM5输入捕获参数 通道1
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_3; //CC1S=01 选择输入端 IC1映射到TI1上
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1上
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM5_ICInitStructure.TIM_ICFilter = 0x00; //IC1F=0000 配置输入滤波器 不滤波
TIM_ICInit(TIM5, &TIM5_ICInitStructure);
//初始化TIM4输入捕获参数 通道2
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_4; //CC1S=01 选择输入端 IC1映射到TI1上
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1上
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM5_ICInitStructure.TIM_ICFilter = 0x00; //IC1F=0000 配置输入滤波器 不滤波
TIM_ICInit(TIM5, &TIM5_ICInitStructure);
//中断分组初始化
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn; //TIM4中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //先占优先级1级
//NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //从优先级0级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
TIM_ITConfig(TIM5, TIM_IT_CC3 | TIM_IT_CC4,ENABLE); //不允许更新中断,允许CC3IE,CC4IE捕获中断
TIM_Cmd(TIM5, ENABLE); //使能定时器4
}
//定时器4中断服务程序
void TIM4_IRQHandler(void)
{
if ((TIM4CH1_CAPTURE_STA & 0X80) == 0) //还未成功捕获
{
if (TIM_GetITStatus(TIM4, TIM_IT_CC1) != RESET) //捕获1发生捕获事件
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC1); //清除中断标志位
if (TIM4CH1_CAPTURE_STA & 0X40) //捕获到一个下降沿
{
TIM4CH1_CAPTURE_DOWNVAL = TIM_GetCapture1(TIM4);//记录下此时的定时器计数值
if (TIM4CH1_CAPTURE_DOWNVAL < TIM4CH1_CAPTURE_UPVAL)
{
tim4_T1 = 65535;
}
else
tim4_T1 = 0;
tempup1 = TIM4CH1_CAPTURE_DOWNVAL - TIM4CH1_CAPTURE_UPVAL
+ tim4_T1; //得到总的高电平的时间
pwmout1 = tempup1; //总的高电平的时间
TIM4CH1_CAPTURE_STA = 0; //捕获标志位清零
TIM_OC1PolarityConfig(TIM4, TIM_ICPolarity_Rising); //设置为上升沿捕获
}
else //发生捕获时间但不是下降沿,第一次捕获到上升沿,记录此时的定时器计数值
{
TIM4CH1_CAPTURE_UPVAL = TIM_GetCapture1(TIM4); //获取上升沿数据
TIM4CH1_CAPTURE_STA |= 0X40; //标记已捕获到上升沿
TIM_OC1PolarityConfig(TIM4, TIM_ICPolarity_Falling);//设置为下降沿捕获
}
}
}
if ((TIM4CH2_CAPTURE_STA & 0X80) == 0) //还未成功捕获
{
if (TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET) //捕获2发生捕获事件
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC2); //清除中断标志位
if (TIM4CH2_CAPTURE_STA & 0X40) //捕获到一个下降沿
{
TIM4CH2_CAPTURE_DOWNVAL = TIM_GetCapture2(TIM4);//记录下此时的定时器计数值
if (TIM4CH2_CAPTURE_DOWNVAL < TIM4CH2_CAPTURE_UPVAL)
{
tim4_T2 = 65535;
}
else
tim4_T2 = 0;
tempup2 = TIM4CH2_CAPTURE_DOWNVAL - TIM4CH2_CAPTURE_UPVAL
+ tim4_T2; //得到总的高电平的时间
pwmout2 = tempup2; //总的高电平的时间
TIM4CH2_CAPTURE_STA = 0; //捕获标志位清零
TIM_OC2PolarityConfig(TIM4, TIM_ICPolarity_Rising); //设置为上升沿捕获
}
else //发生捕获时间但不是下降沿,第一次捕获到上升沿,记录此时的定时器计数值
{
TIM4CH2_CAPTURE_UPVAL = TIM_GetCapture2(TIM4); //获取上升沿数据
TIM4CH2_CAPTURE_STA |= 0X40; //标记已捕获到上升沿
TIM_OC2PolarityConfig(TIM4, TIM_ICPolarity_Falling);//设置为下降沿捕获
}
}
}
if ((TIM4CH3_CAPTURE_STA & 0X80) == 0) //还未成功捕获
{
if (TIM_GetITStatus(TIM4, TIM_IT_CC3) != RESET) //捕获3发生捕获事件
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC3); //清除中断标志位
if (TIM4CH3_CAPTURE_STA & 0X40) //捕获到一个下降沿
{
TIM4CH3_CAPTURE_DOWNVAL = TIM_GetCapture3(TIM4);//记录下此时的定时器计数值
if (TIM4CH3_CAPTURE_DOWNVAL < TIM4CH3_CAPTURE_UPVAL)
{
tim4_T3 = 65535;
}
else
tim4_T3 = 0;
tempup3 = TIM4CH3_CAPTURE_DOWNVAL - TIM4CH3_CAPTURE_UPVAL
+ tim4_T3; //得到总的高电平的时间
pwmout3 = tempup3; //总的高电平的时间
TIM4CH3_CAPTURE_STA = 0; //捕获标志位清零
TIM_OC3PolarityConfig(TIM4, TIM_ICPolarity_Rising); //设置为上升沿捕获
}
else //发生捕获时间但不是下降沿,第一次捕获到上升沿,记录此时的定时器计数值
{
TIM4CH3_CAPTURE_UPVAL = TIM_GetCapture3(TIM4); //获取上升沿数据
TIM4CH3_CAPTURE_STA |= 0X40; //标记已捕获到上升沿
TIM_OC3PolarityConfig(TIM4, TIM_ICPolarity_Falling);//设置为下降沿捕获
}
}
}
if ((TIM4CH4_CAPTURE_STA & 0X80) == 0) //还未成功捕获
{
if (TIM_GetITStatus(TIM4, TIM_IT_CC4) != RESET) //捕获4发生捕获事件
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC4); //清除中断标志位
if (TIM4CH4_CAPTURE_STA & 0X40) //捕获到一个下降沿
{
TIM4CH4_CAPTURE_DOWNVAL = TIM_GetCapture4(TIM4);//记录下此时的定时器计数值
if (TIM4CH4_CAPTURE_DOWNVAL < TIM4CH4_CAPTURE_UPVAL)
{
tim4_T4 = 65535;
}
else
tim4_T4 = 0;
tempup4 = TIM4CH4_CAPTURE_DOWNVAL - TIM4CH4_CAPTURE_UPVAL
+ tim4_T4; //得到总的高电平的时间
pwmout4 = tempup4; //总的高电平的时间
TIM4CH4_CAPTURE_STA = 0; //捕获标志位清零
TIM_OC4PolarityConfig(TIM4, TIM_ICPolarity_Rising); //设置为上升沿捕获
}
else //发生捕获时间但不是下降沿,第一次捕获到上升沿,记录此时的定时器计数值
{
TIM4CH4_CAPTURE_UPVAL = TIM_GetCapture4(TIM4); //获取上升沿数据
TIM4CH4_CAPTURE_STA |= 0X40; //标记已捕获到上升沿
TIM_OC4PolarityConfig(TIM4, TIM_ICPolarity_Falling);//设置为下降沿捕获
}
}
}
}
void TIM5_IRQHandler(void)
{
if ((TIM5CH3_CAPTURE_STA & 0X80) == 0) //还未成功捕获
{
if (TIM_GetITStatus(TIM5, TIM_IT_CC3) != RESET) //捕获1发生捕获事件
{
TIM_ClearITPendingBit(TIM5, TIM_IT_CC3); //清除中断标志位
if (TIM5CH3_CAPTURE_STA & 0X40) //捕获到一个下降沿
{
TIM5CH3_CAPTURE_DOWNVAL = TIM_GetCapture3(TIM5);//记录下此时的定时器计数值
if (TIM5CH3_CAPTURE_DOWNVAL < TIM5CH3_CAPTURE_UPVAL)
{
tim5_T3 = 65535;
}
else
tim5_T3 = 0;
tempup5 = TIM5CH3_CAPTURE_DOWNVAL - TIM5CH3_CAPTURE_UPVAL
+ tim5_T3; //得到总的高电平的时间
pwmout5 = tempup5; //总的高电平的时间
TIM5CH3_CAPTURE_STA = 0; //捕获标志位清零
TIM_OC3PolarityConfig(TIM5, TIM_ICPolarity_Rising); //设置为上升沿捕获
}
else //发生捕获时间但不是下降沿,第一次捕获到上升沿,记录此时的定时器计数值
{
TIM5CH3_CAPTURE_UPVAL = TIM_GetCapture3(TIM5); //获取上升沿数据
TIM5CH3_CAPTURE_STA |= 0X40; //标记已捕获到上升沿
TIM_OC3PolarityConfig(TIM5, TIM_ICPolarity_Falling);//设置为下降沿捕获
}
}
}
if ((TIM5CH4_CAPTURE_STA & 0X80) == 0) //还未成功捕获
{
if (TIM_GetITStatus(TIM5, TIM_IT_CC4) != RESET) //捕获2发生捕获事件
{
TIM_ClearITPendingBit(TIM5, TIM_IT_CC4); //清除中断标志位
if (TIM5CH4_CAPTURE_STA & 0X40) //捕获到一个下降沿
{
TIM5CH4_CAPTURE_DOWNVAL = TIM_GetCapture4(TIM5);//记录下此时的定时器计数值
if (TIM5CH4_CAPTURE_DOWNVAL < TIM5CH4_CAPTURE_UPVAL)
{
tim5_T4 = 65535;
}
else
tim5_T4 = 0;
tempup6 = TIM5CH4_CAPTURE_DOWNVAL - TIM5CH4_CAPTURE_UPVAL
+ tim5_T4; //得到总的高电平的时间
pwmout6 = tempup6; //总的高电平的时间
TIM5CH4_CAPTURE_STA = 0; //捕获标志位清零
TIM_OC4PolarityConfig(TIM5, TIM_ICPolarity_Rising); //设置为上升沿捕获
}
else //发生捕获时间但不是下降沿,第一次捕获到上升沿,记录此时的定时器计数值
{
TIM5CH4_CAPTURE_UPVAL = TIM_GetCapture4(TIM5); //获取上升沿数据
TIM5CH4_CAPTURE_STA |= 0X40; //标记已捕获到上升沿
TIM_OC4PolarityConfig(TIM5, TIM_ICPolarity_Falling);//设置为下降沿捕获
}
}
}
}
上一篇: Spark(三)第一个Spark程序