Thread: Help Please

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Help Please

    Code:
    void main ()
    {
    int count=0;
    TRISD=0x00;
    MEMCONbits.EBDIS=1;
    while(1)
    {
    if(count>8)
    count=0;
    switch(count)
    {
    case 0:
    PORTD=0x00;
    break;
    case 1:
    PORTD=0x01;
    break;
    case 2:
    PORTD=0x03;
    break;
    case 3:
    PORTD=0x07;
    break;
    case 4:
    PORTD=0x0f;
    break;
    case 5:
    PORTD=0x1f;
    break;
    case 6:
    PORTD=0x3f;
    break;
    case 7:
    PORTD=0x7f;
    break;
    case 8:
    PORTD=0xff; // 0b11111111 , 255
    break;
    }
    Delay10KTCYx(0);
    count++;
    }
    }

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    3
    Can you please tell me what this code is doing?

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    It is running around in a circle, counting from 0 to 8 and setting bits on a port.

    Pretty useless really... unless that port connects to something.

    If you want to know what the individual parts of the code ... switch(), if() etc. are doing... grab any good C language manual and look them up.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    3
    Thank you ,
    you r righr since the port is connected to an LED

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by KABIDI View Post
    Thank you ,
    you r righr since the port is connected to an LED
    Ok... so what do I win?

  6. #6
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Progressively turning on LEDs until all eight are lit. Then turning all off and starting over.
    Code:
    - - - - - - - -
    * - - - - - - -
    * * - - - - - -
    * * * - - - - -
    * * * * - - - -
    * * * * * - - -
    * * * * * * - -
    * * * * * * * -
    * * * * * * * *

Popular pages Recent additions subscribe to a feed

Tags for this Thread