The microcontroller software development will be based around a programming environment which will normally include:
- A text editor to develop the source program code
- An Assembler to produce a machine executable program with linked library modules
- Some form of debugging to allow the program to be tested
- Access to a programmer to program the target device.
- The job of the Assembler is to convert the source code produced by the programmer into an object code file. It works by replacing each line of assembly instruction code with the corresponding machine code instruction that will be executed on the target microcontroller.
The object code file cannot be executed on the target microcontroller. It needs to be passed through a program called a Linker. The job of the Linker is to take the object file produced by the Assembler and link it with standard library modules (that have already been pre-assembled into object files) to produce a complete working executable file that can be loaded into the memory of the microcontroller. Sometimes the Assembler and Linker are combined into one program so that assembling a source program automatically links it as well. This is the case with the PIC Assembler.
Figure below, shows the different stages in the production of a program. Note that the only stage that requires a lot of user input is the initial production of the user source code file. The rest of the program production involves using the Assembler and Linker tools.
- ‘Filename’ is the name of the program that the user is developing, thus the output of the Editor is the source file ‘filename.asm’.
- The output of the Assembler is the object file ‘filename.obj’.
- The Linker links the ‘filename.obj’ with any Library object files that the program might use. It will also link any user object files that the user might want to include.
- The Linker output is the executable file to run on the target system.
A program called a Loader takes your executable .hex file from the hard disk and loads it onto the target microcontroller. The original source file will contain instructions about where to place the .hex file in the target microcontroller memory. Typically, this instruction will be: ORG 0000H This instruction ORGanises the target program to be loaded to the target microcontroller memory address 0000 hex, ie. at the address 0000 0000 0000 0000 binary. Other key addresses may also be needed, such as the interrupt vector addresses for any interrupt service routines (isr) that the program may use.
Generally, the Loader program is integrated into the development environment so that it is performed by the programmer tools. For example, in the MPLAB PIC development environment, the PICSTART menu will deal with loading the target program into the memory of the EPROM Programmer system which will then program the target microcontroller which has been placed into the zero insertion socket of the programmer system.