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

for loop not executing

Good Day, i am writing a code for a density based traffic light project using for loops for the density part of the system, but my for loops wont execute. the code is attached below.

Parents
  •  #include<reg52.h>
    
    sbit in1_na=P2^0;               //sensor1
    sbit in2_nb=P2^1;       //sensor2
    sbit in1_wa=P2^2;       //sensor3
    sbit in2_wb=P2^3;    //sensor4
    sbit in1_sa=P2^4;    //sensor5
    sbit in2_sb=P2^5;               //sensor6
    sbit in1_ea=P2^6;               //sensor7
    sbit in2_eb=P2^7;               //sensor8
    
    sbit out1_ng=P0^0;
    sbit out2_ny=P0^1;
    sbit out3_nr=P0^2;
    
    sbit out1_wr=P0^3;
    sbit out2_wy=P0^4;
    sbit out3_wg=P0^5;
    
    sbit out1_eg=P1^0;
    sbit out2_ey=P1^1;
    sbit out3_er=P1^2;
    
    sbit out1_sr=P1^3;
    sbit out2_sy=P1^4;
    sbit out3_sg=P1^5;
    
    unsigned int i,j,k=0,v1=0,w1=0,x1=0,y1=0,z1=0,t1=0;
    
    void delay_2sec();
    void delay_5sec();
    void delay_12sec();
    
    void main()
    {
         while(1)
                     {
                                            v1=0;                                                                                                                           //clear v1
                                            w1=0;                                                                                                                           //clear w1
              x1=0;                               //clear xl
              y1=0;                               //clear y1
    
            if(in1_na==1)                         //if sensor1 is blocked
                                    {
                   v1=1;
                                    }
              if((in1_na==1)&&(in2_nb==1))  //if sensorl & sensor2 are blocked
                                            {
                   v1=2;
                                            }
    
              if(in1_wa==1)                     //if sensor3 is blocked
                                            {
                                                            w1=1;
                                            }
    
                                            if((in1_wa==1)&&(in2_wb==1))            //if sensor3 and sensor4 are blocked
                                            {
                                                            w1=2;
                                            }
    
                                            if(in1_sa==1)                         //if sensor5 is blocked
                                    {
                   x1=1;
                                    }
              if((in1_sa==1)&&(in2_sb==1))  //if sensor5 & sensor6 are blocked
                                            {
                   x1=2;
                                            }
    
              if(in1_wa==1)                     //if sensor7 is blocked
                                            {
                                                            y1=1;
                                            }
    
                                            if((in1_wa==1)&&(in2_wb==1))            //if sensor7 and sensor8 are blocked
                                            {
                                                            y1=2;
                                            }
    
    
    
           out1_wr=1; //led off
           out2_wy=0; //led off
           out3_wg=0; //led on
    
           out1_sr=1; //led on
           out2_sy=0; //led off
           out3_sg=0; //led off
    
           out1_eg=0;  //led off
           out2_ey=0;  //led off
           out3_er=1;  //led on
    
           out1_ng=1; //led on
           out2_ny=0; //led off
                             out3_nr=0; //led off
    
    
                            delay_5sec();  //delay for 5sec
    
                            out3_er=1;                                      //led off
                            out2_ey=0;          //led off
                            out1_eg=0;          //led on
                            out1_ng=0;                                      //led off
                            out2_ny=1;           //led on
                            out3_nr=0;           //led off
    
                            delay_2sec();   //delay for 2sec
    
                            out1_ng=0;          //led off
                            out2_ny=0;          //led off
                            out3_nr=1;          //led on
    
                            out1_eg=1;           //led on
                            out2_ey=0;           //led off
                            out3_er=0;           //led off
    
                            out1_sr=1;          //led off
                            out2_sy=0;          //led on
                            out3_sg=0;          //led off
    
                      out1_wr=1;         //led on
                            out2_wy=0;         //led off
                            out3_wg=0;         //led off
    
    
        delay_5sec();  //delay for 5sec
    
    
                            out3_er=0;                                      //led off
                            out2_ey=1;          //led off
                            out1_eg=0;          //led on
                            out1_sr=1;                                      //led off
                            out2_sy=0;           //led on
                            out3_sg=0;           //led off
    
        delay_2sec();       //delay for 2sec
    
                            out1_ng=0;          //led off
                            out2_ny=0;          //led off
                            out3_nr=1;          //led on
    
                            out1_eg=0;           //led on
                            out2_ey=0;           //led off
                            out3_er=1;           //led off
    
                            out1_sr=0;          //led off
                            out2_sy=0;          //led on
                            out3_sg=1;          //led off
    
                      out1_wr=1;         //led on
                            out2_wy=0;         //led off
                            out3_wg=0;         //led off
    
    
        delay_5sec();  //delay for 5sec
    
                            out1_sr=0;                                      //led off
                            out2_sy=1;           //led on
                            out3_sg=0;           //led off
                            out1_wr=1;         //led on
                            out2_wy=0;         //led off
                            out3_wg=0;         //led off
    
        delay_2sec();       //delay for 2sec
    
                            out1_ng=0;          //led off
                            out2_ny=0;          //led off
                            out3_nr=1;          //led on
    
                            out1_eg=0;           //led on
                            out2_ey=0;           //led off
                            out3_er=1;           //led off
    
                            out1_sr=1;          //led off
                            out2_sy=0;          //led on
                            out3_sg=0;          //led off
    
                      out1_wr=0;         //led on
                            out2_wy=0;         //led off
                            out3_wg=1;         //led off
    
    

Reply
  •  #include<reg52.h>
    
    sbit in1_na=P2^0;               //sensor1
    sbit in2_nb=P2^1;       //sensor2
    sbit in1_wa=P2^2;       //sensor3
    sbit in2_wb=P2^3;    //sensor4
    sbit in1_sa=P2^4;    //sensor5
    sbit in2_sb=P2^5;               //sensor6
    sbit in1_ea=P2^6;               //sensor7
    sbit in2_eb=P2^7;               //sensor8
    
    sbit out1_ng=P0^0;
    sbit out2_ny=P0^1;
    sbit out3_nr=P0^2;
    
    sbit out1_wr=P0^3;
    sbit out2_wy=P0^4;
    sbit out3_wg=P0^5;
    
    sbit out1_eg=P1^0;
    sbit out2_ey=P1^1;
    sbit out3_er=P1^2;
    
    sbit out1_sr=P1^3;
    sbit out2_sy=P1^4;
    sbit out3_sg=P1^5;
    
    unsigned int i,j,k=0,v1=0,w1=0,x1=0,y1=0,z1=0,t1=0;
    
    void delay_2sec();
    void delay_5sec();
    void delay_12sec();
    
    void main()
    {
         while(1)
                     {
                                            v1=0;                                                                                                                           //clear v1
                                            w1=0;                                                                                                                           //clear w1
              x1=0;                               //clear xl
              y1=0;                               //clear y1
    
            if(in1_na==1)                         //if sensor1 is blocked
                                    {
                   v1=1;
                                    }
              if((in1_na==1)&&(in2_nb==1))  //if sensorl & sensor2 are blocked
                                            {
                   v1=2;
                                            }
    
              if(in1_wa==1)                     //if sensor3 is blocked
                                            {
                                                            w1=1;
                                            }
    
                                            if((in1_wa==1)&&(in2_wb==1))            //if sensor3 and sensor4 are blocked
                                            {
                                                            w1=2;
                                            }
    
                                            if(in1_sa==1)                         //if sensor5 is blocked
                                    {
                   x1=1;
                                    }
              if((in1_sa==1)&&(in2_sb==1))  //if sensor5 & sensor6 are blocked
                                            {
                   x1=2;
                                            }
    
              if(in1_wa==1)                     //if sensor7 is blocked
                                            {
                                                            y1=1;
                                            }
    
                                            if((in1_wa==1)&&(in2_wb==1))            //if sensor7 and sensor8 are blocked
                                            {
                                                            y1=2;
                                            }
    
    
    
           out1_wr=1; //led off
           out2_wy=0; //led off
           out3_wg=0; //led on
    
           out1_sr=1; //led on
           out2_sy=0; //led off
           out3_sg=0; //led off
    
           out1_eg=0;  //led off
           out2_ey=0;  //led off
           out3_er=1;  //led on
    
           out1_ng=1; //led on
           out2_ny=0; //led off
                             out3_nr=0; //led off
    
    
                            delay_5sec();  //delay for 5sec
    
                            out3_er=1;                                      //led off
                            out2_ey=0;          //led off
                            out1_eg=0;          //led on
                            out1_ng=0;                                      //led off
                            out2_ny=1;           //led on
                            out3_nr=0;           //led off
    
                            delay_2sec();   //delay for 2sec
    
                            out1_ng=0;          //led off
                            out2_ny=0;          //led off
                            out3_nr=1;          //led on
    
                            out1_eg=1;           //led on
                            out2_ey=0;           //led off
                            out3_er=0;           //led off
    
                            out1_sr=1;          //led off
                            out2_sy=0;          //led on
                            out3_sg=0;          //led off
    
                      out1_wr=1;         //led on
                            out2_wy=0;         //led off
                            out3_wg=0;         //led off
    
    
        delay_5sec();  //delay for 5sec
    
    
                            out3_er=0;                                      //led off
                            out2_ey=1;          //led off
                            out1_eg=0;          //led on
                            out1_sr=1;                                      //led off
                            out2_sy=0;           //led on
                            out3_sg=0;           //led off
    
        delay_2sec();       //delay for 2sec
    
                            out1_ng=0;          //led off
                            out2_ny=0;          //led off
                            out3_nr=1;          //led on
    
                            out1_eg=0;           //led on
                            out2_ey=0;           //led off
                            out3_er=1;           //led off
    
                            out1_sr=0;          //led off
                            out2_sy=0;          //led on
                            out3_sg=1;          //led off
    
                      out1_wr=1;         //led on
                            out2_wy=0;         //led off
                            out3_wg=0;         //led off
    
    
        delay_5sec();  //delay for 5sec
    
                            out1_sr=0;                                      //led off
                            out2_sy=1;           //led on
                            out3_sg=0;           //led off
                            out1_wr=1;         //led on
                            out2_wy=0;         //led off
                            out3_wg=0;         //led off
    
        delay_2sec();       //delay for 2sec
    
                            out1_ng=0;          //led off
                            out2_ny=0;          //led off
                            out3_nr=1;          //led on
    
                            out1_eg=0;           //led on
                            out2_ey=0;           //led off
                            out3_er=1;           //led off
    
                            out1_sr=1;          //led off
                            out2_sy=0;          //led on
                            out3_sg=0;          //led off
    
                      out1_wr=0;         //led on
                            out2_wy=0;         //led off
                            out3_wg=1;         //led off
    
    

Children