Continue to Site

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.

  • 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.

how to convert C code to HEX file

Status
Not open for further replies.

pysch

New Member
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..
 
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..
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.
 
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?
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..
 
Really! I think you're the first to actually admit it here though. :D

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..
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.
 
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..
 
when i was compiling this program...
it show an error...
"unable to open include pic.h"
what does this mean???
 
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
 
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.
 
i dont know how to make it by hand....
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
is it MPLAB C Compiler for PIC18 MCUs?
but i'm using pic16..
 
Last edited:
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.

You had a hex keypad? We started with 16 individual front panel toggle bit switches in the early minicomputer days ;)
 
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..
 
C:\Documents and Settings\FysL\Desktop\Source Code\test\test.c(10): Unable to open include file: pic.h
1 errors detected
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:
#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:
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:
#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);

what do i have to do with this code?
make a new file.. and name it as system.h?
 
what do i have to do with this code?
make a new file.. and name it as system.h?
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:
Replace the pic.h header line in your program with the system.h one.

i get this one..

is it like this
Code:
#pragma CLOCK_FREQ 4000000
#pragma DATA 0x2007, 0x184
#include <system.h>

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.

i dont know about this can u help me..
 
Last edited:
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..

You're supposed to complete your own school assignments else how are you learning anything if someone does it for you?
 
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..
 
i get this one..

is it like this
Code:
#pragma CLOCK_FREQ 4000000
#pragma DATA 0x2007, 0x184
#include <system.h>
i dont know about this can u help me..

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:
#pragma DATA _CONFIG, _XT_OSC & _WDT_OFF & _CP_OFF & _PWRTE_OFF
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:
**broken link removed**

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:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top