This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

please help me to correct the program

I have a written a program for a 4channel IR remote control with keilc for ATMEL89c51.IR sensor(TSOP1738) is coneected with interrupt1 (P3.3) and timer0.I use timer0 as 16 bit counter and timer1 as 16 bit timer.Timer0 counts the no of pulses which comes to it and timer1 is on for .5 second.If the no of pulses in .5 second is between 115 to 125 pin P0.0 becomes on and it becomes off if gets same range of pulse.Now i'm not sure the program is fully correct.Please help me with necessary correction.Where i'll place the infinite loop[while(1)]?
#include<reg51.h>
sbit op1=P0^0;//o/p
sbit op2=P0^1;//o/p
sbit op3=P0^2;//o/p
sbit op4=P0^3;//o/p

int c;

void delay(void)//delay .5 second

{ int d; for(d=0;d<10;d++)
 {
TF1=0;//clear overflow flag
TL1=0xB0;
TH1=0x3C;
TR1=1; //start timer
while(TF1==0)
TR1=0; //stop timer }
}<pre/>

void intr1(void) interrupt 2 //external interrupt1 function
{
 EX1=0; //disable all interrupts
TH0=0x00; //reset counter
TL0=0x00;
TR0=1; //start counter
delay();
TR0=0; //stop counter
c=TL0; //store count
EX1=1; //enable all interrupts
}<pre/>

void main()
{
 TMOD=0x25; //initialize T0 as 16bit counter and T1 as 16bit timer
IE=0x84; //enable external interrupt 1 if((c>=0x73)&&(c<=0x7D))
 {
if(op1==0)
{
op1=1;
 }
else
{
op1=0;
 }
}
else if((c>=0x5F)&&(c<=0x69))
{
if(op2==0)
 {
op2=1;
}
else
{
op2=0;
}
}
else if((c>=0x4B)&&(c<=0x55))
 {
if(op3==0)
{
op3=1;
 }
else
{
 op3=0;
}
}
else if((c>=0x37)&&(c<=0x41))
 {
 if(op4==0)
{
 op4=1;
}
else
{
op4=0;
}
}<pre/>


  • programs have comments and indentions, what you post can only qualify as scribbles.

    Erik

  • If you take time to carefully format and comment your code, it is quite likely that you spot errors in the process!

  • That includes explaining all the "magic numbers" that you're using - or, preferably, giving them proper symbolic names...

  • What's with all the obture responses to peoples problems from the regulars today?

    Give the guy a break.

    Listen chum. You've posted this snippet three times now. It's still unreadable and very difficult to read. If you really want help, consider posting it in a manner that would not discourage people from taking it seriously.

  • Your program is really a posting mess which makes it hard to know what's wrong. It also appears you really need to take some time to learn the C programming language. The power of C is that it includes a lot of operators that are very powerful yet easy to understand.

    I have re-written your main function with a while(1) using C operators. Maybe this will help.

    void main (void)
    {
    TMOD=0x25; //initialize T0 as 16bit counter and T1 as 16bit timer
    IE=0x84; //enable external interrupt 1
    
    while(1)
      {
      if((c>=0x73)&&(c<=0x7D))
        op1 = !op1;
      else if((c>=0x5F)&&(c<=0x69))
        op2 = !op2;
      else if((c>=0x4B)&&(c<=0x55))
        op3 = !op3;
      else if((c>=0x37)&&(c<=0x41))
        op4 = !op4;
      }
    }
    

    Jon