problem with code

Status
Not open for further replies.

shanky25

New Member
Hello ! I jus tried building a remote controlled car using rc5 coding. I am using an 89s52 controller. Using this i am trying to control the rear and front motors. the problem is the code is working only if i program for forward direction or reverse direction. if i try out writng the same code for all the directions some of the relays of my motor are not getting triggered. here is my code.

#include<reg51.h>
#include<intrins.h>

char receive();
void send(char);
void delay();
void delay_1(unsigned int);
void delay_t(int);


void delay1(int);

sbit rx=P3^0;

sbit m1p=P1^0;
sbit m1n=P1^1;
sbit m2p=P1^2;
sbit m2n=P1^3;
sbit m3p=P1^4;
sbit m3n=P1^5;
sbit m4p=P1^6;
sbit m4n=P1^7;

void main()
{
char a,ch;
TMOD=0x01;

while(1)
{
a=receive();
//send(a);
if(a==1)//P1=>left_up
{
m1p=1;
m1n=0;
m2p=1;
m2n=0;
m3p=1;
m3n=0;
m4p=1;
m4n=0;
}

if(a==2)//P1=>left_dn
{
m1p=0;
m1n=1;
m2p=0;
m2n=1;
m3p=0;
m3n=1;
m4p=0;
m4n=1;
}

if(a==3)
{
m1p=1;
m1n=0;
m2p=1;
m2n=0;
m3p=0;
m3n=1;
m4p=0;
m4n=1;
}

if(a==4)
{
m1p=0;
m1n=1;
m2p=0;
m2n=1;
m3p=1;
m3n=0;
m4p=1;
m4n=0;
}

if(a==8)
{
m1p=1;
m1n=1;
m2p=1;
m2n=1;
m3p=1;
m3n=1;
m4p=1;
m4n=1;
}
}
}

void delay_1(unsigned int k)
{
int i;
for(i=0;i<k;i++);
}



void send(char a)
{
TI=0;
SBUF=a;
while(TI==0);
}

void delay_t(int k)
{
unsigned int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<1257;j++);
}
}

void delay()
{
IE=0x00;
TH0=0xF9;
TL0=0x9D;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}

char receive()
{
int i;
char a,b;
TH1=0xaa;
TL1=0x00;
IE=0x88;
TR1=1;
while(rx==1);
a=0x00;
b=0x20;
for(i=0;i<6;i++)
delay();
for(i=0;i<17;i++);

for(i=0;i<6;i++)
{
delay();
if(rx==1)
a=a|b;
b=b/2;
}
return a;
}
 
M sorry for such a big msg but I have been facing problems with this code since a week ! plz help me out !
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…