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

how to convert C code to HEX file

Discussion in 'Microcontrollers' started by pysch, Oct 24, 2008.

  1. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    hi there, i wanna ask if anybody know what software used to convert C codes to HEX file and how to do it....i'm using PIC16F876a..

    Please help me..i'm new/noob in these thing..Plus its urgent thou..
     
  2. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Hahahaha! :D:D These things are all SOOO urgent. :p Hehehe! What happened? Did you leave your class assignment till the last couple days before it's due? Good luck with learning C in a couple days. :p

    Anyway, what you're looking for is a C compiler. I recommend SourceBoost BoostC. The demo is only code size/RAM limited - works for all supported PICs. And when you hit the limits of the demo, a full license for the compiler is only about $75! Compare with C18's price of ~$500 and PICC's price of ~$1000. It's a no brainer! Better yet, BoostC comes with both 16F (supports some 12F also) and 18F compilers.
     
  3. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    kinda:eek::eek:

    can u explain to me more about this "SourceBoost BoostC."... does it writes C codes straight to PIC? By da way, i've done with writing on C.... i just don't know how to "burn-to-project" part.... kinda sucks at these thing..
     
  4. dave

    Dave New Member

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


     
  5. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.

    Really! I think you're the first to actually admit it here though. :D

    Who wrote your source code? What compiler did they write it for? You may be better off to get that compiler to save you having to port the source code to suit a different compiler's syntax. They all have their own ways of doing things. It's still C, but there are compiler-specific syntax differences (include file equates, etc.). If it's a small program it's not a big deal, but if it's large it can be quite a chore.

    Anyway, to program a chip you install the compiler, being sure that it gets integrated into MPLAB properly. Then start MPLAB and run the Project Wizard. Make a new project for your chip and select the compiler you just installed as the toolsuite. Add the necessary files to the project to suit your compiler (BoostC wants the appropriate lib file added) and also add the source file (put both the source and any associated header files in the project dir first).

    Select your programmer (assuming it's MPLAB compatible) and compile. Then program the chip. If your programmer is not MPLAB compatible you may have to run a different program to program the chip. The hex file will be in the project directory you created before compiling.
     
  6. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    Hey guys..

    when i tried compile this program using Sourceboost, it will show this error..

    ""C:\Program Files\SourceBoost\boostc.pic16.exe" -t PIC16F876A test.c
    BoostC Optimizing C Compiler Version 6.89 (for PIC16 architecture)
    SourceBoost Technologies - Home of BoostC Free PIC C Compiler and BoostBasic Free Pic Basic Compiler
    Copyright(C) 2004-2008 Pavel Baranov
    Copyright(C) 2004-2008 David Hobday
    Single user Lite License (Unregistered) for 0 node(s)
    Limitations: PIC12,PIC16 max code size:2048 words, max RAM banks:2, Non commercial use only
    test.c
    C:\Documents and Settings\FysL\Desktop\Source Code\test\test.c(10): Unable to open include file: pic.h
    1 errors detected
    failure
    Error: preprocessing error
    Failed to locate output file 'test.obj'
    Done
    Failed"

    can u help me please..
     
  7. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    when i was compiling this program...
    it show an error...
    "unable to open include pic.h"
    what does this mean???
     
  8. Noggin

    Noggin Member

    Joined:
    Jul 21, 2003
    Messages:
    595
    Likes:
    9
    Location:
    Austin, TX
    it means it can't find the file pic.h. If you look at the top of your c or h files there will be a line that states #include <pic.h>. The pic.h file is included with the compiler, though different compilers will call it by a slightly different name. Your source code is apparantly not written for sourceboost. You could either rewrite it or change compilers. Given the questions you're asking, I think you should figure out what compiler this code was written for, most likely microchip's c18 compiler. Download it from microchip.com
     
  9. Ubergeek63

    Ubergeek63 Well-Known Member

    Joined:
    Apr 16, 2008
    Messages:
    1,886
    Likes:
    37
    Or you could do it the old fashioned way: compile by hand ( convert C to assembly ), assemble by hand ( look up all the hex codes in an instruction code table ), and then enter them all into a .hex text file.

    Of course when I learned it I had to enter them manually into a hex keypad.
     
  10. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    i dont know how to make it by hand....
    is it MPLAB C Compiler for PIC18 MCUs?
    but i'm using pic16..
     
    Last edited: Nov 5, 2008
  11. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    do i have to-connect-to the board before compiling this program?
     
  12. Leftyretro

    Leftyretro New Member

    Joined:
    Mar 11, 2007
    Messages:
    1,420
    Likes:
    13
    Location:
    Hercules, California
    You had a hex keypad? We started with 16 individual front panel toggle bit switches in the early minicomputer days ;)
     
  13. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    can someone convert these code to asm and hex...
    i dont think i'm capable to do this anymore...
    i've trying for a month and using many compilers...
    and i have to send this thing on 8/11..

    please help me on these one...:(
    if someone want to help me...
    i will post the code here..
    thank you..
     
  14. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Your code is almost certainly written for Hi-Tech's PICC compiler, which uses the pic.h header.

    To change that for BoostC you would use system.h. All this stuff is in the manual.

    Here's the first lines of a typical BoostC program for an 18F448. The CLOCK_FREQ will have to be adjusted to suit your setup. The configs will be different for 16F's. A 16F will usually have only one line.

    Code (text):
    #include <system.h>
    #pragma CLOCK_FREQ 20000000
    #pragma DATA    _CONFIG1H, _HS_OSC_1H
    #pragma DATA    _CONFIG2H, _WDT_OFF_2H
    #pragma DATA    _CONFIG4L, _LVP_OFF_4L

    void main(void)
    {
        int i;
        trisc=0;
        while(1){
            for(i=0;i<256;i++){
                latc.3=1;
                delay_10us(i);
                latc.3=0;
                delay_ms(5);
            }
            delay_ms(50);
     
     
    Last edited: Nov 5, 2008
  15. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    what do i have to do with this code?
    make a new file.. and name it as system.h?
     
  16. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    No. Why would you even think that? :p

    Replace the pic.h header line in your program with the system.h one. Then you'll have to make some other changes to suit differences in how the two compilers name things like registers, and how they access bits in registers.
     
    Last edited: Nov 5, 2008
  17. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    i get this one..

    is it like this
    Code (text):

    #pragma CLOCK_FREQ 4000000
    #pragma DATA 0x2007, 0x184
    #include <system.h>
     
    i dont know about this can u help me..
     
    Last edited: Nov 5, 2008
  18. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    You're supposed to complete your own school assignments else how are you learning anything if someone does it for you?
     
  19. pysch

    pysch New Member

    Joined:
    Oct 24, 2008
    Messages:
    10
    Likes:
    0
    i'm sorry for my stupid reply before..
    kinda lose hope in doing something i dont know much..

    as futz were saying that my header were wrong...
    i already know the clock..
    what about the config??
    what the use of it..
    could u help me..
     
  20. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    You'll find quite a bit of simple "example" BoostC code at my web-site. With that and the BoostC manual you should be able to figure out the changes to make.
     
  21. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    People here don't mind helping, but I don't think anyone will do your work for you.

    The clock frequency and included header look correct.

    The config settings are done differently in SB. For example:
    Much easier than using a hex number and having to look up which bits are being set or reset in the data sheet.

    You should start by reading this thread:
    "pic Micro Programming In Boostc For Beginners" - SourceBoost support forum

    I'd try a simple exercise like blinking an LED first to make sure you have it right, then go on with your project.

    When you have some questions, come back and get some help, or sign up to the SourceBoost forums, and get some help there too.

    You have a couple of days left, if you work hard, you can do it.

    Edit:
    Sorry futz, I should have thought about your excellent site! Great advice pysch, take it.
     
    Last edited: Nov 6, 2008

Share This Page