1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

compiler for c

Discussion in 'Microcontrollers' started by Dr_Doggy, Dec 28, 2011.

  1. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    mostly i have been using GCGB compiler which is working fine so i am keeping it for my 10f-18f smaller pgm apps.
    however i have been working on some code where GCGB isn't cutting it any longer so i need to switch to a c compiler, what is the easiest option here; is there a better one?



    A)ihave mplab ide; which has worked with assembally code(which I dont know) demos. there is a way to set it up for c but i ran in to details. Maybe i just need a template file(for16f886)?

    B) I have tried WIZ-C PRO and i got the first demo to run on simulator, but then nothing else again(i think i have the wrong file loaded in). saying that this software may be to complex for me to "crash start"..,, but i do like the notion of the simulator.

    C) swordfish has been working for me but my code has exceeded demo, maybe its best to just blow the 200$ to get the full license?
     
  2. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    I think Hi-Tech C is a popular choice, especially with MPLAB. It comes in lite mode for free and seems to work great. I personally use C18 Lite (from Microchip) because I only have 18F chips. Hi-Tech covers a huge range of processors, though, and it would definitely be worth looking into. You can find the download for the lite version at the bottom of this page.

    I hope this helps!
    Good luck
     
    Last edited: Dec 28, 2011
  3. Gobbledok

    Gobbledok Active Member

    Joined:
    Mar 9, 2008
    Messages:
    452
    Likes:
    34
    Location:
    Toowoomba, Australia
    The easiest way is to use MPLAB. If you didn't install it during MPLAB installation, then you should find the Hi-Tech C Compiler at C:/Program Files (x86)/Microchip/picc-x.xx-win.exe, depending on your system.

    Note that the included Hi-Tech C Compiler is suitable for PIC 10/12/16's only, you will need Microchip C18 for PIC18's. You will need Microchip PIC C30 for PIC24's and dsPIC's and Microchip C32 for PIC32's.

    Then all you have to do is select the suitable C Compiler as your Tool Suite when starting a new project.
     
    Last edited: Dec 28, 2011
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA

    We have the option of using the lite version of the Hi-Tech 18F compiler too. It is part of the Hi-Tech universal toolsuite. (
     
  6. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,024
    Likes:
    317
    Location:
    Brisbane Australia
    For 16 series devices I tend to use BoostC over HiTech C. The main reason is the price for the full version, $70 -v- $500. Both have free versions to try.

    You may also want to look at BoostBasic as, although I haven't tried it, it's supposed to be similar to VB and therefore should be similar to Swordfish.

    For 18 series I use C18 and BoostC.

    Mike.
     
  7. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    c18 it is , thnx guys!
     
  8. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    Enjoy. It's the one I use, and it works great. Good luck!
     
  9. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,024
    Likes:
    317
    Location:
    Brisbane Australia
    You mentioned the 16F886 in your original post and so I thought I'd point out that C18 will not work for that chip.

    Mike.
     
  10. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    yup, i forgot to point that out, the code that needs to be extended is for an 18f, but my demoboard is 16f, I thought they would be similar enough that if i got one going the switch would be simple, my bad!

    im just watching now 3v0 intro demo so i ll bbs with lots of ?'s !
     
  11. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    I should do a version of that demo for the hi-tech and the demo board that comes with pk2.
     
  12. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    WOW, so i got furthur than i though i would anyway! i got to 6min in to the demo, but when i build it says FAILED
    "Error - Device not specified. Use /p option to specify a device."

    i went in to configure/select device.... and my pic is selected there, also i believe i have copied the source file exactly


    #pragma config OSC=INTIO67, WDT=OFF, LVP=OFF
    #include <p18f4620.h>
    void main (void)
    {
    }


    right?
     
  13. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    Did you remember to add the p18f4620.h header file to your project?

    What version of MPLAB are you using?

    Some versions had an error that would not set it properly. You can fix this by doing the following:

    Go to Project –> Build Options –> Project, and open the MPLINK Linker tab. Make sure the ‘Use Alternate Settings’ check box is checked, for this setup.

    You should see something that looks like this:

    /m”$(BINDIR_)$(TARGETBASE).map”/w/o”$(BINDIR_)$(TARGETBASE).cof”

    You'll need to change this to:

    /m”$(BINDIR_)$(TARGETBASE).map”/w/p18F4620/o”$(BINDIR_)$(TARGETBASE).cof”

    Let me know if this doesn't work, and I'll do some more research.

    Good luck!
     
    Last edited: Dec 29, 2011
  14. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    :( yes, and the linker file aswell :(
     
  15. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    Check my edited post above.
     
    Last edited: Dec 29, 2011
  16. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    OK! IT workS! thnx!
     
  17. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    You're welcome. I'm glad to hear it :)
     
  18. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    OK everything seems to be working ok, however i am just having a simple problem with some of the basic switching functions; I understand that TRIS(A-E) sets up the port and that PORT(A-E) change the bit values out(i will stay digital for now); but is there a way to change a single bit? in GCGB i would just say: SET PORTD.3 ON; also how would i say: READ PORTB.2?
     
  19. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    If your library doesn't define (structures for) bit fields you can define your own. Read this thread:
    http://www.electro-tech-online.com/threads/c18-structure-for-bits.94878/

    I like to use macros for bit access. Setting a bit for example:

    Code (text):

    #define sbi(port, bit) ((port) |= (1 << (bit)))

    main()
    {
    /* Set bit 3 in Port B */
    sbi(PORTB, 3);
    }
     
    Here is a full collection of my bit operation macros:

    Code (text):

    /* Bit operation macros */
    #define sbi(b,n) (b |= (1<<n))            /* Set bit number n in byte b */
    #define cbi(b,n) (b &= (~(1<<n)))         /* Clear bit number n in byte b   */
    #define fbi(b,n) (b ^= (1<<n))            /* Flip bit number n in byte b    */

    #define bit_is_set(b,n) (b & (1<<n))       /* Return nonzero if bit is set */
    #define bit_is_clear(b,n) (!(b & (1<<n)))  /* Return nonzero if bit is clear */

    #define wait_until_bit_is_set(b,n)   while(bit_is_clear(b,n)){}
    #define wait_until_bit_is_clear(b,n) while(bit_is_set(b,n)){}
     
     
    Last edited: Jan 1, 2012
  20. nickelflippr

    nickelflippr Member

    Joined:
    Oct 20, 2006
    Messages:
    891
    Likes:
    18
    Location:
    Oregon, USA
    Out of curiosity, where do you encounter the roadblock? is it math functions? array size?, some other libraries? Any specific code that doesn't work?
     
  21. Gobbledok

    Gobbledok Active Member

    Joined:
    Mar 9, 2008
    Messages:
    452
    Likes:
    34
    Location:
    Toowoomba, Australia
    You can also use:

    LATAbits.LATA0 = 1; to set a bit, or:

    PORTAbits.RA0; to read a bit.
     

Share This Page