MPLAB IDE code help

Discussion in 'Embedded Systems and Microcontrollers' started by shinigami.alv, Apr 21, 2012.

  1. shinigami.alv

    Thread Starter New Member

    Feb 23, 2011
    4
    0
    im using 16F877A with MPLAB as compiler but program wont work. previously used ccs and worked fine. my program supposes to light up LED for 2 secs after pressing a button. (used inverter so it's active-high) below is my code:

    Code ( (Unknown Language)):
    1. #include <pic.h>
    2. #define _XTAL_FREQ 20000000
    3.  
    4.  
    5. void main(void)
    6. {
    7.                    
    8.  
    9.   TRISD = 0b000000;
    10.   TRISC = 0b111111;
    11.  
    12.  
    13.  
    14.    while(1)
    15.   {
    16.  
    17.   if (RC2=1)
    18.   {
    19.  RD2=1;
    20.  while (RC2=1);
    21.  __delay_ms(2000);
    22.  RD2=0;
    23.  }
    24.  
    25. else RD2=0;
    26.  
    27.  if (RC3=1)
    28.   {
    29.  RD3=1;
    30.  while(RC3=1);
    31.  __delay_ms(2000);
    32.  RD3=0;
    33.  }
    34.  else RD3=0;
    35.  
    36.  
    37.    }
    38.  
    39.  
    40. }
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    In all of your if ( ) and while ( )
    the proper comparison operator is ==
    For example
    while ( RC3 == 1)

    RC3 = 1 is an assignment operation
    RC3 == 1 is a logical operation
     
  3. shinigami.alv

    Thread Starter New Member

    Feb 23, 2011
    4
    0
    okay, fixed that. but found out my major problem is that i did not put '__CONFIG (0x3F32);' and now it's solved. thanks for your help!
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    __CONFIG(0x3F32) is rather cryptic and doesn't indicate what options are selected.

    Use a statement such as:

    __CONFIG( XT & WDTDIS & PWRTDIS & BORDIS & LVPDIS & DEBUGEN & UNPROTECT);

    Your selected setting of 0x3F32 is

    __CONFIG( HS & WDTDIS & CPD & CP);


    To find out the Configuration bit definitions, look at the the pic16f887.h file found in
    in the HI_TECH include folder.
    The listing is at the end of the file.
     
Loading...