0% found this document useful (0 votes)
12 views

ProgramingaMicrocontroller IJCA

Uploaded by

leer20848
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

ProgramingaMicrocontroller IJCA

Uploaded by

leer20848
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/311669390

Programming a Microcontroller

Article in International Journal of Computer Applications · December 2016


DOI: 10.5120/ijca2016912310

CITATIONS READS

12 20,915

4 authors, including:

Altaf Hussain Muhammad Hamad


Institute of Space Technology National University of Sciences and Technology
51 PUBLICATIONS 188 CITATIONS 27 PUBLICATIONS 12 CITATIONS

SEE PROFILE SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Code Generating Tools View project

Load Balancing in Cloud Computing View project

All content following this page was uploaded by Altaf Hussain on 17 December 2016.

The user has requested enhancement of the downloaded file.


International Journal of Computer Applications (0975 – 8887)
Volume 155 – No 1, December 2016

Programming a Microcontroller

Altaf Hussain Muhammad Hammad Kamran Hafeez


Computer Science Department Computer Science Department Computer Science Department
KICSIT, Rawalpindi KICSIT, Rawalpindi KICSIT, Rawalpindi
UET Taxila, Pakistan UET Taxila, Pakistan UET Taxila, Pakistan
[email protected] [email protected] [email protected]

Tabinda Zainab
Computer Science Department
KICSIT, Rawalpindi
UET Taxila, Pakistan
[email protected]

ABSTRACT devices from all aspect of life. Any device that measures,
Microcontroller is a computer on single integrated circuit that stores, controls, calculates, or displays information is a
includes a CPU, RAM, some form of ROM, and I/O ports. It candidate for putting a microcontroller inside [1]. The largest
has great impact in our life which cannot be ignored. Unlike a use for microcontrollers is in automobiles; just about every
general purpose computer, microcontrollers are dedicated to car manufactured today includes at least one microcontroller
perform a specified task and execute single application. for engine control, and often more to control additional
Automatically controlled products like automatic engine systems in the car. In desktop computers, you can find
control systems, remote controls, power tools, toys, and office microcontrollers inside keyboards, modems, printers, and
machines i.e. photo-copier, printer, and fax machines which other peripherals. Similarly, Consumer products that use
are used commonly; are being programmed using microcontrollers include cameras, video recorders, compact-
microcontroller. Any person working in the field of disk players, and ovens etc. but these are just a few examples.
electronics has the knowledge to use a microcontroller but not A microcontroller is similar to the microprocessor inside a
necessarily be having good programming skills for it. While personal computer [1]. To make a complete computer,
programing for a microcontroller, one has to interact with a microprocessor requires memory for storing data and
different software tools i.e. Proteus for making circuit programs, and input/output (I/O) interfaces for connecting
diagram, mikroC PRO for source coding, and QL-PROGen external devices like keyboards and displays. In contrast, a
for burning hex file in microcontroller. So it is really a tough microcontroller is a single-chip computer because it contains
task to program a microcontroller for such persons. Our work memory and I/O interfaces in addition to the CPU. Because
aims to extend the automatic programmer tool [1] that the amount of memory and interfaces that can fit on a single
generates mikroC code and its hex file from a block diagram. chip is limited, microcontrollers tend to be used in smaller
This enhanced tool provides an integrated platform that allows systems. Examples of popular microcontrollers are Intel’s
the user to design circuit diagram, generate its code, and burn 8052, Motorola’s 68HC11, and Zilog’s Z8.
the hex file directly into the microcontroller. It provides a set In 1971, the first microcontroller was invented by two
of blocks for business logics; that are used to build an engineers at Texas Instruments, according to the Smithsonian
algorithm of application as an input for source code Institution. Gary Boone and Michael Cochran created the
generation. In addition, it provides the feature to compile the TMS 1000, which was a 4-bit microcontroller with built-in
generated code and then to burn the hex file directly into the ROM and RAM. The microcontroller was used internally at
chip. The microcontrollers used in this tool are PIC18F442, TI in its calculator products from 1972 until 1974, and was
PIC18F4520, and PIC18F542; placed in the middle of Circuit refined over the years. In 1974, TI offered the TMS 1000 for
Diagram Window of this tool. sale to the electronics industry [8]. In addition, Intel also
developed many important microcontrollers, two of which are
General Terms the 8048 and 8051. The 8048 was one of Intel's first
PIC programmer. microcontrollers introduced in 1976 and was used as the
processor in the IBM personal computer keyboard. The 8051
Keywords followed in 1980 and became one of the most popular
Microcontroller, PIC18f452, hex file generator, graphical microcontroller families. Variations of the 8051 architecture
block, OpenBlocks for microcontrollers. are still being produced today, making the 8051 one of the
most long-lived electronics designs in history [8].
1. INTRODUCTION
A microcontroller is a computer-on-a-chip, or, it may be During the 1990s, microcontrollers with electrically erasable
considered as a single-chip computer. Micro means a small and programmable ROM (EEPROM) memories, such as flash
device, and controller identifies it as a device to control memory, became available. These microcontrollers could be
objects, processes, or events. An alternate term used for it is programmed, erased and reprogrammed using only electrical
embedded controller, because the microcontroller and its signals. Prior to the electrically reprogrammable devices,
support circuits are often built into, or embedded in, the microcontrollers often required specialized programming and
devices they control. Microcontrollers are usually used in erasing hardware, which required that the device be removed

