当前位置:网站首页>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);//???????
}
}
边栏推荐
- Solution of IP network broadcasting system in Middle School Campus - Design Guide for Campus Digital IP broadcasting system
- 7-5 maximal submatrix sum problem
- throttle-debounce. JS: a small anti shake throttling function library
- Actipro WPF Controls 2022.1.2
- Morris遍曆
- golang map clear
- 7-7 solving mode problems
- 二分查找数组下标
- 华为机器学习服务语音识别功能,让应用绘“声”绘色
- 抖音实战~实现App端视频上传与发布
猜你喜欢
What good smart home brands in China support homekit?
Installing IBM CPLEX academic edition | CONDA installing CPLEX
点的螺旋距离
Installation and deployment of ganglia
一文理解OpenStack网络
Hyperledger Fabric 2. X dynamic update smart contract
Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
今天睡眠质量记录79分
22map introduction and API
随机推荐
sql -CONVERT函数
golang convert map to json string
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
Quickly build KVM virtual machine on # yyds dry goods inventory # physical machine
Annual salary of millions, 7 years of testing experience: stay at a fairly good track, accumulate slowly, wait for the wind to come
(Smooth)ScrollToPosition doesn't work properly with RecyclerView
Helix distance of point
Use of types, values, namespaces, combinations, etc. in typescript
#22Map介绍与API
Yyds dry goods counting uses xshell to implement agent function
Inventory of data governance status of six major banks: governance architecture, data standards and data middle office (April 2022)
Record a Webflux application memory leak troubleshooting
Morris遍历
Actipro WPF Controls 2022.1.2
7-5 maximal submatrix sum problem
点的螺旋距离
7-3 maximum sub segment and
No main manifest attribute in jar
Continuous soul torture from two MySQL indexes of interviewers
Bubble sort