PIC Microcontroller

리모콘(Remote control) Program

EP 기술연구소 2018. 6. 19. 00:56

*==================================================================================== Header File

//===== IR_REMOTE CONTROL RECEIVER MODULE (HI-M900V0 series) define
//    high -> low -> high -> low -> high
//#define "Start"  9.4  4.5     
//#define "0"   0.6  0.6       
//#define "1"   0.6  1.6       
//#define "End"  0.6  4.5       
//#define "Cuntinue" 9.4  2.3  0.6  4.5  

#define  start_low  94
#define  start_high  45
#define  data_start  6
#define  data_0   6
#define  data_1   16
#define  end_high  45
#define  remo_continue 23


#define  reciver_count 4  // 4 x 8bit = 32 bit
#define  recive_bit0_clear  0xFFFFFFFE

short IR_StartFlag, IR_StateFlag, IR_CompFlag, IR_CountKeyFlag;
unsigned char IR_BitCounter, IR_Time_H, IR_Time_L;
unsigned long long IR_ReciverData, IR_Reciver, IR_Buffer[reciver_count];

unsigned long NoIR_Timer;


//========================================================================  100uSec Interrupt
 //100uSec Timer Interrupt
  //IR-Remocom Control Routine
    if (IR_Input) {
        if (IR_StateFlag == 0) {
            // IR_Module statr : L -> H
        }
        if(++IR_Time_H >= 150){
         IR_Time_H = 150;
         if((IR_Time_L <= 6) & (IR_StartFlag == 1)) IR_CompFlag = 1;  // IR_Reciver complite
        }
        IR_StateFlag = 1;
    }
    else {
        if (IR_StateFlag == 1) {
            // IR_Module statr : H -> L (1-bit data reciver)
            if(IR_Time_H <= 45){
             if(IR_Time_L <= 6){  // 6
              IR_Reciver <<= 1;
              if(IR_Time_H >= 12)IR_Reciver |= 1;
              else IR_Reciver &= recive_bit0_clear;
             }
             else {
                 if(IR_Time_L <= 94) {
                  IR_StartFlag = 1;
                     if (IR_Time_H <= 23) IR_CountKeyFlag = 1; // Continues key command
                     else {
                      IR_CountKeyFlag = 0;
                      IR_Reciver = 0; // Start command
                     }
                 }
             }
   }
            IR_Time_H = 0;
            IR_Time_L = 0;
        }
        if(++IR_Time_L >= 250) IR_Time_L = 250;
        IR_StateFlag = 0;
    }
}

//==========================================================
// Remocon Input complite  check Routine
#define ir_count 32   // Reciver data = 32bit
/*
const char StartKey_Tbl[4] = {0x40, 0xFF, 0,  0xFF};
const char StrongKey_Tbl[4] = {0x40, 0xFF, 0x20, 0xDF};
const char TimeKey_Tbl[4] = {0x40, 0xFF, 0x60, 0x9F};
const char UpKey_Tbl[4] =  {0x40, 0xFF, 0x40, 0xBF};
const char DownKey_Tbl[4] = {0x40, 0xFF, 0xE0, 0x1F};
*/

void IR_Module()
{
 unsigned char i;
 
 i = (IR_Reciver >> 12);
    i &= 0x0f;
   
 switch(i){
  case 0:  // Power Key
   if(IR_CountKeyFlag == 0) KeyJump(power_key);
   break;
  case 2:  // Starong Key
   if(IR_CountKeyFlag == 0) KeyJump(strong_key);
   break;
  case 6:  // Reserved Time
   if(IR_CountKeyFlag == 0) KeyJump(time_key);
   break;
  case 10: // UP key
   break;
  case 14: // DOWN key
   break;
  default:
   break;
 }
 
 IR_CompFlag = 0;
 IR_StartFlag = 0;

}