Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.59 KB | None | 0 0
  1. /********************************************************************
  2.  * Function:        void GetSIRC(unsigned char *address, unsigned char *command)
  3.  *
  4.  * Note:            None
  5.  *******************************************************************/
  6. void GetSIRC(unsigned char *address, unsigned char *command)
  7. {
  8.     unsigned char ir_add;
  9.     unsigned char ir_cmd;
  10.     unsigned char x;
  11.     unsigned int y = 0;
  12.  
  13. StartLook:
  14.     ir_add = ir_cmd = 0;
  15.  
  16.     while(y<990)
  17.     {
  18.         if(irPin)
  19.         {
  20.             y++;               //wait for it to be low
  21.         }
  22.         else
  23.         {
  24.             y=1000;
  25.             break;
  26.         }
  27.     }
  28.     if(y!=1000)                 //Did we timeout?
  29.     {
  30.         *address = 0xFF;
  31.         *command = 0xFF;
  32.         return;
  33.     }
  34.     USBModuleDisable();
  35.     lTime = 0;                  //reset the counter
  36.  
  37.     while(irPin == 0)
  38.     {
  39.         //while the pin is low which is our pulse count
  40.         lTime++;                //increment every 200uS until pin is high
  41.         Delay200us(1);        //200uS delay
  42.     }
  43.  
  44.     if(lTime <= 10)             //Start too short
  45.         goto StartLook;         //Restart
  46.     if(lTime >= 14)             //Start too long
  47.         goto StartLook;         //Restart
  48.            
  49.     lTime = 0;
  50.     for(x=0;x<7;x++){           //repeat 7 times for command
  51.         ir_cmd >>= 1;           //if it was skipped or is done ORing then shift over the 1
  52.  
  53.         while(irPin);           //wait for it to be low
  54.         lTime = 0;              //reset the counter
  55.  
  56.         while(irPin == 0){      //while the pin is low which is our pulse count
  57.             lTime++;            //increment every 200uS until pin is high
  58.             Delay200us(1);    //200uS delay
  59.         }
  60.  
  61.         if(lTime >= 6)          //If its high then OR a 1 in else skip
  62.             ir_cmd |= 0x40;     //if its less than 6 its a 0 so dont OR it     
  63.                                
  64.     }
  65.     for(x=0;x<5;x++){           //repeat 5 times for address/device
  66.         ir_add >>= 1;           //if it was skipped or is done ORing then shift over the 1
  67.  
  68.         while(irPin);           //wait for it to be low
  69.         lTime = 0;              //reset the counter
  70.  
  71.         while(irPin == 0){      //while the pin is low which is our pulse count
  72.             lTime++;            //increment every 200uS until pin is high
  73.             Delay200us(1);    //200uS delay
  74.         }
  75.  
  76.         if(lTime >= 6)          //If its high then OR a 1 in else skip
  77.             ir_add |= 0x10;     //if its less than 6 its a 0 so dont OR it         
  78.     }
  79.  
  80.     *address = ir_add;
  81.     *command = ir_cmd;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement