C++ problem with Codevision

Discussion in 'Programmer's Corner' started by frogacult, May 11, 2008.

  1. frogacult

    Thread Starter Member

    Apr 30, 2008
    27
    0
    I'm trying to program AVR STK500 with Codevision (c++) & run it with AVRstudio4.
    I want to make this : When PIND.0 is set then the outpout PORTB.1 & PORTB.4 are "1" and a message in lcd,when it is "0" nothing happens.
    i write the code and it works. (PIND.0 is connnected with a switch).
    if i connect a second switch to input PIND.1 and program it when it is set "1"
    to do something and when it is "0" something else then nothing works right
    and the 2 occasions are on always or works the one input or the other.
    i've attached t he code below.
    There is another way that i wouldn't use the "if" command because i think this makes the problems
     
  2. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    Mike,
    Your while loop needs braces. It should look like this:

    while (1)
    {
    // chain of if - else statements
    }
     
  3. frogacult

    Thread Starter Member

    Apr 30, 2008
    27
    0
    Mark, i didn't understand , what do u mean to use braces?
    and what does chain stands for?
     
    Last edited: May 11, 2008
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Code ( (Unknown Language)):
    1.  
    2. while (1)
    3. [B]{   // Added this brace...[/B]
    4.       if(PIND.0==0)         //Input. Airflow sensor
    5.        {
    6.         air_flow_error();
    7.        }
    8.        else
    9.        {
    10.         air_flow_ok();
    11.        }
    12.  
    13.        if(PIND.1==0)  //Input.Thermal sensor
    14.        {
    15.         low_temp();
    16.        }
    17.        else
    18.        {
    19.         high_temp();
    20.        }
    21.  
    22.        if(PIND.0==0&&PIND.1==0)
    23.        {
    24.         air_flow_error();
    25.         low_temp();
    26.        }
    27.  
    28.        else if(PIND.0==0&&PIND.1==1)
    29.        {
    30.         air_flow_error();
    31.         high_temp();
    32.        }
    33.  
    34.        else if(PIND.0==1&&PIND.1==0)
    35.        {
    36.         air_flow_ok();
    37.         low_temp();
    38.        }
    39.  
    40.        else if(PIND.0==1&&PIND.1==1)
    41.        {
    42.         air_flow_ok();
    43.         high_temp();
    44. [B]}  //Added this brace....[/B]
    45.  
    46. }
    I have bolded the braces that mark44 has been trying to get you to add.

    hgmjr
     
  5. frogacult

    Thread Starter Member

    Apr 30, 2008
    27
    0
    Ok i Got it ;)
    I'm going to try it out and i hope it will work this time!!
     
Loading...