C語言 for 改寫成while

#define LEDPORT PORTC

void main()

{

unsigned short int i;

CCP1CON=CCP2CON=0;

LEDPORT=0;

TRISC=0;

while(1)

{

for(i=1;i>0;i=i<<1)

{

LEDPORT=i;

Delay_ms(200);

}

}

}

Update:

0.0 要能連續動作

另外問一下 要使得8個LED左右來回移動要怎改

Update 2:

題目是左旋 那右旋要改哪裡

1 Answer

Rating
  • 10 years ago
    Favorite Answer

    for(i=1;i>0;i=i<<1)

    {

    LEDPORT=i;

    Delay_ms(200);

    }

    ---------------------------------------

    i=1;

    while(i>0){

    LEDPORT=i;

    Delay_ms(200);

    i << 1;

    }

    2010-10-19 18:03:54 補充:

    右旋

    i << 1;

    改成

    i >> 1;

    <<與>>是位元移位,後面數字是指移動幾位

    Source(s): me
Still have questions? Get your answers by asking now.