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

coufused by array and shift bit

Hi, The code is given below.

void CSToOut(void)
{
static unsigned char data bSimulate[8] ;
int I;

        for( I = 0 ;I < 8;I ++)
        {
                bSimulate[I] = 0x01 << I ;
                ComOutChar( bSimulate[I] );
        }
}


result: 00 00 00 00 00 00 00 00

why?

  • Maybe a problem with the ComOutChar function or your use of it?

  • void ComOutChar(unsigned char OutData)
    {
            SBUF = OutData;
            while(!TI);
            TI = 0;
    }
    

    tks.

  • You tried single stepping in the simulator?

  •                         I = 0 ;
                            bSimulate[0] = 0x01 << I ;
    
                            I = 1 ;
                            bSimulate[1] = 0x01 << I;
    
                            I = 2 ;
                            bSimulate[2] = 0x01 << I;
    
                            I = 3 ;
                            bSimulate[3] = 0x01 << I;
    
                            I = 4 ;
                            bSimulate[4] = 0x01 << I;
    
                            I = 5 ;
                            bSimulate[5] = 0x01 << I;
    
                            I = 6 ;
                            bSimulate[6] = 0x01 << I;
    
                            I = 7 ;
                            bSimulate[7] = 0x01 << I;
    
                            for( I = 0 ;I < 8;I ++)
                            {
    //                              bSimulate[I] = 0x01 << I ;
                                    ComOutChar( bSimulate[I] );
                            }
    

    result:01 02 04 08 10 20 40 80

                            I = 0 ;
                            bSimulate[I] = 0x01 << I ;
    
                            I = 1 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 2 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 3 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 4 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 5 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 6 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 7 ;
                            bSimulate[I] = 0x01 << I;
    
                            for( I = 0 ;I < 8;I ++)
                            {
    //                              bSimulate[I] = 0x01 << I ;
                                    ComOutChar( bSimulate[I] );
                            }
    

    result:00 00 00 00 00 00 00 00

    unsigned char J;
                            I = 0 ;
                            J = 0 ;
                            bSimulate[J] = 0x01 << I ;
    
                            I = 1 ;
                            J = 1 ;
                            bSimulate[J] = 0x01 << I;
    
                            I = 2 ;
                            J = 2 ;
                            bSimulate[J] = 0x01 << I;
    
                            I = 3 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 4 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 5 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 6 ;
                            bSimulate[I] = 0x01 << I;
    
                            I = 7 ;
                            bSimulate[I] = 0x01 << I;
    
                            for( I = 0 ;I < 8;I ++)
                            {
    //                              bSimulate[I] = 0x01 << I ;
                                    ComOutChar( bSimulate[I] );
                            }
    

    result:80 80 80 00 00 00 00 00

    tks

  • Why is bSimulate declared static?

    What does the assembly that the compiler generates look like? I often find that looking at the assembly listing gives a lot of good information to help with debugging.