STM32电视遥控器解码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
void TIM3_IRQHandler(void) //定时器中断函数,用于定时计数
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)!=RESET)
{
cn++;
TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //最高输出频率50MHz
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); //设置向量表位置和偏移
TIM_Cmd(TIM3, ENABLE); //使能外设TIM3
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); //使能定时器中断
}
void ADMIT_EXTI_Rise_Config(void) //上升沿中断线配置
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //IO口复用时钟配置
EXTI_InitStructure.EXTI_LineCmd=ENABLE; //使能中断线
EXTI_Init(&EXTI_InitStructure);
EXTI_GenerateSWInterrupt(EXTI_Line0); //产生一个软件中断
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void ADMIT_EXTI_Fall_Config(void) //下降沿中断线配置
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; //从占优先级7
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; //使能中断通道
NVIC_Init(&NVIC_InitStructure);
}
}
void EXTI0_IRQHandler(void) //外部中断线0中断函数
{
static unsigned char i=0;
static unsigned char buffer;
static unsigned char Conting;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising; //上升沿中断请求
EXTI_InitStructure.EXTI_LineCmd=ENABLE; //使能中断线
EXTI_Init(&EXTI_Infig(void)
{
ADMIT_GPIO_Config(); //红外接收IO口配置
ADMIT_EXTI_Rise_Config(); //红外接收上升沿中断配置
ADMIT_TIME_Config(); //定时器中断配置
}
void ADMIT_GPIO_Config(void) //红外接收IO口配置
buffer=0;
Conting=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; //从占优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; //使能中断通道
NVIC_Init(&NVIC_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //IO口复用时钟配置
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource0); //将PC0用作外部中断线
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE); //红外接收IO口时钟配置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //红外接收IO口PC0
NVIC_Init(&NVIC_InitStructure);
}
void ADMIT_TIME_Config(void) //定时器中断配置
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //中断优先级分组
NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn; //中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //先占优先级0
TIM_TimeBaseStructure.TIM_Prescaler=0; //预分频
TIM_TimeBaseStructure.TIM_ClockDivision=0; //时钟分割
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up ; //向上计数模式
EXTI_InitStructure.EXTI_Line=EXTI_Line0; //中断线0
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; //模式为中断请求
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; //下降沿中断请求
{
ADMIT_EXTI_Fall_Config();
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
fall=1;
cn=0;
}
else if(fall==1) //红外信号接收,起始/高/低位判别,美的空调为6个字节
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource0); //将PC0用作外部中断线
EXTI_InitStructure.EXTI_Line=EXTI_Line0; //中断线0
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; //模式为中断请求
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn; //中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //先占优先级0
static unsigned char admit_dat;
//消抖
if(EXTI_GetITStatus(EXTI_Line0) != RESET) //检查指定的EXTI0线路触发请求发生与否
{
if(fall==0)
/*
对象:电视机
功能:解码四位的电视遥控器
可切换到任意位的遥控器解码
切换方式:
修改 Matchnumber 的数值大小
解码接口:
PC0
移植方法:将admit_reg[4]用于显示就可以看到遥控器的解码
*/
#include "stm32f10x.h"
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //清除中断处理位
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //中断优先级分组
#define Matchnumber 4
unsigned char fall=0; //fall=0上升沿中断,fall=1下降沿中断
unsigned int cn=0; //定时器中断次数,用于计量高电平宽度
unsigned char admit_reg[4]; //红外接收数组,
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //先占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; //从占优先级7
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; //使能中断通道
EXTI_GenerateSWInterrupt(EXTI_Line0); //产生一个软件中断
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //中断优先级分组
NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn; //中断通道
{
switch(i)
{
case 0:
{
if(cn<400&&cn>300)
{
i=1;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE ); //定时器时钟配置
TIM_TimeBaseStructure.TIM_Period=1000; //自动预重装寄存器周期:72k
相关文档
最新文档