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

check rc car code in c using 89c51 uc

i am working on 89c51 uc is this code correct for rc car.

#include<stdio.h>
#include<Regx51.h>

sbit t0=P1^0;
sbit t1=P1^1;
sbit t2=P1^2;
sbit t3=P1^3;
sbit t4=P2^0;
sbit t5=P2^1;
sbit t6=P2^2;
sbit t7=P2^3;
sbit t8=P2^4;
sbit t9=P1^5;
sbit t10=P1^6;
sbit t11=P1^7;
sbit t12=P2^5;
sbit t13=P2^6;
sbit t14=P2^7;

void main()
{

t9=t10=t11=t12=t13=t14=0; t0=1; t1=1;t2=1;t3=1;//t3=t2=t1=t0=1; for(; ;) { l1: if(t0==0) //left { t4=1; t5=1; t6=t7=t8=0; goto l1; } l2:if(t1==0) //right { t6=1; t7=1; t4=t5=t8=0; goto l2; } l3:if(t2==0) //forward { t7=1; t4=t5=t6=t8=0; goto l3; } l4:if(t3==0) //reverse { t8=1; t4=t5=t6=t7=0; goto l4; }

}
}

Parents
  • Erik,

    How I'd like you to pass comment on what my employer has recently given me. Very few comments, incorrect comments, irrelevant comments, plenty of gotos, magic values all over the place, a lot of these magic values into arrays containing a multitude of different length elements (plenty of them logically unrelated), no passing of parameters or return of values to/from functions, virtually no local variables, plenty of global variables, few assumptions about ordering of variables in memory. I've seen a lot of bad code during my career, but this is the pits!

Reply
  • Erik,

    How I'd like you to pass comment on what my employer has recently given me. Very few comments, incorrect comments, irrelevant comments, plenty of gotos, magic values all over the place, a lot of these magic values into arrays containing a multitude of different length elements (plenty of them logically unrelated), no passing of parameters or return of values to/from functions, virtually no local variables, plenty of global variables, few assumptions about ordering of variables in memory. I've seen a lot of bad code during my career, but this is the pits!

Children