Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
/* **************************************************************************
; *
; Filename: SIRC *
; Date: May 29, 2009 *
; File Version: 001 *
; *
; Author: Jason Lopez *
; Company: AtomSoft *
; *
;****************************************************************************
; Notes:
;
*/
#include <p18f1320.h>
#include <delays.h>
#include <string.h>
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO2, MCLRE = OFF
#define irTris TRISBbits.TRISB0
#define irPin LATBbits.LATB0
#define BtnTris TRISBbits.TRISB1
#define Btn PORTBbits.RB1
#define TV 1
#define POWER 21
void main(void);
void SendSIRC(unsigned char myDEV, unsigned char myCMD);
void PulseIt(unsigned char time);
void main(void){
char tmp;
OSCCON = 0x72; //8MHz clock
//while(!OSCCONbits.IOFS); //wait for osc stable
ADCON1 = 0xFF;
BtnTris = 1;
irTris = 0;
while(1){
if(Btn){
SendSIRC(TV,POWER);
Delay10KTCYx(1);
while(Btn);
}
}
}
void SendSIRC(unsigned char myDEV, unsigned char myCMD){
char x;
PulseIt(4); //Logic Start
for(x=0;x<7;x++){
if(myCMD & 0x01){
PulseIt(2); //Logic 1
} else {
PulseIt(1); //Logic 0
}
myCMD >>= 1;
}
for(x=0;x<5;x++){
if(myDEV & 0x01){
PulseIt(2); //Logic 1
} else {
PulseIt(1); //Logic 0
}
myDEV >>= 1;
}
Delay10KTCYx(90); //45mS Delay
}
void PulseIt(unsigned char time){
unsigned char x,y,z;
for(y=0;y<time;y++){
for(x=0;x<24;x++){ //600uS worth
irPin = 1;
Delay10TCY();
Nop();
Nop();
Nop(); //About 7uS
irPin = 0;
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Delay10TCY();
Delay10TCY(); //About 18uS
}
}
for(x=0;x<24;x++){ //600uS worth
irPin = 0;
Delay10TCY();
Nop();
Nop();
Nop(); //About 7uS
irPin = 0;
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Delay10TCY();
Delay10TCY(); //About 18uS
}
}
void GetSIRC(unsigned char *address, unsigned char *command){
unsigned char ir_add;
unsigned char ir_cmd;
unsigned char lTime;
char x;
StartLook:
ir_add = ir_cmd = 0;
while(IR_Pin); //wait for it to be low
lTime = 0; //reset the counter
while(IR_Pin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
delay_100us(2); //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(IR_Pin); //wait for it to be low
lTime = 0; //reset the counter
while(IR_Pin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
delay_100us(2); //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(IR_Pin); //wait for it to be low
lTime = 0; //reset the counter
while(IR_Pin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
delay_100us(2); //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;
}
void GetSIRC(unsigned char *address, unsigned char *command){
unsigned char ir_add;
unsigned char ir_cmd;
unsigned char lTime;
unsigned long int IRTimeOut = 0;
char x;
StartLook:
ir_add = ir_cmd = 0;
while(IR_Pin)
{if(IRTimeOut++ > 10000){return;}} //wait for it to be low
IRTimeOut = 0;
lTime = 0; //reset the counter
while(IR_Pin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
delay_100us(2); //200uS delay
if(IRTimeOut++ > 10000){return;}
}
IRTimeOut = 0;
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(IR_Pin) //wait for it to be low
{if(IRTimeOut++ > 10000){return;}}
IRTimeOut = 0;
lTime = 0; //reset the counter
while(IR_Pin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
delay_100us(2); //200uS delay
if(IRTimeOut++ > 10000){return;}
}
IRTimeOut = 0;
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(IR_Pin) //wait for it to be low
{if(IRTimeOut++ > 10000){return;}}
IRTimeOut = 0;
lTime = 0; //reset the counter
while(IR_Pin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
delay_100us(2); //200uS delay
if(IRTimeOut++ > 10000){return;}
}
IRTimeOut = 0;
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;
}