Файл: Introduction to PIC Microcontrollers (Complete Guide to PIC).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 1208
Скачиваний: 0
Chapter 5 - MPLAB
5.2 MPLAB
Following the installment procedure, you will get a screen of the program itself. As you can see, MPLAB looks like most of the Windows programs. Near working area there is a "menu" (upper blue colored area with options File, Edit..etc.), "toolbar" (an area with illustrations the size of small squares), and status line on the bottom of the window. There is a rule in Windows of taking some of the most frequently used program options and placing them below the menu, too. Thus we can access them easier and speed up the work. In other words, what you have in the toolbar you also have in the menu.
http://www.mikroelektronika.co.yu/english/books/5_02Poglavlje.htm (1 of 2) [30/12/2001 16:54:02]
Chapter 5 - MPLAB
The screen after starting the MPLAB
The purpose of this chapter is for you to become familiar with MPLAB developing environment and with basic elements of MPLAB such as:
Choosing a developing mode Designing a project
Designing a file for the original program
Writing an elementary program in assembler program language Translating a program into executive code
Starting the program
Opening a new window for a simulator
Opening a new window for variables whose values we watch (Watch Window) !saving a window with variables whose values we are watching
Setting the break points in a simulator (Break point)
Preparing a program to be read in a microcontroller can boil down to several basic steps:
© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.
http://www.mikroelektronika.co.yu/english/books/5_02Poglavlje.htm (2 of 2) [30/12/2001 16:54:02]
Chapter 5 - MPLAB
5.3 Choosing the development mode
Setting a developing mode is necessary so that MPLAB can know what tools will be used to execute the written program. In our case, we need to set up the simulator as a tool that's being used. By clicking on OPTIONS---> DEVELOPMENT MODE, a new window will appear as in the picture below:
Setting a developing mode
We should select the 'MPLAB-SIM Simulator' option because that is where the program will be tried out. Beside this option, the 'Editor Only' option is also available. This option is used only if we want to write a program and using a programmer write' hex file' in a microcontroller. Selection of the microcontroller model is done on the right hand side. Since this book is based on the PIC16F84, this model should be selected.
Ordinarily when we start working with microcontrollers, we use a simulator. As the level of knowledge increases, program can be written in a microcontroller right after translation. Our advice is that you always use the simulator. Though program will seem to develop slower, it will pay off in the end.
http://www.mikroelektronika.co.yu/english/books/5_03Poglavlje.htm (1 of 2) [30/12/2001 16:54:04]
Chapter 5 - MPLAB
© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.
http://www.mikroelektronika.co.yu/english/books/5_03Poglavlje.htm (2 of 2) [30/12/2001 16:54:04]
Chapter 5 - MPLAB
5.4 Designing a project
In order to start writing a program you need to create a project first. By clicking on PROJECT --> NEW PROJECT you are able to name your project and store it in a directory of your choice. In the picture below, a project named 'proba.pjt' is being created and stored in c:\PIC\PROJEKTI\ directory.
This directory is chosen because authors had such directory set up of on their computer. Generally speaking, directory with files is usually placed in a larger directory whose name is unmistakably associated with its contents.
Opening a new project
After naming the project, click on OK. New window comes up as in the next picture.
http://www.mikroelektronika.co.yu/english/books/5_04Poglavlje.htm (1 of 6) [30/12/2001 16:54:07]
Chapter 5 - MPLAB
Adjusting project elements
Using a mouse click on "proba [.hex]" which activates 'Node properties' option in the bottom right corner of a window. By clicking on it you get the following window.
http://www.mikroelektronika.co.yu/english/books/5_04Poglavlje.htm (2 of 6) [30/12/2001 16:54:07]
Chapter 5 - MPLAB
Defining parameters of MPASM assembler
From the picture we see that there are many different parameters. Each kind corresponds to one parameter in "Command line" term. As memorizing these parameters is very uncomfortable, even forbidding for beginners, graphic adjustment has been introduced. From the picture we see which options need to be turned on. By clicking on OK we go back to previous window where "Add node" is an active option. By clicking on it we get the following window where we name our assembler program. Let's name it "Proba.asm" since this is our first program in MPLAB.
http://www.mikroelektronika.co.yu/english/books/5_04Poglavlje.htm (3 of 6) [30/12/2001 16:54:07]
Chapter 5 - MPLAB
Opening a new project
By clicking on OK we go back to the starting window where we see added an assembler file.
http://www.mikroelektronika.co.yu/english/books/5_04Poglavlje.htm (4 of 6) [30/12/2001 16:54:07]
Chapter 5 - MPLAB
Assembler file added
By clicking on OK we return to MPLAB environment.
http://www.mikroelektronika.co.yu/english/books/5_04Poglavlje.htm (5 of 6) [30/12/2001 16:54:07]
Chapter 5 - MPLAB
© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.
http://www.mikroelektronika.co.yu/english/books/5_04Poglavlje.htm (6 of 6) [30/12/2001 16:54:07]
Chapter 5 - MPLAB
5.5 Designing a new assembler file (writing a new program)
When "project" part of the work is finished, we need to start writing a program. In other words, new file must be opened, and will be named "proba.asm". In our case, file has to be named "proba.asm" because in projects which have only one file (such as ours), name of the project and name of the original file have to be the same.
New file is opened by clicking on FILE>NEW. Thus we get a text window inside MPLAB work space.
http://www.mikroelektronika.co.yu/english/books/5_05Poglavlje.htm (1 of 2) [30/12/2001 16:54:09]
Chapter 5 - MPLAB
New assembler file opened
New window represents a file where program will be written. Since our assembler file has to be named "proba.asm", we will name it so. Naming is done (as with all Windows programs) by clicking on FILE>SAVE AS. Then we get a window like the following picture.
Naming and saving a new assembler file
When we get this window, we need to write 'proba.asm' below 'File name:', and click on OK. After that, we will see 'proba.asm' file name at the top of our window.
© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.
http://www.mikroelektronika.co.yu/english/books/5_05Poglavlje.htm (2 of 2) [30/12/2001 16:54:09]
Chapter 5 - MPLAB
5.6 Writing a program
Only after all of the preceding operations have been completed can we start writing a program. Since a simple program has already been written in "Assembly Language Programming" section of the book, so we will use that same program here, too.
Chapter 5 - MPLAB
Program has to be copied to a window that's opened, or copied from a disc, or taken from MikroElektronika Internet presentation using options copy and paste. When the program is copied to "proba.asm" window, we can use PROJECT -> BUILD ALL command (if there were no errors), and a new window will appear as in the next picture.
Window with messages following a translation of assembler program
We can see from the picture that we get "proba.hex" file as a result of translation process, that MPASMWIN program is used for translation, and that there is one message. In all that information, the last sentence in the window is the most important one because it shows whether translation was successful or not. 'Build completed successfully' is a message stating that translation was successful and that there were no errors.
In case an error shows up, we need to double click on error message in 'Build Results' window. This will automatically transfers you to assembler program and to the line where the error is.
http://www.mikroelektronika.co.yu/english/books/5_06Poglavlje.htm (2 of 3) [30/12/2001 16:54:11]
Chapter 5 - MPLAB
© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.
http://www.mikroelektronika.co.yu/english/books/5_06Poglavlje.htm (3 of 3) [30/12/2001 16:54:11]
Chapter 5 - MPLAB
5.7 MPSIM Simulator
Simulator is part of MPLAB environment which provides a better insight into the workings of a microcontroller. With the help of a simulator, we can watch current variable values, register values and status of port pins. Truthfully, simulator does not have the same value in all programs. If a program is simple (like the one given here as an example), simulation is not of great importance because setting port B pins to logic one is not a difficult task. However, simulator can be of great help with more complicated programs which include timers, different conditions where something happens and other similar requirements (especially with mathematical operations). Simulation, as the name indicates "simulates the work of a microcontroller". As microcontroller executes instructions one by one, simulator is conceived - programmer moves through a program step by step (line by line) and follows what goes on with data within a microcontroller. When writing is completed, it is a good trait if programmer first checks his program in a simulator, and then tries it out in a real situation. Unfortunately, as with many other good habits, man avoids this one too, more or less. Reasons for this are partly personality, and partly lack of good simulators.
First thing we need to do, as we would in a real situation, is to reset a microcontroller with DEBUG > RUN > RESET command. This command results in bold line positioned at the beginning of a program, and program counter is positioned at zero which can be seen in status line (pc: 0x00).
http://www.mikroelektronika.co.yu/english/books/5_07Poglavlje.htm (1 of 4) [30/12/2001 16:54:14]
Chapter 5 - MPLAB
Beginning of program simulation, resetting a microcontroller
One of the main characteristics of a simulator is the ability to view register status within a microcontroller. These registers are also called special function registers, or SFR registers. We can get a window with SFR registers by clicking on WINDOW->SPECIAL FUNCTION REGISTERS, or on SFR icon.
Beside SFR registers, it is useful to have an insight into file registers. Window with file registers can be opened by clicking on WINDOW->FILE REGISTERS.
If there are variables in the program, it is good to watch them, too. To each variable is assigned one window (Watch Windows) by clicking on WINDOW->WATCH WINDOWS.
http://www.mikroelektronika.co.yu/english/books/5_07Poglavlje.htm (2 of 4) [30/12/2001 16:54:14]
Chapter 5 - MPLAB
Simulator with open windows for SFR registers, file registers and variables.
The next command in a simulator is DEBUG>RUN>STEP which starts our movement through the program. The same command could have been assigned from a keyboard with <F7> key (generally speaking, all significant commands have keys assigned on the keyboard).
By using the F7 key, program is executed step by step. When we get to a macro, file containing a macro is opened (Bank.inc), and we proceed to go through a macro. In a SFR registers window we can observe how W register receives value 0xFF and delivers it to port B. By clicking on F7 key again, we don't achieve anything because program has arrived to an "infinite loop". Infinite loop is a term we will meet often. It represents a loop from which a microcontroller can not get out until interrupt occurs (if it is used in a program), or until a microcontroller is reset.
http://www.mikroelektronika.co.yu/english/books/5_07Poglavlje.htm (3 of 4) [30/12/2001 16:54:14]
Chapter 5 - MPLAB
© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.
http://www.mikroelektronika.co.yu/english/books/5_07Poglavlje.htm (4 of 4) [30/12/2001 16:54:14]