stm 32 f 103は、割り込み受付により、タイマが記録されたときに赤外線リモコン値を取得する


個人的な理由でスクリーンショットはできませんが、コードは自分でテストして使用できます.
ハードウェア:正点原子stm 32 f 103開発ボード.
コードは次のとおりです.
機能コードremote.c
#include "remote.h"
#include "stdio.h"

u32 receiveBuffer;
u32 CodeTime=0;
u32 CodeTimeBuff=0;
u8 hRevFlag=0;
u8 Rev_Count=0;

#define GET_REMOTE_HEAD 0x80

static void execuIRQ(void)
{
	CodeTimeBuff=CodeTime;
	CodeTime=0; 	
	if(hRevFlag==GET_REMOTE_HEAD)
	{
		receiveBuffer<<=1;
		if((CodeTimeBuff>9)&&(CodeTimeBuff<13))// 2.265ms
		{
			receiveBuffer|=1;
		}
		else if((CodeTimeBuff>4)&&(CodeTimeBuff<7))// 1.135ms
		{
			receiveBuffer|=0;
		}
		else
		{
			hRevFlag=0;
			receiveBuffer=0;
		}
		Rev_Count++;

		if(Rev_Count==32)
		{	
		 
			Rev_Count=0;
			if(receiveBuffer!=0)
			{
				printf("get the remote -> %#x",receiveBuffer);
			}
			receiveBuffer=0;
			hRevFlag=0;
		}
	}

	if((CodeTimeBuff>60)&&(CodeTimeBuff<70))// 13.45ms 
	{ 
		hRevFlag=GET_REMOTE_HEAD; 
	}
   
 
}

void EXTI9_5_IRQHandler(void)
{
	if(EXTI_GetITStatus(EXTI_Line9) != RESET)
    {
    	execuIRQ();
   	 	EXTI_ClearITPendingBit(EXTI_Line9);
    }	
}
 
void TIM3_IRQHandler(void)
{
	if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) 
		{	
			TIM_ClearITPendingBit(TIM3, TIM_IT_Update  ); 
			CodeTime++;
  	 		if(CodeTime>74) 
   			{
   				CodeTime=0;
   			}
		
		}
}

static void remote_TIM3_Init(u16 arr,u16 psc)
{
    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	NVIC_InitTypeDef NVIC_InitStructure;

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); 
	
	TIM_TimeBaseStructure.TIM_Period = arr; 
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; 
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
	TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
 
	TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE );
	
	NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;  
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;  
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);  

	TIM_Cmd(TIM3, ENABLE); 
}

static void remote_exit_init(void)
{
 
 	EXTI_InitTypeDef EXTI_InitStructure;
 	NVIC_InitTypeDef NVIC_InitStructure;
  	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);

  	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource9);

  	EXTI_InitStructure.EXTI_Line=EXTI_Line9;	
  	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;	
  	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  	EXTI_Init(&EXTI_InitStructure);	 	
  	
	NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;			
  	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03;
  	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03;					
  	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;	
  	NVIC_Init(&NVIC_InitStructure);  	  
 
}

static void remote_gpio_init(void)    			  
{  
	GPIO_InitTypeDef GPIO_InitStructure;
	
 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); 
 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;				
 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; 		
 	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 	GPIO_Init(GPIOB, &GPIO_InitStructure);								 
}

void remote_init(void)
{
	remote_gpio_init();	
	remote_exit_init();	
	remote_TIM3_Init(1,7199);//10Khz , 200us   ,200*5000=1s
}


ヘッダファイル
remote.h
#ifndef __REMOTE_H
#define __REMOTE_H 

#include "stm32f10x.h"
void remote_init(void);

#endif


しゅプログラム
#include "stdio.h"
#include "delay.h"
#include "usart.h"	 
#include "remote.h"

 int main(void)
 {	 
	
	delay_init();	    	
  	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  	uart_init(115200);	 	
	remote_init();
	
  	printf("REMOTE For Denzel\r
"); while(1) { } }