当前位置:网站首页>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);//???????
}
}
边栏推荐
- The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and judges the balance of all covariates in the sample after the
- Annual salary of millions, 7 years of testing experience: stay at a fairly good track, accumulate slowly, wait for the wind to come
- R language uses GLM function to build Poisson log linear regression model, processes three-dimensional contingency table data to build saturation model, uses summary function to obtain model summary s
- 常用正则表达式
- 都2022年了,你还不了解什么是性能测试?
- 去商场逛街
- 7-7 solving mode problems
- 还在用 SimpleDateFormat 做时间格式化?小心项目崩掉
- R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses exp function, confint function and coef function to obtain the confidence
- 【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化
猜你喜欢

Ganglia 的安装与部署

斐波那契

Hyperledger Fabric 2. X dynamic update smart contract

Volcano成Spark默认batch调度器

国内有哪些好的智能家居品牌支持homekit?

【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化

抖音实战~项目关联UniCloud

Huawei machine learning service speech recognition function enables applications to paint "sound" and color

7-7 数字三角形

(Smooth)ScrollToPosition doesn't work properly with RecyclerView
随机推荐
[JS] - [linked list - application] - learning notes
MySQL semi sync replication
Bubble sort
去处电脑桌面小箭头
jar中没有主清单属性
常用正则表达式
Morris traversal
idea创建模块提示已存在
7-2 后序+中序序列构造二叉树
7-8 循环日程安排问题
Latest development of jetpack compose
点的螺旋距离
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy
golang map clear
[JS] - [array application] - learning notes
SimpleDateFormat 格式化和解析日期的具体类
RT thread uses RT kprintf
Fibonacci
Common regular expressions
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验