EMBEDDED C TUTORIAL.
TIMOTHY ADEGBITE
Welcome
to the today’s Trinnex electronics tutorial on embedded C. In this tutorial, I
will be explaining the microcontroller. Its internal configuration and how it
functions.
Circumstances that we find ourselves in today's in the field
of microcontrollers had their beginnings in the development of technology of
integrated circuits. This development has made it possible to store hundreds of
thousands of transistors into one chip. That was a prerequisite for production
of microprocessors, and the first computers were made by adding external
peripherals such as memory, input-output lines, timers and other. Further
increasing of the volume of the package resulted in creation of integrated
circuits. These integrated circuits contained both processor and peripherals.
That is how the first chip containing a microcomputer, or what would later be
known as a microcontroller came about.
It was year 1969, and a team of Japanese engineers from the
BUSICOM Company arrived to United States with a request that a few integrated
circuits for calculators be made using their projects. The proposition was set
to INTEL, and Marcian Hoff was responsible for the project. Since he was the
one who has had experience in working with a computer (PC) PDP8, it occurred to
him to suggest a fundamentally different solution instead of the suggested
construction. This solution presumed that the function of the integrated
circuit is determined by a program stored in it. That meant that configuration
would be simpler, but that it would require far more memory than the project
that was proposed by Japanese engineers would require. After a while, though
Japanese engineers tried finding an easier solution, Marcian's idea won, and
the first microprocessor was born. In transforming an idea into a ready-made
product, Frederico Faggin was a major help to INTEL. He transferred to INTEL,
and in only 9 months had succeeded in making a product from its first
conception. INTEL obtained the rights to sell this integral block in 1971.
First, they bought the license from the BUSICOM Company who had no idea what
treasure they had. During that year, there appeared on the market a
microprocessor called 4004. That was the first 4-bit microprocessor with the
speed of 6 000 operations per second. Not long after that, American company CTC
requested from INTEL and Texas Instruments to make an 8-bit microprocessor for
use in terminals. Even though CTC gave up this idea in the end, Intel and Texas
Instruments kept working on the microprocessor and in April of 1972, first
8-bit microprocessor appeared on the market under a name 8008. It was able to
address 16Kb of memory, and it had 45 instructions and the speed of 300 000
operations per second. That microprocessor was the predecessor of all today's
microprocessors. Intel kept their developments up in April of 1974, and they
put on the market the 8-bit processor under a name 8080 which was able to
address 64Kb of memory, and which had 75 instructions, and the price began at
$360.
That is just a breve introduction to the
microcontroller.
Let’s see the similarity and difference between a
microcontroller and a microprocessor.
Microcontrollers versus Microprocessors.
Microcontroller differs from a microprocessor in many ways.
First and the most important is its functionality. In order for a
microprocessor to be used, other components such as memory, or components for
receiving and sending data must be added to it. That means that microprocessor
is the very core of the computer. In contrast, microcontroller is designed to
be all of that in one. No other external components are needed for its
application because all vital and necessary peripherals are already built into
it at the point of manufacturing. Thus, time and space needed to construct devices
are been saved.
The
target pic microcontroller we be using in this tutorial is PIC16F84A.
The Microcontroller Program memory.
The Microcontroller Program memory.
In
the microcontroller the program written is stored in the (Electrically
Programmable Read Only Memory) EPROM, this memory is non-volatile and it is
always remembered when the power is switched off.
By
means of a hardware called a programmer, the EPROM is electrically programmed.
The
instructions programmed into the microcontroller work by moving and manipulating
data in memory locations known as user files and registers.
This
memory is called RAM, Random Access Memory.
PIC
Microcontrollers 16F84A is an 8 bit micros, which means that the memory
locations,
The
user files and registers are made up of 8 binary digits. What does this
means? It means that the maximum value
each file can contain, either a user defined register or a special function
register, cannot go beyond 256. If you convert 8-bit into a decimal number, you
get 256. We will do more of that as the tutorial goes on.
I
mentioned earlier, user defined register/file and special function
register/file. What does this means? User defined register (UDR) are the
register, that can be given any name and used for any purpose. While special function register (SFR) are the
register that is solely owned by the microcontroller. Their names cannot be
changed. They are files through which the microcontroller communicates to the
outside world and vice versa. Examples
of SFR are the PORTA, PORTB, STATUS FILE, ADCON0, ADCON1 etc.
Below shows the memory map of the PIC16F84A.
What does the memory map means? It is a table that shows the location, position
and bank of any file of the micro.
16F84 memory map.
PORTA,
PORTB, TMR0 etc. in addresses 00 to 0B contain the special function register and
the location of the User Files occupies locations 0C through to 4F. These files
are very important when writing our code. The Special Function Registers enable
us to tell the microcontroller to do things, i.e. set PORTB up as an output
port with TRISB, alter the rate of TMR0 with the OPTION register, while the
user register is used for our own purposes.
FILE
ADDRESS
|
FILE
NAME
|
FILE
NAME
|
FILE
ADDRESS
|
00H
|
INDIRET
ADDRESS
|
INDIRECT
ADDRESS
|
80H
|
01H
|
TMR0
|
OPTION_REG
|
81H
|
02H
|
PCL
|
PCL
|
82H
|
03H
|
STATUS
|
STATUS
|
83H
|
04H
|
FSR
|
FSR
|
84H
|
05H
|
PORTA
|
TRISA
|
85H
|
06H
|
PORTB
|
TRISB
|
86H
|
07H
|
---
|
---
|
87H
|
08H
|
EEDATA
|
EECON1
|
88H
|
09H
|
EEADR
|
EECON2
|
89H
|
0AH
|
PCLATH
|
PCLATH
|
8AH
|
0BH
|
INTCON
|
INTCON
|
8BH
|
0CH
4FH
|
68 GENERAL
PURPOSE
REGISTERS
(SRAM)
|
Mapped (accesses)
in Bank 0
|
8CH
CFH
|
BANK 0
|
BANK 1
|
PIC 16F84A MEMORY MAP.
What
your program does in essence is to move values from one file to another. Either
a user file or a special function register.
This
is achieved by the controls statement written as a program.
With
all that is explained here, we are good to go into the programming a
microcontroller.
The
next thing that is crucial talking about, is the MPLABX and the XC8 compiler. I
hope you have gotten it ready. It is time to put it into use.
The
MPLABX IDE has a simulator and an editor. The XC8 compiler is installed
separately. After its installation, it is been linked to the MPLABX IDE.
In
the next tutorial, I will explain how configure the MPLABX for the purpose of
writing your programs.
Thank
you for reading.
Your comments and questions are
all highly welcomed. You can forward them to trinnexelectronics@gmail.com.
You can also visit my blog timothyadegbite.blogspot.com to read my articles on renewable energy.
Comments