当前位置:网站首页>Stm32f030f4 reading infrared remote control data
Stm32f030f4 reading infrared remote control data
2022-06-24 23:35:00 【mialo163】
One frame data structure (NEC agreement )
data 0 And data 1 It means

The phase of the signal received at the receiving head is opposite

Configure external interrupts
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
void EXTI0_Config(void)
{
/* Enable GPIOA clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Configure PA0 pin as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Connect EXTI0 Line to PA0 pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
/* Configure EXTI0 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //EXTI_Trigger_Falling;// EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI0 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
Obtain high level pulse width time
u8 HW_ReceiveTime(void)
{
u8 t=0;
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1)//???
{
t++;
delay_us(20);//20us In units of
if(t>=250) return t;//????
}
return t;
}External interrupt processing
void EXTI0_1_IRQHandler()
{
u8 time=0,startSignal=0,Data=0,Count=0;
unsigned long HW_ReceivedData=0;
if(EXTI_GetITStatus(EXTI_Line0) != RESET)//?????EXTI??????????,????EXTI_Line???
{
//if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)) GPIO_SetBits(GPIOA,GPIO_Pin_0);//??LED
//else GPIO_ResetBits(GPIOA,GPIO_Pin_0);//?
while(1)
{
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1)
{
time = HW_ReceiveTime();
if(time>=250)
{
startSignal=0;
HW_ReceivedData=0;
Count=0;
break;
}
else if(time>=200 && time<250)// Pilot code 4.5ms
{
startSignal=1;//??????
HW_ReceivedData=0;
Count=0;
continue;
}
else if(time>=60 && time<90) // Level width 1.5ms
{
Data=1;//???? 1
}
else if(time>=10 && time<50) // Level width 0.6ms
{
Data=0;//???? 0
}
// else
// {
// break;
//
// }
if(startSignal==1)
{
HW_ReceivedData<<=1;
HW_ReceivedData+=Data;// Deposit data
Count++;
if(Count>=32)// full 32 Bit fetch number
{
// for(i=0;i<4;i++)
// {
// printf("%x\n",HW_ReceivedData);
// }
//printf("0x%lx\n",HW_ReceivedData);
unsigned char cha[4]= {0};
cha[0] = (HW_ReceivedData & 0xFF000000)>>24;
cha[1] = (HW_ReceivedData & 0x00FF0000)>>16;
cha[2] = (HW_ReceivedData & 0x0000FF00)>>8;
cha[3] = HW_ReceivedData & 0x000000FF;
if(cha[0]==0x00&&cha[1]==0xFF)// User code
{
if(cha[2]==0x90&&(cha[2]+cha[3])==0xFF)// Judge the inverse code
{
//..... Get encoded data processing
}
}
}
}
}
// /* Clear the EXTI line 0 pending bit */
EXTI_ClearITPendingBit(EXTI_Line0);
// EXTI_ClearITPendingBit(EXTI_Line0);//???????
EXTI_ClearFlag(EXTI_Line0);//???????
}
}
边栏推荐
- Continuous soul torture from two MySQL indexes of interviewers
- Morris traversal
- R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用summary函数获取模型汇总统计信息、解读模型系数交互作用及其显著性
- R language uses the aggregate function of epidisplay package to split numerical variables into different subsets based on factor variables, calculate the summary statistics of each subset, and customi
- 7-5 maximal submatrix sum problem
- js监听页面或元素scroll事件,滚动到底部或顶部
- Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
- 7-8 循环日程安排问题
- 7-5 最大子矩阵和问题
- 一文理解OpenStack网络
猜你喜欢

Installing IBM CPLEX academic edition | CONDA installing CPLEX

抖音实战~项目关联UniCloud

我的为人处事真的有问题吗?

中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南

Selective sort method

7-7 数字三角形
![[JS] - [tree] - learning notes](/img/62/de4fa2a7c5e52c461b8be4a884a395.png)
[JS] - [tree] - learning notes

第六章 网络学习相关技巧5(超参数验证)

JS listens for page or element scroll events, scrolling to the bottom or top

Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
随机推荐
斐波那契
Common regular expressions
js监听页面或元素scroll事件,滚动到底部或顶部
7-9 寻宝路线
7-2 solving the stock buying problem
HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
Simpledateformat concrete classes for formatting and parsing dates
Annual salary of millions, 7 years of testing experience: stay at a fairly good track, accumulate slowly, wait for the wind to come
golang map clear
去商场逛街
HMS core discovery Episode 13 live broadcast Preview - building the real world in mobile games
Morris traversal
How to resolve the 35 year old crisis? Sharing of 20 years' technical experience of chief architect of Huawei cloud database
[JS] - [string - application] - learning notes
第六章 网络学习相关技巧5(超参数验证)
Andersen Global借助巴勒斯坦成员公司加强中东平台
一文理解OpenStack网络
379. hide and seek
当初吃土建起来的“中台”,现在为啥不香了?
抖音实战~项目关联UniCloud