1
International Journal of Computer Applications (0975 – 8887)
Volume 155 – No 1, December 2016

from its circuit, slowing software development and making that contains a database of components, which we can use to
the effort more expensive. Overcoming this limitation, build the circuit. The components to be used are available in
microcontrollers were able to be programmed and the component library.
reprogrammed while in a circuit so devices with
microcontrollers could be upgraded with new software
without having to be returned to the manufacturer. Many
current microcontrollers, such as those available from
Microchip and Atmel, incorporate flash memory technology.
In addition to general purpose devices, specialized
microcontrollers are being produced for areas such as
automotive, lighting, communications and low-power
consumer devices. Microcontrollers have also become smaller
and more powerful. For example, in 2010, Atmel announced a
flash microcontroller in a package measuring 2 mm by 2 mm.
These tiny microcontrollers are small enough and cheap
enough to be used in products such as toys and toothbrushes
[8].
Fig. 1: Proteus: A Software for circuit designing
On such a demanding use of microcontrollers, the need of
writing code for the microcontrollers is becoming an 2.1.2 Programming a Microcontroller
important task. To make this task easier, we have introduced A microcontroller does not know what to do by itself. So in
the initial version of automatic programmer [4]. Automatic step-2, it is the responsibility of programmer to write a code
Programmer is a software tool that allows the user to generate for microcontroller. The compiler used for this purpose is
mikroC code for microcontroller PIC after creating his/her microC PRO or MP-Lab. After writing the code, it is
desired block diagram; then it generates the Hex file of the compiled for respective microcontroller in the form of a hex
following code. A block diagram is basically a group of file.
properly interconnected blocks, with each interconnected
block representing and describing a portion of the system. The
block diagram is very simple to construct also for complicated
system. The function of individual element as well as overall
performance of the system can be plotted/ studied from the
block diagram. Due to their simplicity and versatility, block
diagrams are widely used by control engineers to model all
types of dynamic systems [5]. For the verification of the
respective generated mikroC code, the Proteus Software is
being used in Automatic Programmer. In this work we have
enhanced the automatic programmer as explained in Section
4.
The remainder of this paper is organized as follows: Section 2
gives a detail of programming for microcontroller. Section 3
describes the automatic programmer [4]. Section 4 presents Fig. 2: mikroC PRO: C Compiler for PIC
enhancements of automatic programmer and the use of this
extension. While Section 5 presents a calculator case study 2.1.3 Burning hex file
using enhanced automatic programmer. Section 6 presents the The code loading process of microcontroller is called
Conclusion of this work. dumping. The microcontrollers understand only the machine
level language, which contains ‘0s or 1s’. So we need to load
2. EXISTING SYSTEM the hex code into the microcontroller. There are many
software tools available for loading the code to the
2.1 Using a Microcontroller microcontroller e.g. QL-PROGen or PICFLSH [3].
Normally, when we use microcontroller for making some
application there are at least 3 steps to follow, first of all
design the circuit, write C code for it and generate hex file,
and to burn this hex file into the microcontroller. For each
step to complete, we have to use separate software. The steps
are discussed here.

2.1.1 Circuit Designing


Usually in step-1, the circuit is designed with the help of
Proteus software. Proteus developed by Lab center Electronics
Ltd. was founded in 1988. The Proteus Design Suite is wholly
unique in offering the ability to co-simulate both high and low
level microcontroller codes in the context of a mixed-mode
SPICE circuit simulation. SPICE (Simulation Program with
Integrated Circuit Emphasis) is a general-purpose, open
source analog electronic circuit simulator. Proteus’s Virtual Fig. 3: PicFlash: Software used for dumping
System Modeling (SVM) has microcontroller programming
tool, environment, with its many software features and
hardware options [9].Proteus is a circuit designing software

2
International Journal of Computer Applications (0975 – 8887)
Volume 155 – No 1, December 2016

