当前位置:网站首页>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);//???????
}
}
边栏推荐
- golang map clear
- 7-6 laying oil well pipeline
- Tomorrow is the PMP Exam (June 25). Have you understood all this?
- 都2022年了,你还不了解什么是性能测试?
- [introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy
- Record a Webflux application memory leak troubleshooting
- [JS] - [stack, team - application] - learning notes
- [JS] - [array, stack, queue, linked list basics] - Notes
- jar中没有主清单属性
- Volcano成Spark默认batch调度器
猜你喜欢

华为机器学习服务语音识别功能,让应用绘“声”绘色

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

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

go 语言指针,值引用和指针引用
![[JS] - [linked list - application] - learning notes](/img/e1/76d2a347b05212de349322f43e0b3a.png)
[JS] - [linked list - application] - learning notes

First person singular reading notes

js监听页面或元素scroll事件,滚动到底部或顶部
![[JS] - [tree] - learning notes](/img/62/de4fa2a7c5e52c461b8be4a884a395.png)
[JS] - [tree] - learning notes

Actipro WPF Controls 2022.1.2

Quickly build KVM virtual machine on # yyds dry goods inventory # physical machine
随机推荐
单调栈以及单调栈的应用
Helix distance of point
UNION ALL UNION FULL JOIN
MySQL semi sync replication
中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南
7-3 maximum sub segment and
Morris traversal
7-3 最大子段和
golang map clear
Understanding openstack network
Hyperledger Fabric 2. X dynamic update smart contract
HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
点的螺旋距离
7-2 后序+中序序列构造二叉树
HMS core discovery Episode 13 live broadcast Preview - building the real world in mobile games
libnum库简单使用(进制字符串转换)
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、通过双样本t检验分析(双独立样本t检验)来判断倾向性评分匹配后样本中的所有协变量的平衡情况
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and performs Welch double sample t-test analysis and double inde
Inventory of data governance status of six major banks: governance architecture, data standards and data middle office (April 2022)
7-6 laying oil well pipeline