Programming Design Tools
Programming Design Tools
Step 1 is driven by the designer, although MPLAB X IDE can help in modeling
circuits and code so that crucial design decisions can be made.MPLAB X IDE
really helps with steps 2 through 4. Its Programmer’s Editor helps write correct
code with the language tools of choice. The editor is aware of the assembler
and compiler programming constructs and automatically “color-keys” the source
code to help ensure it is syntactically correct. The Project Manager enables you
to organize the various files used in your application: source files, processor
description header files and library files. When the code is built, you can control
how rigorously code will be optimized for size or speed by the compiler and
where individual variables and pro-gram data will be programmed into the
device. You can also specify a “memory model” in order to make the best use of
the microcontroller’s memory for your application. If the language tools run into
errors when building the application, the offending line is shown and can be
double clicked to go to the corresponding source file for immediate editing. After
editing, you will rebuild and try your application again. Often this write-compile-
fix loop is done many times for complex code as the sub-sections are written
and tested. MPLAB X IDE goes through this loop with maximum speed,
allowing you to get on to the next step.When the code builds with no errors, it
needs to be tested. MPLAB X IDE has compo-nents called “debuggers” and
free software simulators for all PIC MCU and dsPIC DSC devices to help test
the code. Even if the hardware is not yet finished, you can begin testing the
code with the simulator, a software program that simulates the execution of the
microcontroller. The simulator can accept a simulated input (stimulus), in order
to model how the firmware responds to external signals. The simulator can
measure code execution time, single step through code to watch variables and
peripherals, and trace the code to generate a detailed record of how the
program ran.When the hardware is in a prototype stage, a hardware debugger,
such as an in-circuit emulator or an in-circuit debugger, can be used. These
debug tools run the code in real time on your actual application by using special
circuitry built into many devices with Flash program memory. They can “see
into” the target microcontroller’s program and data memory, and stop and start
program execution, allowing you to test the code with the microcontroller in
place on the application.After the application is running correctly, you can
program a microcontroller with one of Microchip’s devices or development
programmers. These programmers verify that the finished code will run as
designed. MPLAB X IDE supports most PIC MCUs and all dsPIC DSCs.
MPLAB X IDE is a “wrapper” that coordinates all the tools from a single
graphical user interface, usually automatically. For instance, once code is
written, it can be converted to executable instructions and downloaded into a
microcontroller to see how it works. In this process multiple tools are needed:
an editor to write the code, a project manager to organize files and settings, a
compiler or assembler to convert the source code to machine code and some
sort of hardware or software that either connects to a target microcontroller or
simulates the operation of a microcontroller.
1.4PROJECT MANAGER
The project manager organizes the files to be edited and other associated files
so they can be sent to the language tools for assembly or compilation, and
ultimately to a linker. The linker has the task of placing the object code
fragments from the assembler, com-piler and libraries into the proper memory
areas of the embedded controller, and ensure that the modules function with
each other (or are “linked”). This entire operation from assembly and
compilation through the link process is called a project “build”. Properties
specified for the language tools can be invoked differently for each file, if
desired, and a build process integrates all of the language tools’ operations.
The source files are text files that are written conforming to the rules of the
assembler or compiler. The assembler and compiler convert them into
intermediate modules of machine code and placeholders for references to
functions and data storage. The linker resolves these placeholders and
combines all the modules into a file of exe-cutable machine code. The linker
also produces a debug file which allows MPLAB X IDE to relate the executing
machine codes back to the source files.
A text editor is used to write the code. It recognizes the constructs in the text
and uses color coding to identify various elements, such as instruction
mnemonics, C language constructs and comments. The editor supports
operations commonly used in writing source code. After the code is written, the
editor works with the other tools to display code execution in the debugger.
Breakpoints (which stop or “break” the execution of code) can be set in the
editor, and the values of variables can be inspected by hovering the mouse
pointer over the variable name. Names of variables can be dragged from
source text windows and then dropped into a Watches window where their
changing values can be watched after each breakpoint or during code
execution.
1.5LANGUAGE TOOLS
Language tools are programs such as cross-assemblers and cross-compilers.
Most people are familiar with some of the language tools that run on a
computer, e.g., Visual Basic or C compilers. When using language tools for
embedded systems, a “cross-assembler” or “cross-compiler” is used. These
tools differ from typical compilers in that they run on a computer, but they
produce code to run on another microprocessor (or microcontroller).Language
tools also produce a debug file that MPLAB X IDE uses to correlate the
machine instructions and memory locations with the source code. This bit of
integration allows the MPLAB X IDE editor to set breakpoints, allows Watches
windows to view variable contents, and lets you single step through the source
code, while watching the application execute.Embedded system language tools
also differ somewhat from compilers that run and execute on a computer
because they must be very space conscious. The smaller the code produced,
the better, because that provides the smallest possible memory usage for the
target, which reduces cost. This means that techniques to optimize and
enhance the code, using machine-specific knowledge, are desirable. The size
of programs for computers typically extends into the megabytes for moder-ately
complex programs. The size of simple embedded systems programs may be as
small as a thousand bytes or less. A medium size embedded system might
need 32K or 64K of code for relatively complex functions. Some embedded
systems use megabytes of storage for large tables, user text messages or data
logging.
1.6 TARGET DEBUGGING
In a development environment, the execution of the code is tested on a
debugger. The debugger can be a software program that simulates the
operation of the microcontroller for testing, or it can be a hardware instrument to
analyze the program as it executes in the application.
1.6.1Software Debuggers
Simulators are built into MPLAB X IDE so a program can be tested without any
addi-tional hardware. A simulator is a software debugger, and the debugger
functions for the simulator are almost identical to the hardware debuggers,
allowing a new tool to be learned with ease. Usually, a simulator runs
somewhat slower than an actual microcon-troller, since the CPU in the
computer is being used to simulate the operations of the microcontroller.
1.6.2Hardware Debuggers
There are two types of hardware that can be used with MPLAB X IDE:
programmers and hardware debuggers. A programmer simply burns the
machine code from the PC into the internal memory of the target
microcontroller. The microcontroller can then be plugged into the application
and, hopefully, it will run as designed.Usually, however, the code does not
function exactly as anticipated, and the engineer is tasked with reviewing the
code and its operation in the application to determine how to modify the original
source code to make it execute as desired. This process is called debugging.
As noted previously, the simulator can be used to test how the code will
operate, but once a microcontroller is programmed with the firmware, many
things out-side the scope of the simulator come into play. Using just a
programmer, the code could be changed, reprogrammed into the
microcontroller and plugged into the target for retest, but this could be a long,
laborious cycle if the code is complex, and it is difficult to understand exactly
what is going wrong in the hardware.This is where a hardware debugger is
useful. Hardware debuggers can be in-circuit emulators or in-circuit debuggers,
which use microcontrollers that have special built-in debugging features. A
hardware debugger, like a simulator, allows the engineer to inspect variables at
various points in the code, and single step to follow instructions as the hardware
interacts with its specialized circuitry.
1.6.3Integrated Development
EnvironmentDebugging usually becomes urgent near the end of the project
design cycle. As dead-lines loom, getting the application to function as originally
designed is the last step before going into deployment of the product, and often
has the most influence on pro-ducing delays in getting a product out. That’s
where an integrated development envi-ronment is most important. Doing fine
“tweaks” to the code, recompiling, downloading and testing all require time.
Using all tools within a single environment will reduce the time around the
“cycle.” These last steps, where critical bugs are worked out, are a test for the
embedded systems designer. The right tool can save time. With MPLAB X IDE,
many tools can be selected, but they all will have a similar interface, and the
learning curve from simulator to low-cost in-circuit debugger to powerful in-
circuit emulator is small.
UPYCRAFT [2]
Python, a script language that is relatively simple and easy to learn. It is more and more
popular in programming languages. With the support of powerful communities, Python
becomes an ideal language for more and more amateur programmers, especially beginners
to get started.
uPyCraft is an MicroPython programmable IDE that runs in Windows, simply design and
convenient to use. There are many basic libraries were built in uPyCraft IDE itself,
providing a practical platform for MicroPython fans.
When uPyCraft detected the current version is not the latest(e.g. the current version is 0.25,
while the latest version is 0.26), it will suggest to update. Please click “OK” to download
the new one and follow the advice to delete the older one when downloaded.
Directory(leftmost)
To administrate files through different file directories, containing device, sd, uPy_lib,
workSpace and so on.
Users can edit and modify files. The source program editing is generally accomplished at
here. The top of Code Edit shows files opened, right-click one then you can achieve
operations such as editing or executing… Keep the mouse in the file name for a while then
you can check the saving address. Right-click in the Code Edit can copy and paste the file
content.
Terminal(Bottom)
To show state and advice of executed program. If occurs error, it will inform error
information.
Right-click the mouse to choose, then you can copy and paste contents of the terminal.
Menu(uppermost)
To provide basic quick-start operations. For more details, refers to image as below.
Create(please refers to 2.3.2 for details) and name a new file (e.g. test.py). Then you can
edit code in the Code Edit.
Besides, there are many commands in the menu Edit, such as Copy, Cut, Paste, Redo,
Undo, Find, Replace and so on. According to these commands, you can operate the edit
contents more easily. The shortcut keys and quick-start icons has the same effects, shown
as below.
Click quick-start icon after completing code edit can check program syntax (NOTE:
Logic check is not concluded), then printing information could be seen in the terminal. If
the program syntax is alright, it will print “syntax finish”; If syntax errors exist, error
information will be printed, shown as below.
To download files for the development board, there are two types of files, one is the library
files that do not need to be executed, and the other is the files that need to be executed. So
we implement three separate functions: download, execute, download and execute.
Select file to run in the device directory, right-click the mouth to select run.
Download and Run
saving icon ).
NOTE: If you want to run a file when the Code Edit opens more than one files, click the
file label first and download to run.
Stop Execution
Select a menu option Tools→Stop (or click quick-start file-saving icon ) to stop the
executing program.
Now we have already learned how to edit and execute programs in uPyCraft. The next
section will introduce how to use uPyCraft IDE built-in examples.
http://docs.dfrobot.com/upycraft/The%201st%20Chapter%20MicroPython.html