3. AUTOMATIC PROGRAMMER [4] QL-PROGEN is also integrated for burning code into the
To make this task easier, a software tool has been introduced microcontroller.
by Hussain et al. in the form of Automatic Programmer [4]. It EAP has a visual interface comprised of 1) Component
was a software tool that allows the user to generate mikroC Toolbox, 2) Circuit Diagram Window containing
code for P*IC microcontroller after creating the desired circuit microcontroller, 3) Display Code Window used for displaying
diagram; then it generates the hex file on compilation. Its generated code and 4) Make Flow Window. User can make
circuit diagram using components provided in the component
benefit was to automatically generate configuration code i.e.
toolbox. The available set of components are LED, LCD- 8bit,
setting of direction register, and user does not have to write Keypad, Stepper motor, and seven segment. The
code to set direction registers and the hex file is also created. microcontrollers used in our software tool are PIC18F442,
PIC18F4520, and PIC18F542 and it is already placed on the
As discussed earlier, the user has to use three different Circuit Diagram Window.
software tools for circuit designing, programming the chip,
After creating the circuit diagram, the user has to make
and burning hex file onto the chip. Using Automatic connections between components and microcontroller. Then
Programmer, the user can design the circuit and generate the properties of components are set. On plotting the desired
configuration code but there was no mechanism of providing circuit diagram, the configuration code is generated for it as
business logic of application that has been introduced in shown on the screen in the Display Code Window. Initially
enhanced automatic programmer. In addition, automatic user has to create project directory where generated source
programmer did not provide the mechanism for burning the code is saved as “.c file” with another file named as “.mcppi”
which contain configuration setting. These two files are
hex file onto the chip and user has to use separate software for
required for compilation. First the user has to select the PIC
it. microcontroller type (PIC18F442, PIC18F452, or
PIC18F4520) and then sets its frequency and the project is
4. ENHANCED PROGRAMMER saved with a specific name. After making circuit diagram user
Enhanced Automatic Programmer (EAP) is an extension to will provide the input algorithm by joining blocks provided in
previously designed software named as Automatic the toolbox and click on update code and this business logic
Programmer. EAP is an integrated platform for designing and configuration code will be merged.
circuit diagram, setting configurations of components (i.e.
setting direction registers by mouse click without writing 4.2 Using Enhanced Programmer
code), making block diagram in which user will provide Using “Create Project” option in the File menu, new window
algorithm of his functionality by joining blocks, burn/load will appear that will help the user to create new project
directly this hex file into the microcontroller. directory. On project creation, the main window appears with
microcontroller placed on the middle of it. This main window
A block diagram is a group of properly interconnected blocks, has component toolbox on the left side. This toolbox
and each block represents a portion of the system. The block comprises of components as discussed earlier in section-IV
diagram is very simple even to construct for complicated for constructing a circuit diagram. Right side of the main
system. The function of individual element as well as overall window shows a working area that contains a microcontroller
performance of the system can be plotted/studied from the on it and other components are needed to be added from the
block diagram. Due to the simplicity and versatility, block toolbox as per requirement of input algorithm. Using drag and
diagrams are widely used by control engineers to model all drop, the user can place any of desired components from the
types of dynamic systems [5]. For the verification of the provided toolbox to working area. Three options appeared on
generated micro C code, the same circuit is designed in the right click on any of the components that are: 1) Delete
Proteus software and the generated code is loaded inside the component 2) Drag component 3) Set component property.
microcontroller to simulate. Proteus developed by Labcenter With set component property option user can set properties of
Electronics Ltd. was founded in 1988. The Proteus Design respective component e.g. to set LED port and pin.
Suite is wholly unique in offering the ability to co-simulate
both high and low level microcontroller codes in the context When all components are configured then the basic code is
of a mixed-mode SPICE circuit simulation. SPICE generated by using Generate code button on top of menu bar.
(Simulation Program with Integrated Circuit Emphasis) is a This is basic configuration code generated for devices
general-purpose, open source analog electronic circuit attached to microcontroller. User can view generated code in
simulator. Proteus’s Virtual System Modeling (SVM) has code tab view. Now user has to make logical flow diagram by
microcontroller programming tool, environment, with its using open Make flow diagram window from code tab view.
many software features and hardware options [6]. This new window has Component toolbox which contains
block design of conditional statements, logical statements,
4.1 Enhanced Programmer Development logical operators and block design of functions like
It is developed in NetBeans using Java. OpenBlocks is used in “getselectedkey” function used to get keypad selected key,
designing the interface with which user can make block “writeonlcd” function used for writing content on LCD etc.
diagram of the input algorithm. OpenBlocks is an open source After creating flow diagram click on update code that will
java library used for creating block based programming UIs. generate logical code and merge it with configuration code to
OpenBlocks consists of two packages: codeblocks and make complete final source code.
slcodeblocks. Codeblocks is the basic underlying library that
In order to compile this source code, compilation button from
is responsible for most of the functionality [7]. Mikro C Pro
menu bar is used that produced .hex file. At the end, button
commands are used for verification and compilation of source
named “burn code” from menu bar will open a new window.
code generated by this software. Hex file generated as output
This will ask required information and took .hex file as input
of compilation is further used for burring into microcontroller.
to burn it in microcontroller.

