Mplab help!!!

Discussion in 'Programmer's Corner' started by Rk17, Apr 23, 2011.

  1. Rk17

    Rk17 Thread Starter Member

    Joined:
    Apr 23, 2011
    Messages:
    43
    helo its my first time to post here i really need some help regarding mplab. i cant compile a code in mplab ide; i use the hi-tech compiler; here is the code

    #include <16c84.h> #USE DELAY( CLOCK=4000000 ) /* Using a 4 Mhz clock */ #FUSES XT,NOWDT,NOPROTECT,NOPUT /* Use XT mode, No Watch Dog, No Code Protect, No Power-up Timer */ #byte port_b=6 /* define the location of register port_b */ main(){ byte cnt; value; set_tris_b(0); /* set port_b to be outputs */ port_b = 0; /* initialize All port_b outp/uts to be zero */ value = 0x01; while( TRUE ) { /* forever loop using WHILE construct */ cnt = 0; while ( cnt<8 ) { port_b = value; DELAY_MS(1000); value = value << 1; /* shift left will put 0x01, 0x02, 0x04, 0x08, 0x10 */ cnt++; /* 0x20, 0x40, 0x80 to port_b */ } } }

    >>and here is the error;

    Build C:\Documents and Settings\Administrator\My Documents\forsundayfinal\srv for device 16F84A
    Using driver C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe

    Make: The target "C:\Documents and Settings\Administrator\My Documents\forsundayfinal\srv.p1" is out of date.
    Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" --pass1 "C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\srv.c" -q --chip=16F84A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
    Error [141] C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\srv.c; 1.18 can't open include file "16c84.h": No such file or directory

    ********** Build failed! **********


    **i dont know the cause of this.. please help me.. tnx in advnce!


  2. nerdegutta

    nerdegutta Senior Member

    Joined:
    Dec 15, 2009
    Messages:
    1,749
    Location:
    (GMT +1)
    For starters, if you edit your post, and use the code - tag, the readability will be much better. :)

    What PIC are you programming? 16F84 or 16C84?

    Try changing the:
    Code:
    #include <16c84.h>
    
    with:
    Code:
    #include <htc.h>
    
    You configuration word looks also a bit off...
    Rk17 likes this.
  3. Rk17

    Rk17 Thread Starter Member

    Joined:
    Apr 23, 2011
    Messages:
    43
    im kind of a rookie in this stuff but thanks for the help bor i really appreciate it by the way what does #include <htc.h> mean?

    ive did what you said and the result got better but still faild to compile here is the error code i got>>

    Make: The target "C:\Documents and Settings\Administrator\My Documents\forsundayfinal\srv.p1" is out of date.
    Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" --pass1 "C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\16F84A_delay (100)\srv.c" -q --chip=16F84A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
    Warning [361] C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\16F84A_delay (100)\srv.c; 54.1 function declared implicit int
    Warning [361] C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\16F84A_delay (100)\srv.c; 56.1 function declared implicit int
    Warning [361] C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\16F84A_delay (100)\srv.c; 58.1 function declared implicit int
    Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" -osrv.cof -msrv.map --summary=default --output=default srv.p1 --chip=16F84A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
    HI-TECH C Compiler for PIC10/12/16 MCUs (PRO Mode) V9.81
    Copyright (C) 2010 Microchip Technology Inc.
    Licensed for evaluation purposes only.
    This licence will expire on Tue, 07 Jun 2011.
    Warning [1090] C:\Documents and Settings\Administrator\My Documents\pic16F84 projects\16F84A_delay (100)\srv.c; 41. variable "_i" is not used
    Error [500] ; 0. undefined symbols:
    _Delay_ms(srv.obj) _resBit(srv.obj) _setBit(srv.obj)

    ********** Build failed! **********

    ive program the source code on my PIC16F84A and it worked when i used the hex file that was the 100ms delay time.
    I wish to recompile the file to do a little experiment (change 100ms to 5000ms) but it turned out to be that mplab cant recompile

    further help would be highly appreciated tnx in advance
  4. spinnaker

    spinnaker Senior Member

    Joined:
    Oct 29, 2009
    Messages:
    3,687
    Location:
    Pittsburgh, PA U.S.A.
    Repost your code with code tags as suggested and mark whicj line is 361.

    but those are warnings and usually nothing to worry about.

    This line

    Error [500] ; 0. undefined symbols:
    _Delay_ms(srv.obj) _resBit(srv.obj) _setBit(srv.obj)

    is an error and it means these are functions missing from your project. The need to be included either from a library or source code included in your project.

    And this should have been posted in the embedded forum and not here. Hopefully a mod will move it soon. If not then PM a mode.
    Rk17 likes this.
  5. Rk17

    Rk17 Thread Starter Member

    Joined:
    Apr 23, 2011
    Messages:
    43
    ok tanx for the info i really appreciate it. ill try it again
  6. Rk17

    Rk17 Thread Starter Member

    Joined:
    Apr 23, 2011
    Messages:
    43
    sir it seems that _Delay_ms(srv.obj) _resBit(srv.obj) _setBit(srv.obj) are terms which mplab can not indentify. here is the code
    >>
    #include <htc.h>

    void main() {
    unsigned short pa=0;
    unsigned int i;


    PORTA = 0;
    TRISA = 0; // o/p - sets analogue pins to digital output

    TRISB = 0;
    PORTB = 0;

    while(1) {

    pa=~pa;
    if (pa) {
    setBit(PORTB,3);
    } else {
    resBit(PORTB,3);
    }
    Delay_ms(100);
    } ; // infinite while loop
    }

    >>i got this from this link http://www.best-microcontroller-projects.com/pic16f84.html#Circuit_diagram

    im using mplab.. but it says mikroC is there a difference between the two? they have the same commands in c right?

    i have a .ppc file also downloaded with it but i dont know how to open it.

    tnx for the help sir
  7. nerdegutta

    nerdegutta Senior Member

    Joined:
    Dec 15, 2009
    Messages:
    1,749
    Location:
    (GMT +1)
    This line:
    Code:
    #include <htc.h>
    
    tells the compiler to include the file htc.h at compile time.

    Try:
    Code:
    __delay_ms(1000);
    
    Instead of:
    Code:
    Delay_ms(1000);
    
    You can not mix MikroC and MPLAB Hi-tech C. Stick with one of them.
    Rk17 likes this.
  8. t06afre

    t06afre AAC Fanatic!

    Joined:
    May 11, 2009
    Messages:
    5,939
    You are using a program not written for HI-Tech C hence all your problems.
    before you do anything more I will STRONGLY recommend reading the document
    C:\Program Files\HI-TECH Software\PICC\9.81\docs\quickstart.pdf
    Then in the same folder you will also find the manual. Check out the function __delay_ms. And HI-tech C also do not use the
    Code:
     
    #FUSES XT,NOWDT,NOPROTECT,NOPUT 
    
    but rather
    Code:
    __CONFIG(XT & WDTDIS & PWRTDIS & BORDIS & LVPEN & WRTEN &DEBUGEN & DUNPROT & UNPROTECT);
    
    as an example. This setting may not apply to your MCU
    And please use code tags
    Rk17 likes this.
  9. Rk17

    Rk17 Thread Starter Member

    Joined:
    Apr 23, 2011
    Messages:
    43
    ah ok now i think i get it thnks again.. sori bout that. really appreciate your help :D
  10. nerdegutta

    nerdegutta Senior Member

    Joined:
    Dec 15, 2009
    Messages:
    1,749
    Location:
    (GMT +1)
    What does your code look like now?

    Post it with code-tags... It's the # symbol in the menu on top of the editor...
    Rk17 likes this.
  11. Rk17

    Rk17 Thread Starter Member

    Joined:
    Apr 23, 2011
    Messages:
    43
    i still got this error message:

    Code:
    Error   [500] ; . undefined symbols:
        _resBit (16F84_LED_Flash.obj)_setBit (16F84_LED_Flash.obj)___delay_ms (16F84_LED_Flash.obj) 
    it says undefined symbols is my code still wrong?
  12. nerdegutta

    nerdegutta Senior Member

    Joined:
    Dec 15, 2009
    Messages:
    1,749
    Location:
    (GMT +1)
    We got that, but I think it would be easier if you posted your code.

    Are you still using MPLAB and Hi-tech C?
    Rk17 likes this.
  13. Rk17

    Rk17 Thread Starter Member

    Joined:
    Apr 23, 2011
    Messages:
    43
    Code:
     //////////////////////////////////////////////////////////////////////
    //
    // File: 16F84_led_flash.c
    //
    // Author: J F Main.
    //
    // Description:
    //
    //   Flash an led at RB3
    //
    // Compiler : mikroC, mikroElektronika C compiler
    //            for Microchip PIC microcontrollers
    //            Version: 5.0.0.3
    //
    // Note Testing:
    //
    //   Tested on 16F84
    //
    // Requirements:
    //
    //   Target : 16F84
    //
    // Notes :
    //
    //   Uses internal oscillator.
    //
    // Version:
    // 1.00 Initial release.
    //
    // Copyright : Copyright © John Main 2006
    //   http://www.best-microcontroller-projects.com
    //   Free for non commercial use as long as this entire copyright notice
    //   is included in source code and any other documentation.
    //
    //////////////////////////////////////////////////////////////////////
    
    #include <htc.h>
    
    void main() {
    unsigned short pa=0;
    unsigned int i;
    
    
      PORTA = 0;
      TRISA = 0; // o/p   - sets analogue pins to digital output
    
      TRISB = 0;
      PORTB = 0;
    
      while(1) {
    
         pa=~pa;
         if (pa) {
            setBit(PORTB,3);
         } else {
            resBit(PORTB,3);
         }
         Delay_ms(100);
      } ; // infinite while loop
    } 
    this is the link where i got the code

    [LINK]http://www.best-microcontroller-projects.com/pic16f84.html#Circuit_diagram[/LINK]
  14. nerdegutta

    nerdegutta Senior Member

    Joined:
    Dec 15, 2009
    Messages:
    1,749
    Location:
    (GMT +1)
    Are you using MikroC or MPLAB?
    Rk17 likes this.
  15. Rk17

    Rk17 Thread Starter Member

    Joined:
    Apr 23, 2011
    Messages:
    43
    im using mplab IDE v8.66 and the hi-tech C compiler
  16. nerdegutta

    nerdegutta Senior Member

    Joined:
    Dec 15, 2009
    Messages:
    1,749
    Location:
    (GMT +1)
    Then I think you need to redo some of your code... Have you read the documents recomended by t06afre?
  17. nerdegutta

    nerdegutta Senior Member

    Joined:
    Dec 15, 2009
    Messages:
    1,749
    Location:
    (GMT +1)
    In the comment section of your program, it says:

    Code:
    // Compiler : mikroC, mikroElektronika C compiler
    //            for Microchip PIC microcontrollers
    //            Version: 5.0.0.3
    
    
    I think this little code will blink a LED on a PIC16F628.

    Code:
    #include <htc.h> 
    #define _XTAL_FREQ 4000000 
     
    /* Configuration */ 
     
    __CONFIG    (WDTDIS & 
                PWRTEN & 
                MCLREN & 
                BOREN & 
                LVPDIS & 
                DATUNPROT & 
                UNPROTECT & 
                XT); 
     
    /* Prototyping the functions */ 
    /*  For future references */ 
     
    /* Global variables */ 
    /*  For future references */
     
    /* Main program */ 
    void main() 
    { 
    TRISA = 0b00000000;    // Setting all bits on port a to output
    TRISB = 0b00000000;    // Setting all bits on port b to output 
     
    PORTA = 0b00000000;    // Setting all bits on port a to LOW 
    PORTB = 0b00000000;    // Setting all bits on port b to LOW 
     
    CMCON = 0x07;    // Disabling the analogue comparators 
     
    while (1) 
    { 
     
        PORTB = 0b00000001; // Setting bit 0 to HIGH 
        __delay_ms(1000); 
     
        PORTB = 0b00000000; // Setting all bits to LOW
        __delay_ms(1000); 
     
    } // end while 
     
    }  //end main
    
    
    I don't think those two PIC are so different....
    Rk17 likes this.
  18. Rk17

    Rk17 Thread Starter Member

    Joined:
    Apr 23, 2011
    Messages:
    43
    will this work on a picF84A?

    ive tried to compile it but it failed

    Code:
    Error   [139] ; . end of file in comment
    just this error though. please try to double chek it i i wanna give it a try if it works tnx
  19. nerdegutta

    nerdegutta Senior Member

    Joined:
    Dec 15, 2009
    Messages:
    1,749
    Location:
    (GMT +1)
    What does you code look like now?

    Have you built a circuit yet?
    Rk17 likes this.
  20. AlexR

    AlexR Well-Known Member

    Joined:
    Jan 16, 2008
    Messages:
    735
    Location:
    Australia (UTC+10)
    The config bit names are wrong. Also if you are using a PIC16F84A you need to comment out the line "CMCON = 0x07;" as that chip has no CMON register.
    The code below should compile correctly.
    Code:
    #include <htc.h> 
    #define _XTAL_FREQ 4000000 
     
    /* Configuration */ 
     
    __CONFIG(WDTE_OFF & PWRTE_ON & CP_OFF & FOSC_XT); 
     
    /* Prototyping the functions */ 
    /*  For future references */ 
     
    /* Global variables */ 
    /*  For future references */
     
    /* Main program */ 
    void main() 
    { 
        TRISA = 0b00000000;    // Setting all bits on port a to output
        TRISB = 0b00000000;    // Setting all bits on port b to output 
        PORTA = 0b00000000;    // Setting all bits on port a to LOW 
        PORTB = 0b00000000;    // Setting all bits on port b to LOW  
     
        while (1) 
        { 
             PORTB = 0b00000001; // Setting bit 0 to HIGH 
            __delay_ms(1000); 
     
            PORTB = 0b00000000; // Setting all bits to LOW
            __delay_ms(1000); 
     
        } 
     
    }  
    
    Rk17 likes this.
Similar Threads
Forum Title Date
Programmer's Corner Can't figure out this Unexpected Token, MPlab X & XC8 Wednesday at 7:38 PM
Programmer's Corner trouble downloading mplabx 2.26 ide Nov 24, 2014
Programmer's Corner Build Failures after updating MPLabX and XC8 Nov 22, 2014
Programmer's Corner MPLAB Window Sep 2, 2014
Programmer's Corner Types of delay in C language and changes in MPLAB X XC8 May 5, 2014

Share This Page