0

How can I compile a different micro-controller on different micro-controller family IDE/compiler.

For example, I have 8051 keil uVision IDE. I need to compile the code for PIC or AVR controller. Is it possible, by changing any internal settings in the IDE? Or by adding Controller specific header files etc.?

The Actual answer i required here is,

what the IDE/compiler will add to the code after selecting a particular "Microcontroller" in device list of keil or AVR Studio or PIC etc..?

  • As i know, Eclipse supports for all the family controllers. But even though it needs platform dependent toolchains etc.. for different controllers – Lokesh V Gowda Jun 12 '15 at 04:31
  • 1
    "Eclipse supports ...": Well .. not really. Eclipse just supports various code compilers/etc. , which _in term_ support various CPUs. However, even with the same CPU core, your code will very likely not run after just a re-compiler. For different architectures, just forget about it. You will have to rewrite all hardware-related parts - at least, if the logic-only parts are properly designed (e.g. no `int` for 16 bit values, but `int16_t`, etc.) – too honest for this site Jun 12 '15 at 11:25
  • 1
    You'll need to study how C code compiles into machine code before doing anything else. – Lundin Jun 12 '15 at 11:51

3 Answers3

4

what the IDE/compiler will add to the code after selecting a particular "Microcontroller" in device list of keil or AVR Studio or PIC etc..?

You are getting it wrong. Let's take a different approach:

Think of a C program as a specification for your processor i.e description in human readable language how it should perform sequentially.

Now each processor has different Hardware architecture and different set of instructions to control it.

Normally ,a C compiler will convert the C Code into Assembly (.asm/.a) instructions specified for that particular processor.

So a C Compiler for different architectures is along-together a different compiler.

In Eclipse or IAR tool-chain you use a different compilers for different processors.

Vagish
  • 2,520
  • 19
  • 32
  • Thank you Vagish, got it – Lokesh V Gowda Jun 12 '15 at 08:17
  • Ok compiler produces specific controller related .ASM code from C code before producing output file. If the compilers of different controllers family doing only this different thing means, Then if we develope the code directly in ASM we could produce the output(hex) file using any compiler right? – Lokesh V Gowda Jun 12 '15 at 10:48
  • @LokeshVGowda: Start at [Wikipedia](https://en.wikipedia.org/wiki/List_of_CPU_architectures) and follow the links. There are hundrets of different CPU architectures, each with very different instruction sets, registers sets, features, word-widths, etc. – too honest for this site Jun 12 '15 at 11:32
  • @LokeshVGowda Generating a hex from a assembly is a job of assembler. I suggest you to refer a compiler reference manual and IDE manual for any one of the architectures of your interest. – Vagish Jun 12 '15 at 11:52
2

No. PIC and AVR are both separate architectures from the 8051, and as such require entirely different compilers. You cannot convert a compiler for one into another by changing settings or adding header files; they are simply too different.

Keil does not provide compilers for the AVR or PIC architectures; you will need to install another development environment to work with those parts.

  • thank u duskwuff, my question is what the compiler add internally, specific to that controller during compilation? I know it cannot be seen. But in the background compiler adding some controller specific things with our c code before producing hex file right? – Lokesh V Gowda Jun 12 '15 at 06:47
  • 1
    That doesn't make a lot of sense as a question, as you're still assuming that there's some underlying similarity. There really isn't. The three controllers you're referring to (8051, AVR, and PIC) all have completely different instruction sets, memory models, and peripherals. –  Jun 12 '15 at 06:51
  • @Lokesh V Gowda: For the particular issue of which files are more or less silently added by the IDE, On _Keil µVision_ IDE for the **8051** architecture, the 2 files STARTUP.A51 and INIT.A51that you typically find under C:\Keil\C51\LIB are added. You may add these files explicitely (init.a51 should be the last files of the project) if you want to see in the debugger what's going on . These files are valid for my system based of Silabs µC. In the folder you will find other similar files for other 8051 based µC from other Vendors. For PIC or AVR you have to port your C Code to other IDEs – NGI Jun 12 '15 at 08:39
  • hi Mr. duskwuff, Can you please tell me what data will be there in that 2 files you mentioned (STARTUP.A51 and INIT.A51) – Lokesh V Gowda Jun 12 '15 at 10:51
  • @Lokesh V Gowda These files are assembler files and are here to initialize the microcontroller after reset ( paging if you use it, usual stack if you use it, setting of the global variables (with initialization) from code to ram... ). You may edit these files and read the assembler code and the comments. Under µVision editor these files have an additional below tab for a more human user-friendly view. Up to now I have never had the need to modify them and I leave the IDE add them implicitely for me ( I just saved them under configuration management (svn) in case... ) – NGI Jun 12 '15 at 11:50
1

There are 2 types of compilers

  1. Native
  2. Cross compiler

Native On a PC when you write a program in high level language and compiles using let us say "Visual studio" it generates code for microprocessor on your computer. ( Most probably Intel ).

Compiler convert the high level language constructs into machine language of microprocessor.

Cross compiler A cross compiler is compiler which converts the C code into other microprocessor /micro-controller machine language.

Now various tool like Keil uVision, IAR Embedded Workbench , Code Composer Studio which runs on PC but create machine code for micro-controller selected. Every IDE will provide list of processor families and part number which it supports and it compiles C code accordingly.

These IDE provides various features to configure your program output as per the hardware. Start up and INIT.A51 file you have mentioned will do necessary hardware initialization before main() function will start executing your program.

So when you select particular part number from device list compiler checks if compiled output can be run on part mentioned. For example : If your program requires X amount of RAM and controller has less than X amount of memory it will throw compiler error.

prasad
  • 219
  • 3
  • 17