3
International Journal of Computer Applications (0975 – 8887)
Volume 155 – No 1, December 2016

5. CALCULATOR CASE STUDY iskeypadclicked, keypad. getclickedkey, LCD clear, display


Create Project directory from “Create Project” option in the on LCD etc. Now start making flow against the calculator
File menu. Create Project window will appear, save it with in algorithm on view port. The algorithm used for calculator is
project folder. Both the project and its folder is named as explained in Fig. 7.
“Calculator”. Now select device name “PIC18F452” from
dropdown list and enter device clock 20 Mhz and click create
button that will successfully create project directory as shown
in Fig. 4.

Fig. 6: Configuration Code Window

In the figures 8, 9, 10, 11, and 12, the algorithm in Fig. 7 has
Figure 4: Create Project Window been implemented by using respective blocks. In the Fig. 13,
hex file of code is generated that will be loaded into
Now first, make a block diagram for calculator by using LCD
microcontroller using this tool and calculator will be ready to
and keypad. Drag LCD and keypad from list to viewport and
use.
set their properties to make connections with microcontroller.
Keypad is connected at port B. Data ports of LCD is
connected at port C and RS bit of LCD at bit 0 of port D and
E bit at bit 1 of port D as shown in Fig. 5.

Fig. 5: Designing Ciruite Block Diagram

After making connections with microcontroller, use “generate


code” button for producing basic configuration code.
Configuration code refers to set the direction registers to set as
input or output and for keypad it will generate the method to
find the key pressed we will simply call this function and can
get the value of key clicked. LCD will also be initialized in
configuration code as shown in Fig. 6.
Now click on make flow button in the code tab and another
window will be opened that will help you to make flow of
calculator i.e. to provide algorithm stated earlier in the
software. For making flow of algorithms using blocks we
have used an open source library openblocks in our software. Figure 7: Algorithm for Calculator
As we can see there are six different tabs (Control,
components, logic operators, number, utilities) on left hand
side of screen .Control tab contains conditional statements (if,
if else) and loops (for, while), Components tab contains helper
methods for hardware components like led on, led off, rotate
stepper clockwise, rotate stepper anti-clockwise,

4
International Journal of Computer Applications (0975 – 8887)
Volume 155 – No 1, December 2016

Figure 12: Calculator Algorithm - Part-04


Fig. 8: Make Flow Window

Figure 13: Generate Hex File

6. CONCLUSION
This work is the extension of automatic programmer to
provide a friendlier and integrated platform for providing the
solution of creating source code for microcontroller from
block diagram. The extension to the tool comprise of
introducing new components, generation of configuration
Fig. 9: Calculator Algorithm - Part-01 code and the actual source code. In addition, QL-PROGen is
integrated to burn the created hex file in the microcontroller
and the same can be pre-simulated within this enhanced tool.

7. REFERENCES
[1] Axelson, J. (1994). The Microcontroller Idea Book.
2008.
[2] Verle, M. (2009). PIC Microcontrollers Programming in
C: A Complete Guide to Pic Microcontrollers.
MikroElektronika.
[3] How to Program a PIC Microcontroller to Build a Project
[online], Avail-able: https://www.elprocus.com/pic-
microcontroller-programming-using-c-language/
[4] Hussain, A., Riaz, M. A., ul Abdin, Z., & Saeed, A.
(2015, December). Automatic programmer: A software
tool. In Emerging Technologies (ICET), 2015
International Conference on (pp. 1-5). IEEE.
Fig. 10: Calculator Algorithm - Part-02 [5] Maxwell, J. C. (1954). A Treatise on Electricity and
Magnetism Dover Publications. Unabriged Third
Edition, Volume one.
[6] A refactoring branch of MIT OpenBlocks. [online],
Available: http://web.mit.edu/mitstep/openblocks.html
[7] Mei, C. (2002). On teaching the simplification of block
diagrams. International Journal of Engineering
Education, 18(6), 697-703.
[8] Padgavhankar, A. V., & Mohod, S. W. (2014).
Experimental Learning of Digital Power Controller for
Photovoltaic Module Using Proteus VSM. Journal of
Fig. 11: Calculator Algorithm - Part-03 Solar Energy, 2014.

View publication stats

You might also like