Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 25th October 2008, 07:22 AM   #1
Default how to convert C code to HEX file

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..
pysch is offline  
Old 25th October 2008, 07:43 AM   #2
Default

Quote:
Originally Posted by pysch View Post
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! These things are all SOOO urgent. 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.

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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 25th October 2008, 08:09 AM   #3
Default

Quote:
Originally Posted by futz View Post
Hahahaha! These things are all SOOO urgent. Hehehe! What happened? Did you leave your class assignment till the last couple days before it's due?
kinda

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..
pysch is offline  
Old 25th October 2008, 08:21 AM   #4
Default

Quote:
Originally Posted by pysch View Post
kinda
Really! I think you're the first to actually admit it here though.

Quote:
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 5th November 2008, 05:35 AM   #5
Default

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..
pysch is offline  
Old 5th November 2008, 09:50 AM   #6
Default

when i was compiling this program...
it show an error...
"unable to open include pic.h"
what does this mean???
pysch is offline  
Old 5th November 2008, 11:35 PM   #7
Default

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
__________________
A rectangular bear is just a polar bear after a coordinate transform. -- I dunno who.
A recent study shows that research causes cancer in rats. -- I dunno who said that one either.
Noggin is offline  
Old 5th November 2008, 11:58 PM   #8
Default

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.
Ubergeek63 is offline  
Old 6th November 2008, 12:04 AM   #9
Default

i dont know how to make it by hand....
Quote:
Originally Posted by Noggin View Post
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 by pysch; 6th November 2008 at 12:39 AM.
pysch is offline  
Old 6th November 2008, 12:46 AM   #10
Default

do i have to-connect-to the board before compiling this program?
pysch is offline  
Old 6th November 2008, 12:57 AM   #11
Default

Quote:
Originally Posted by Ubergeek63 View Post
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
__________________
Measurement changes behavior
Leftyretro is offline  
Old 6th November 2008, 01:46 AM   #12
Default

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..
pysch is offline  
Old 6th November 2008, 01:54 AM   #13
Default

Quote:
Originally Posted by pysch View Post
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);
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 6th November 2008 at 01:58 AM.
futz is offline  
Old 6th November 2008, 02:01 AM   #14
Default

Quote:
Originally Posted by futz View Post
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?
pysch is offline  
Old 6th November 2008, 02:06 AM   #15
Default

Quote:
Originally Posted by pysch View Post
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?

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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 6th November 2008 at 02:07 AM.
futz is offline  
Reply

Tags
code, convert, file, hex

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Help convert 12c508a file to 16F84 OY2L Micro Controllers 3 26th March 2008 02:49 PM
I want to convert Voltage to digital (BCD Code) nuttaphong191 Electronic Projects Design/Ideas/Reviews 7 15th March 2008 03:30 PM
Convert binary to BCD code genetica General Electronics Chat 7 16th September 2007 03:37 PM
convert hex code to 7 seg display electroicarus General Electronics Chat 12 26th July 2006 02:58 PM
how can i convert this code from C language into assembly ?? zika1212 Micro Controllers 1 24th March 2004 11:56 PM



All times are GMT. The time now is 10:46 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker