abhignans
Newbie level 6
- Joined
- Feb 1, 2012
- Messages
- 13
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,401
hello
i want to decode nec format using 89s52 micro
and i have develoed the code but im unable to get where is the problem.
first thing i want to know is the code correct
secondly can i have any c sample code to decode nec format using 89s52 ...if the code is using 89c2051 i will b gladfull
i just want the sample in c code to decode nec.
here is my previous code which i have developed
#include<reg51.h>
#include<stdio.h>
#define T 516//560us 11.0592MHz
#define _9MS 8295//9000ms 11.0592MHz
#define _4MS 4198//4500ms 11.0592MHz
#define _2T ((T)+(T))//1120us 11.0592MHz
#define _3T (T*3)//1680us 11.0592MHz
#define POW 0x12
#define V_UP 0x02
#define V_DW 0x13
#define uint unsigned int
#define cmp(VALUE,MS) (VALUE>=(MS-MS*.1)&&VALUE<=(MS+MS*.1))?1:0
#define uint unsigned int
#define lint long int
#define uchar unsigned char
static uchar DATAPORT,key;
uchar add1,add2,cmd1,cmd2;
sbit ir=P3^2;
sbit Power=P3^0;
sbit io=P3^1;
uint value,value1;
static uchar count;
uchar irtemp,i,j;
void delay(uint a)
{
uint r,t;
for(r=0;r<a;r++)
for(t=0;t<120;t++);
}
void ir_data() interrupt 0 using 1
{
TH0=TL0=0;
EX0=0;
IE0=0;
TR0=1;
io=0;
while((!ir)&&(TH0<<8|TL0)<9500);
TR0=0;
value=(TH0<<8)|TL0;
TH0=TL0=0;
TR0=1;
while(ir&&(TH0<<8|TL0)<5000);
TR0=0;
value1=(TH0<<8)|TL0;
if(cmp(value,_9MS)&&cmp(value1,_4MS))
{
{
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
irtemp>>=1;///* Recive 'byte' bit-by-bit from MSB to LSB. */
TH0=TL0=0;
while(!ir);
TR0=1;
while(ir);
TR0=0;
value=TH0<<8|TL0;
irtemp|=(cmp(value,_3T))?0x80:0x00;
}
switch(i)
{
case 0:
add1=irtemp;break;
case 1:
add2=irtemp;break;
case 2:
cmd1=irtemp;break;
case 3:
cmd2=irtemp;break;
default :;break;
}
irtemp=0x00;
}
}i=0,j=0;
}
irtemp=0;
if((cmd1==~cmd2)&&(add1==~add2))
{
key=cmd1;
printf("%X %X %X %X\n",add1,cmd1,add2,cmd2);//Display on hyperterminal
}
else
printf("Recive Errer\n");
add1=add2=cmd1=cmd2=0;
delay(200);
io=1;
IE0=0;
EX0=1;
}
void main()
{
EA=0;
TMOD=0x01;
SCON=0x50;
PCON=0x80; //for high baud rate SMOD=1
TH1=0xFD; //19200 baud rate
TI=0;
TR1=1;
ET1=1;
TH0=0;TL0=0;
IT0=1;
EX0=1;
PX0=1;
DATAPORT=0x0F;
P1=DATAPORT;
Power=0;
io=1;
EA=1;
while(1)
{
while(key==0x00);
switch (key)
{
case POW :
Power^=0x01;P1=DATAPORT=0x0F; break;
case V_UP:
if(DATAPORT>0x00&&Power)
{
DATAPORT=DATAPORT-1;
P1=DATAPORT;
//printf("%X",P1);
//puts("VOL+");
}break;
case V_DW :
if(DATAPORT<0x0F&&Power)
{
DATAPORT=DATAPORT+1;
P1=DATAPORT;
//printf("%X",P1);
//puts("VOL-");
}break;
default :
break;
}
key=0x00;
}
}
please correct me if im wrong anywhere. im in a very much urgence for finishing this proj
thanks in advance
i want to decode nec format using 89s52 micro
and i have develoed the code but im unable to get where is the problem.
first thing i want to know is the code correct
secondly can i have any c sample code to decode nec format using 89s52 ...if the code is using 89c2051 i will b gladfull
i just want the sample in c code to decode nec.
here is my previous code which i have developed
#include<reg51.h>
#include<stdio.h>
#define T 516//560us 11.0592MHz
#define _9MS 8295//9000ms 11.0592MHz
#define _4MS 4198//4500ms 11.0592MHz
#define _2T ((T)+(T))//1120us 11.0592MHz
#define _3T (T*3)//1680us 11.0592MHz
#define POW 0x12
#define V_UP 0x02
#define V_DW 0x13
#define uint unsigned int
#define cmp(VALUE,MS) (VALUE>=(MS-MS*.1)&&VALUE<=(MS+MS*.1))?1:0
#define uint unsigned int
#define lint long int
#define uchar unsigned char
static uchar DATAPORT,key;
uchar add1,add2,cmd1,cmd2;
sbit ir=P3^2;
sbit Power=P3^0;
sbit io=P3^1;
uint value,value1;
static uchar count;
uchar irtemp,i,j;
void delay(uint a)
{
uint r,t;
for(r=0;r<a;r++)
for(t=0;t<120;t++);
}
void ir_data() interrupt 0 using 1
{
TH0=TL0=0;
EX0=0;
IE0=0;
TR0=1;
io=0;
while((!ir)&&(TH0<<8|TL0)<9500);
TR0=0;
value=(TH0<<8)|TL0;
TH0=TL0=0;
TR0=1;
while(ir&&(TH0<<8|TL0)<5000);
TR0=0;
value1=(TH0<<8)|TL0;
if(cmp(value,_9MS)&&cmp(value1,_4MS))
{
{
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
irtemp>>=1;///* Recive 'byte' bit-by-bit from MSB to LSB. */
TH0=TL0=0;
while(!ir);
TR0=1;
while(ir);
TR0=0;
value=TH0<<8|TL0;
irtemp|=(cmp(value,_3T))?0x80:0x00;
}
switch(i)
{
case 0:
add1=irtemp;break;
case 1:
add2=irtemp;break;
case 2:
cmd1=irtemp;break;
case 3:
cmd2=irtemp;break;
default :;break;
}
irtemp=0x00;
}
}i=0,j=0;
}
irtemp=0;
if((cmd1==~cmd2)&&(add1==~add2))
{
key=cmd1;
printf("%X %X %X %X\n",add1,cmd1,add2,cmd2);//Display on hyperterminal
}
else
printf("Recive Errer\n");
add1=add2=cmd1=cmd2=0;
delay(200);
io=1;
IE0=0;
EX0=1;
}
void main()
{
EA=0;
TMOD=0x01;
SCON=0x50;
PCON=0x80; //for high baud rate SMOD=1
TH1=0xFD; //19200 baud rate
TI=0;
TR1=1;
ET1=1;
TH0=0;TL0=0;
IT0=1;
EX0=1;
PX0=1;
DATAPORT=0x0F;
P1=DATAPORT;
Power=0;
io=1;
EA=1;
while(1)
{
while(key==0x00);
switch (key)
{
case POW :
Power^=0x01;P1=DATAPORT=0x0F; break;
case V_UP:
if(DATAPORT>0x00&&Power)
{
DATAPORT=DATAPORT-1;
P1=DATAPORT;
//printf("%X",P1);
//puts("VOL+");
}break;
case V_DW :
if(DATAPORT<0x0F&&Power)
{
DATAPORT=DATAPORT+1;
P1=DATAPORT;
//printf("%X",P1);
//puts("VOL-");
}break;
default :
break;
}
key=0x00;
}
}
please correct me if im wrong anywhere. im in a very much urgence for finishing this proj
thanks in advance