phonghip1287
Joined: 14 May 2009 Posts: 1 Location: fgf
|
Need help with Sony IR code |
Posted: Thu May 14, 2009 1:33 pm |
|
|
I have been written a code to decode SONY IR to turn on or turn off lights. But something was wrong. Please help me. Thanks.
Code: | #include <16f877A.h>
#use delay(clock=4000000)
#fuses HS,NOWDT, NOPROTECT
#use fast_IO(B)
#byte portB=0x06
#bit B0=portB.0
#bit B1=portB.1
#bit B2=portB.2
#bit B3=portB.3
#bit B4=portB.4
#bit B5=portB.5
#bit B6=portB.6
#bit B7=portB.7
int16 CCP1Value;
BOOLEAN CCP1Captured;
#int_CCP1
void ngat()
{
CCP1value=CCP_1;
set_timer1(0);
CCP1captured=TRUE;
}
void init_CCP1()
{
setup_CCP1(CCP_CAPTURE_RE);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_8);
CCP1captured=TRUE;
CCP1value=0;
enable_interrupts(int_CCP1);
enable_interrupts(global);
}
float dochuky()
{
float T;
init_CCP1();
if(CCP1captured==TRUE)
{ T=(CCP1value)*8e-6;
CCP1captured=FALSE;
}
return T;
}
void main()
{
int8 A;
int i;
float T;
while(TRUE)
{
A=0b00000010;//lam nhu the de vi ma bit cua phim 1 la 0h
for(i=0;i<8;i++)
{
T=dochuky();
if(T<=1300&&T>=1100) {A=A+0;}
else if(T<=1900&&T>=1700) A=A+0b00000001;
A=A>>1;
}
if(A==0b00000000) B0=!B0;
else if(A==0b00000001) B1=!B1;
else if(A==0b00000010) B2=!B2;
else if(A==0b00000011) B3=!B3;
else if(A==0b00000100) B4=!B4;
else if(A==0b00000101) B5=!B5;
else if(A==0b00000110) B6=!B6;
else if(A==0b00000111) B7=!B7;
}
} |
_________________ fafagh |
|