coding problem???

Discussion in 'Programmer's Corner' started by fiezzshah, Feb 2, 2010.

  1. fiezzshah

    Thread Starter New Member

    Feb 2, 2010
    6
    0
    this is my first project..
    i'm confuse bcoz some of the coding didn't work when i'm running it..
    this is my sample coding...hope someone can help me to expain to me why it happened..

    main(){
    int cnt, value, Junc;
    set_tris_a(0); /* set port_a to be outputs */
    set_tris_b(0); /* set port_b to be outputs */
    port_a = 0; /* initialize All port_b outp/uts to be zero */
    port_b = 0; /* initialize All port_b outp/uts to be zero */
    value = 0x01;
    while( TRUE )
    { /* forever loop using WHILE construct */
    cnt = 1;
    value = 0x01;
    while ( cnt<9 )
    {
    for ( ;Junc; )
    {

    if (port_b = 0x10)
    port_a =0x0E;
    Delay_MS(8000);

    if (port_b = 0x01)
    port_a =0x0E;
    Delay_MS(2000);

    if (port_b = 0x00) <<--/* this coding it didn't work when im running
    port_a =0xFF; it..only working when i removed the if
    Delay_MS(2000); statement */

    }

    why it happened???help me...
     
  2. fiezzshah

    Thread Starter New Member

    Feb 2, 2010
    6
    0
    the circuit work properly when im using this code:

    main(){
    int cnt, value, Junc;
    set_tris_a(0); /* set port_a to be outputs */
    set_tris_b(0); /* set port_b to be outputs */
    port_a = 0; /* initialize All port_b outp/uts to be zero */
    port_b = 0; /* initialize All port_b outp/uts to be zero */
    value = 0x01;
    while( TRUE )
    { /* forever loop using WHILE construct */
    cnt = 1;
    value = 0x01;
    while ( cnt<9 )
    {
    for ( ;Junc; )
    {

    port_b = 0x10;
    port_a =0x0E;
    Delay_MS(8000);

    port_b = 0x01;
    port_a =0x0E;
    Delay_MS(2000);

    port_b = 0x00;
    port_a =0xFF;
    Delay_MS(2000);
    }
    }
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    You don't say what language you are using but it looks like C to me so assuming it is C.

    Your statement should be;
    if(port_b == 0x00)

    The statement as you wrote it sets port_b to 0x00 and then test to see if it's true (which it never will be).
     
  4. fiezzshah

    Thread Starter New Member

    Feb 2, 2010
    6
    0
    yeah..im using C.... em try it already..still not working...
     
  5. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Looking at your first posting you made the same mistake in all of your "if()" statements.

    To test of equality you must use a double equal sign as in example if(a == b).

    If you use a single equal sign you just assigns the right hand value to the left hand variable so if(a = b) would put the value of b into a and then test to see whether a is true or false.
     
Loading...