How to start working?
A microcontroller is a good-natured "genie in 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 take a look...
WRITING PROGRAM IN ASSEMBLY LANGUAGE
In order to write a program for the microcontroller, a specialized program in the Windows environment may be used. Any program for text processing can be used for this purpose. The point is to write all instructions in such an 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! When using custom software, there are numerous tools which are also installed to aid in the development process. One such tool is the Simulator. This enables the user to test the code prior to burning it to the MCU.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 PORTBTo enable the 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
The microcontroller does not understand assembly language as such. This 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 the microcontroller perfectly understands. Such documentation is commonly named "hex code" and seemingly represents a 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 D9FAIn case other software for program writing in assembly language is used, special software for compiling the 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 appropriate software. There are several ways to do it.A lot of programs and electronic circuits having this purpose can be found on the 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 an unlimited number of times.
Is this a happy ending?
This section briefly describes the use of MPLAB 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.