Appendix C: Development Systems
How to start working?A microcontroller is a good-natured “giant from the bottle” and no extra knowledge is required to use it.
In order to create a device controlled by the microcontroller, it is necessary to provide the simplest PC, program for compiling and simple device to transfer that code from PC to chip itself.
Even though this process is quite logical, there are often some queries, not because it is complicated, but for numerous variations. Let’s get to the point...
WRITING PROGRAM IN ASSEMBLY LANGUAGE
In order to write a program for the microcontroller, a specialized program in Windows environment may be used. It may, but it does not have to...When using such a software, there are numerous tools which facilitate operation (simulator tool comes first), which is an obvious advantage. But there is also another way to write a program. Basically, text is the only thing that matters. Because of that, any program for text processing can be used for that purpose. The point is to write all instructions in such order they should be executed by the microcontroller, observe the rules of assembly language and write instructions exactly as they are defined. In other words, you just have to follow the program idea! That’s all!
Loop button PORTA,0,0,Increment
button PORTA,1,0,Decrement
goto Loop
Increment incf cnt,f
movf cnt,w
movwf PORTB
goto Loop
Decrement decf cnt,f
movf cnt,w
movwf PORTB
To enable compiler to perform its task successfully, it is necessary that a document containing this program has the extension, .asm in its name, for example: Program.asm
When a specialized program (MPLAB) is used, this extension will be automatically added. If any other program for text processing (Notepad) is used then the document should be saved and renamed. For example: Program.txt -> Program.asm.
Note for lazy ones: skip this procedure, open a new .asm document in MPLAB and simply copy/paste the text of the program written in assembly language.
COMPILING PROGRAM
Microcontroller does not understand assembly language as such. That is why it is necessary to compile the program into machine language. It is more than simple when using a specialized program (MPLAB) because a compiler is part of the software! Just one click on the appropriate icon solves the problem and a new document with .hex extension pops out. It is actually the same program, but compiled into computer language which microcontroller perfectly understands. Such document is commonly named “hex code” and represents seemingly meaningless sequence of numbers in hexadecimal numerical system.
:03000000020100FA1001000075813F 7590FFB29012010D80F97A1479D40 90110003278589EAF3698E8EB25B A585FEA2569AD96E6D8FED9FAD AF6DD00000001FF255AFED589EA F3698E8EB25BA585FEA2569AD96 DAC59700D00000278E6D8FED9FA DAF6DD00000001FF255AFED8FED 9FADAF6DD000F7590FFB29013278 E6D8FED9FADAF6DD00000001FF2 55AFED589EAF3698E8EB25BA585 FEA2569AD96DAC59D9FADAF6D D00000001FF255AFED8FED9FADA F6DD000F7590FFB29013278E6D82 78E6D8FED9FA589EAF3698E8EB2 5BA585FEA2569AD96DAF6DD000 00001FF2DAF6DD00000001FF255A ADAF6DD00000001FF255AFED8FE D9FA
In case some other software for program writing in assembly language is used, a special software for compiling program must be installed and used as follows: set up the compiler, open the document with .asm extension and compile. The result is the same- a new document with .hex extension. The only problem you have now is that it is stored in your PC.
PROGRAMMING A MICROCONTROLLER
To enable “hex code” transmission to the microcontroller it is necessary to provide a cable for serial communication and a special device called programmer with appropiate software. There are several ways to do it.
A lot of programs and electronic circuits having that purpose can be found on Internet. Do as follows: open hex code document, set a few parameters and click the icon for compiling. After a while, a sequence of zeros and ones is to be programmed into the microcontroller through the serial connection cable and programmer hardware. There is nothing else to be done except for placing the programmed chip into the target device. In case it is necessary to make some changes in the program, the previous procedure may be repeated unlimited number of times.
Is this a happy ending?This section briefly describes the use of MPLAB program and programmer software developed by Mikroelektronika. Everything is very simple...
You have already installed MPLAB, haven’t you? Open a new project and a new document with extension.asm.
OK. You have written a program and tested it by means of simulator. Program did not report any error during compiling process? It seems that everything is under control...
Program is written and successfully compiled. It is only left over to program the microcontroller. For this purpose it is necessary to have programmer and software intervening between PC and programmer hardware ( PIC Flash for example). Start up this program...
Settings are simple and there is no need for additional explanations (type of the microcontroller, frequency and clock oscillator etc.).
- Connect PC and programmer via USB cable
- Load HEX code using command: File -> Load HEX
- Click the “Write” push-button and wait...
That’s all! The microcontroller is programmed and everything is ready for the operation. If you are not satisfied, make some changes in the program and repeat the procedure. Until when? Until you feel satisfied...
Development systems
A device which in testing program phase can simulate any device is called development system. Apart from the programmer, the power supply unit and the microcontroller’s socket, the development system contains also elements for input pins activation and output pins monitoring. The simplest version has every pin connected to one push-button and one LED as well. High quality version has LED displays, LCD displays, temperature sensors and all other elements which the target device can be supplied with. These peripherals could be connected to MCU via miniature jumpers. In that way, the whole program may be tested in practice during its writing because the microcontroller does not know whether its input is activated by a push-button or a sensor built in a real machine.

