From: roelof 't H. <ro...@it...> - 2015-04-30 07:48:07
|
On Thu, 2015-04-30 at 11:53 +0530, Ashok Das wrote: > Hi Ondrej, > > > Thanks for the reply. But as I am new to this compiling and linking > stuff, can you please be a little more elaborate ? Hi Ashok, It works like I tried to show you in my reply. The steps you have to take to get a hex file : - write a source file - compile the source (sdcc will link the .rel file automagically to a .ihx file) - pack your .ihx file to .hex if necessary - load your .ihx/.hex file into uC roelofh@castle:~/test$ sdcc --code-loc 0x2000 test.c roelofh@castle:~/test$ packihx test.ihx > test.hex OR - write source files (just one with "void main(void)" ;-) ) - compile all the source files - link all the .rel files - pack your .ihx file to .hex if necessary - load your .ihx/.hex file into uC roelofh@castle:~/test$ sdcc --code-loc 0x2000 -c test.c roelofh@castle:~/test$ sdcc --code-loc 0x2000 -c main.c roelofh@castle:~/test$ sdcc --code-loc 0x2000 main.rel test.rel roelofh@castle:~/test$ packihx main.ihx > main.hex The first file name that gets named on the link command line is also the name of the resulting output file. Just look at the resulting files in the directory with cat/less/vim or mc. By looking into these files you can deduct the order in which and by what program they where made. Here are the sources for the last compile/link example for you to try : (you might want to change the processor header to the correct type you are using :-) ) ----- main.c #include "types.h" #include "87c591.h" #include "test.h" void main(void) { volatile uint8 rc8; rc8 = 0; while(1) { rc8 += subroutine(rc8); rc8--; } } ----- test.c #include "types.h" #include "87c591.h" uint8 subroutine(uint8 input) { return input * 2; } ----- test.h #ifndef _test_h_ #define _test_h_ #define true 1 #define false 0 uint8 subroutine(uint8); #endif ----- types.h #ifndef _types_h_ #define _types_h_ /******************************************************************************* * Typedefs for the C99 coding standard ******************************************************************************/ typedef unsigned char uint8; typedef signed char int8; typedef unsigned int uint16; typedef signed int int16; typedef unsigned long uint32; typedef signed long int32; #endif |