Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************************************
- * Function: void GetSIRC(unsigned char *address, unsigned char *command)
- *
- * Note: None
- *******************************************************************/
- void GetSIRC(unsigned char *address, unsigned char *command)
- {
- unsigned char ir_add;
- unsigned char ir_cmd;
- unsigned char x;
- unsigned int y = 0;
- StartLook:
- ir_add = ir_cmd = 0;
- while(y<990)
- {
- if(irPin)
- {
- y++; //wait for it to be low
- }
- else
- {
- y=1000;
- break;
- }
- }
- if(y!=1000) //Did we timeout?
- {
- *address = 0xFF;
- *command = 0xFF;
- return;
- }
- USBModuleDisable();
- lTime = 0; //reset the counter
- while(irPin == 0)
- {
- //while the pin is low which is our pulse count
- lTime++; //increment every 200uS until pin is high
- Delay200us(1); //200uS delay
- }
- if(lTime <= 10) //Start too short
- goto StartLook; //Restart
- if(lTime >= 14) //Start too long
- goto StartLook; //Restart
- lTime = 0;
- for(x=0;x<7;x++){ //repeat 7 times for command
- ir_cmd >>= 1; //if it was skipped or is done ORing then shift over the 1
- while(irPin); //wait for it to be low
- lTime = 0; //reset the counter
- while(irPin == 0){ //while the pin is low which is our pulse count
- lTime++; //increment every 200uS until pin is high
- Delay200us(1); //200uS delay
- }
- if(lTime >= 6) //If its high then OR a 1 in else skip
- ir_cmd |= 0x40; //if its less than 6 its a 0 so dont OR it
- }
- for(x=0;x<5;x++){ //repeat 5 times for address/device
- ir_add >>= 1; //if it was skipped or is done ORing then shift over the 1
- while(irPin); //wait for it to be low
- lTime = 0; //reset the counter
- while(irPin == 0){ //while the pin is low which is our pulse count
- lTime++; //increment every 200uS until pin is high
- Delay200us(1); //200uS delay
- }
- if(lTime >= 6) //If its high then OR a 1 in else skip
- ir_add |= 0x10; //if its less than 6 its a 0 so dont OR it
- }
- *address = ir_add;
- *command = ir_cmd;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement