AtomSoft
Well-Known Member
Here ya go:
I even made a little RBG led test using digits 1-7. Ill make a small vid and show in a bit.
Code:
/* **************************************************************************
; *
; Filename: SIRC *
; Date: May 29, 2009 *
; File Version: 001 *
; *
; Author: Jason Lopez *
; Company: AtomSoft *
; *
;****************************************************************************
; Notes:
; I am delaying in this code a nice even number every 200uS. Mainly because if
; i count each pulse it would be accurate but too many counts for a char type
; and i dont want to use a int. So i can get a 600 count by skipping every 300uS
; and the count will be a nice low number...3
;
; For a 1.2mS aka HIGH i should get a count of 6 and for the start 2.4mS i should
; get a count of 12. Since this isnt too accurate i range it about 1-2 numbers
; above or below the standard.
;
;****************************************************************************
*/
#include <p18f2525.h>
#include <delays.h>
#include <string.h>
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67, XINST = OFF
unsigned char lTime;
unsigned char MyAdd;
unsigned char MyCmd;
#define irTris TRISCbits.TRISC4
#define irPin PORTCbits.RC4
void main(void);
void GetSIRC(unsigned char *address, unsigned char *command);
void main(void){
char tmp;
OSCCON = 0x72; //8MHz clock
while(!OSCCONbits.IOFS); //wait for osc stable
TRISC = 0;
irTris = 1;
while(1){
GetSIRC(&MyAdd,&MyCmd);
}
}
void GetSIRC(unsigned char *address, unsigned char *command){
unsigned char ir_add;
unsigned char ir_cmd;
char x;
StartLook:
ir_add = ir_cmd = 0;
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
Delay100TCYx(4); //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
Delay100TCYx(4); //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
Delay100TCYx(4); //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;
}
I even made a little RBG led test using digits 1-7. Ill make a small vid and show in a bit.
Last edited: