/* **************************************************************************
; *
; 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
}
}