SCM infrared receiver algorithm

Infrared remote control currently in the market used more widely, such as TV remote control, remote control lights, remote control toys and so on.

Here mainly introduce the code written infrared remote control receiver, infrared receiver look at the code:

  1 void user_gpio_init(void)
  2 {
  3   /*!< Output push-pull, low level, 10MHz */
  4   GPIO_Init(GPIOC, GPIO_PIN_LNIB, GPIO_MODE_OUT_PP_LOW_SLOW);//FI 0..3
  5   GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_SLOW);//BI
  6   /*!< Input pull-up, external interrupt */
  7   GPIO_Init(GPIOC, GPIO_PIN_7, GPIO_MODE_IN_PU_IT);   //Data
  8   /*@brief  Set the external interrupt sensitivity of the selected port.*/
  9   /*!< Interrupt on Falling edge only */
 10   EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);
 11 }
 12 //interrupt routine
 13 void portC_isr(void)
 14 {
 15   static u8 one_byte;
 16   static u8 index;
 17   static u8 bits_of_byte;
 18   switch(IR_State)
 19   {
 20   case IDL:
 21     {
 22       time_125us=0;
 23       IR_State++;
 24       break;
 25     }
 26   case START:
 27     {
 28       if(time_125us>104)//ok , ready to receive data
 29       {
 30         time_125us=0;
 31         one_byte = 0;
 32         index=0;
 33         bits_of_byte = 0;
 34         IR_State++;
 35       }
 36       else IR_State--;
 37       break;
 38     }
 39   case DATA:
 40     {
 41       if((time_125us<14)&&(time_125us>6))//0
 42       {
 43         one_byte <<=1;
 44         bits_of_byte++;
 45       }
 46       else if((time_125us>14)&&(time_125us<23))//1
 47       {
 48         one_byte<<=1;
 49         one_byte+=1;
 50         bits_of_byte++;
 51       }
 52       else
 53       {
 54         IR_State = IDL;
 55       }
 56       time_125us=0;
 57       if(bits_of_byte >= 8)                     // got one byte ready
 58       {
 59         g_u8arr_buf[index++]=one_byte;
 60         time_release_125us=0;
 61         if(index> = 4 )
 62          {
 63            // __disable_interrupt (); 
64            if ((g_u8arr_buf [ 3 ] == 0x13 ) && (g_u8arr_buf [ 2 ] == 0xEC ) && (g_u8arr_buf [ 1 ] == 0xFF ) && g_u8arr_buf [ 0 ] == 0x00 ) // 0x00FFEC13 
65            {
 66              if (g_motor_busy! = 0x00 )
 67              {
 68                Engine stop;
69                g_motor_busy = 0 ;
 70             }
 71           }
 72           else if ((g_u8arr_buf[3]==0x53)&&(g_u8arr_buf[2]==0xAC)&&(g_u8arr_buf[1]==0xff)&&g_u8arr_buf[0]==0x00)//0x00FFAC53
 73           {
 74             //time_release_125us=0;
 75             if(g_motor_busy!=0x5a)
 76             {
 77               MotorForward;
 78               g_motor_busy=0x5a;
 79             }
 80           }
 81           else if ((g_u8arr_buf[3]==0x33)&&(g_u8arr_buf[2]==0xCC)&&(g_u8arr_buf[1]==0xff)&&g_u8arr_buf[0]==0x00)//0x00FFCC33
 82           {
 83             //time_release_125us=0;
 84             if(g_motor_busy!=0x3c)
 85             {
 86               MotorBackward;
 87               g_motor_busy=0x3c;
 88             }
 89           }
 90           else
 91           {
 92             if(g_motor_busy!=0x00)
 93             {
 94               MotorStop;
 95               g_motor_busy=0;
 96             }
 97           }
 98           IR_State = IDL;
 99           //__enable_interrupt();
100         }
101         bits_of_byte=0;
102         one_byte=0;
103       }
104       break;
105     }
106   default:
107     {
108       IR_State = IDL;
109       break;
110     }
111   }
112 }

Common infrared code format is: Header is 13.5ms signal only after the data transmission starts. Encoded data: about 1ms represents 0 or 1, about 2ms represents 1 or 0. This is mainly to see their own defined.

The focus of the algorithm is tuned timer accuracy, and sensitivity of the infrared continuous read.

 

Guess you like

Origin www.cnblogs.com/lumao1122-Milolu/p/11411130.html