当前位置:网站首页>STM32 infrared communication 3 brief
STM32 infrared communication 3 brief
2022-06-30 07:28:00 【weixin_ forty-six million one thousand two hundred and twenty-o】
bsp_exti.c
#include "bsp_exti.h"
static void NVIC_Configuration(void) // Interrupt priority function
{
NVIC_InitTypeDef NVIC_InitStructure;
/* To configure NVIC For priority group 1 */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); // To configure NVIC For priority group 1
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn ; // Configure interrupt sources :
/*EXTI0_IRQn/EXTI1_IRQn/ EXTI2_IRQn/EXTI3_IRQn/EXTI4_IRQn/EXTI9_5_IRQn/EXTI15_10_IRQn*/
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // Configure preemption priority
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // Configure sub priority
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // Enable interrupt channel
NVIC_Init(&NVIC_InitStructure); // Write structure members
}
void remote_EXTI_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //GPIO Structure
EXTI_InitTypeDef EXTI_InitStructure; // Interrupt structure
NVIC_Configuration(); // Interrupt priority function
// initialization GPIO
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE); // Turn on GPIO The clock of the port // Turn on the key GPIO The clock of the port
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; // Which pin
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; // Configure as floating input
GPIO_Init(GPIOE, &GPIO_InitStructure); // Write structure GPIO member
// initialization EXTI
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); // Turn on reuse GPIO The clock of the port // Turn on the key GPIO The clock of the port
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource5); // choice EXTI The source of the signal GPIOE,pin5
EXTI_InitStructure.EXTI_Line = EXTI_Line5; // Select interrupt source , Choose which pin
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; // Interrupt mode
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; // Both rising and falling edges trigger
EXTI_InitStructure.EXTI_LineCmd = ENABLE; // To interrupt
EXTI_Init(&EXTI_InitStructure); // Write struct interrupt member
}
remote.c
#include "remote.h"
#include "bsp_exti.h"
extern u32 count_100us;
u32 lt=0; // Record the low level time
u32 ht=0; // Record the low level time
u8 ind=0; // Record 32 A data code
u8 remotecode[32]; // Array to hold the address code , Address inversion , Data code , Data inversion
void EXTI9_5_IRQHandler(void)
{
u8 triger;
if(EXTI_GetITStatus(EXTI_Line5) != RESET)
{
// Clears the interrupt flag bit
EXTI_ClearITPendingBit(EXTI_Line5);
triger=GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_5); // Read port level
// Rising edge
if(triger==1)
{
lt=count_100us; // Capture rising edge time
count_100us=0;
}
// Falling edge
else
{
ht=count_100us; // Capture falling edge time
count_100us=0;
//========================= decode ===========================//
// Judge whether the leading code has come
if(ind==0)
{
if((lt<100)&&(lt>80)&&(ht<50)&&(ht>40)) // Determine whether the preamble is correct
{
ind++;
}
}
else
{
if((lt<8)&&(lt>4)&&(ht<7)&&(ht>3)){
remotecode[ind-1]=0;} // If low is 600us, Gao Shi 500us, Express 0
else if((lt<8)&&(lt>4)&&(ht<18)&&(ht>14)){
remotecode[ind-1]=1;} // If low is 600us, Gao Shi 1600us, Express 1
else{
ind=0;return;} // Otherwise, decoding fails , sign out
ind++;
if(ind>=33) // All in all 32 High and low levels
{
ind=0;
if(remotecode[18]==1&&remotecode[19]==1){
LED1_ON;} // Judge whether the data bits are correct
else{
LED1_OFF;}
}
}
}
}
}
边栏推荐
猜你喜欢

Starting MySQL ERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)

Can introduction

1285_ Expand macros defined by AUTOSAR functions and variables with scripts to improve readability

Matter protocol

Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)

社招两年半10个公司28轮面试面经

SwiftUI打造一款美美哒自定义按压反馈按钮

The class imported by idea import clearly exists, but it is red?

期末複習-PHP學習筆記6-字符串處理

网络安全-ARP协议和防御
随机推荐
Embedded test process
Resolved: initialize specified but the data directory has files in it Aborting
社招两年半10个公司28轮面试面经
Graphic explanation pads update PCB design basic operation
Test enumeration types with STM32 platform running RT thread
[resolved] MySQL exception: error 1045 (28000): unknown error 1045, forgetting the initial password
Introduction to go project directory structure
Calculation and parameter quantity of neural network
The simulation interface does not declare an exception and throws an exception
踩坑记录:supervisor 日志返回信息:redis扩展未安装
Error reporting record
[resolved] error 1290 (HY000): unknown error 1290
1285_ Expand macros defined by AUTOSAR functions and variables with scripts to improve readability
Cubemx completes STM32F103 dual serial port 485 transceiver transmission
Introduction to ecostruxure (1) IEC61499 new scheme
视频播放器(二):视频解码
神经网络计算量及参数量
Grep command usage
Examen final - notes d'apprentissage PHP 6 - traitement des chaînes
Go common commands