|
//部分代码
//红外遥控函数
#include "IRCtrol.h"
#include "interface.h"
unsigned char ir_rec_flag=0;
unsigned char IRCOM[4];
void Time3Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 1;
TIM_TimeBaseStructure.TIM_Prescaler = (72 - 1);//72M / 72 = 1us
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
}
void DelayUóê±s(vu32 nCount)
{
u16 TIMCounter = nCount;
TIM_Cmd(TIM3, ENABLE);
TIM_SetCounter(TIM3, TIMCounter);
while (TIMCounter>1)
{
TIMCounter = TIM_GetCounter(TIM3);
}
TIM_Cmd(TIM3, DISABLE);
}
void IRCtrolInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure
NVIC_InitTypeDef NVIC_InitStructure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO , ENABLE);
GPIO_InitStructure.GPIO_Pin = IRIN_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz
GPIO_Init(IRIN_GPIO , &GPIO_InitStructure);
GPIO_EXTILineConfig(IRIN_PORTSOURCE , IRIN_PINSOURCE);
EXTI_InitStructure.EXTI_Line = IRIN_EXITLINE;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt
EXTI_InitStructure.EXTI_LineCmd = ENABLE
EXTI_Init(&EXTI_InitStructure);//½«ÅäÖÃoÃμÄ2ÎêyD′èë¼Ä′æÆ÷
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = IRIN_IRQCH;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
Time3Init();
}void DelayIr(unsigned char x)
{
while(x--)
{
DelayUs(140);
}
}
void IRIntIsr(void)
{
unsigned char j,k,N=0;
DelayIr(15);
if (IRIN==1)
{
return;
}
continue_time = 40
while (!IRIN)
{DelayIr(1);}
for (j=0;j<4;j++)
{
for (k=0;k<8;k++)
{
while (IRIN)
{DelayIr(1);}
while (!IRIN)
{DelayIr(1);}
while (IRIN)
{
DelayIr(1);
N++;
if (N>=30)
{
return;}
}
IRCOM[j]=IRCOM[j] >> 1;
if (N>=8) {IRCOM[j] = IRCOM[j] | 0x80;}
N=0;
}//end for k
}//end for j
k = ~IRCOM[3];
if (IRCOM[2] != k)
{
return; }
switch(IRCOM[2])
{
case 0x46: ctrl_comm = COMM_UP;break;
case 0x15: ctrl_comm = COMM_DOWN;break;
case 0x44: ctrl_comm = COMM_LEFT;break;
case 0x43: ctrl_comm = COMM_RIGHT;break;
case 0x40: ctrl_comm = COMM_STOP;break;
default : return;
}
ir_rec_flag = 1;
}
|
|