Académique Documents
Professionnel Documents
Culture Documents
INTRODUCTION
1.1 Introduction
Circumstances that we find ourselves in today 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. An
embedded computer is a computer that is a component of a larger system; it helps implement
the system functionality. Embedded computers exist in automobiles, airplanes, home
appliances, military vehicles & equipments, medical devices, robotic, mobile communication
system etc. Sophisticated embedded computers have been used in products and systems for
over twenty years.
Embedded computing includes several aspects: methodology, architectures, and applications
which is practiced in conducting research. Methodology is important because the prime goal
is to be able to reliably, predictably develop new systems. Embedded computers is used to
make a wide variety of systems, therefore methodology of designing an embedded system
that enable assessment of a system requirements, develop an architecture, and implement the
embedded system is very important.
Architecture is used here in a broad sense: both software and hardware. Early decisions can
make or break a design. It is important to get the structure of the software and hardware right
at the architectural stage in order to avoid expensive problems later in the design process.
This generally means jointly considering the effects of architectural decisions on both the
hardware and software sides of the implementation.
Applications are the motivation for embedded computing. It is important to take application
characteristics into account during the design of an embedded system, and also important to
understand at least one application area well in order to do the best research in embedded
computing.
An embedded product uses a microprocessors and microcontroller to do one task and one
task only.
Generally basic meaning of embedded is given as follows:
It is HIDDEN inside the main computer which controls it.
Other that PC everything is embedded.
It is combination of electronic hardware and software and additional mechanical parts
designed to perform a specific set of tasks within a given time frame.
1.5 Objective
The objective is to explore the details of embedded computing aspects which are the
Methodology, Architecture and Application. This will enable cutting edge technology
development in hardware and software through embedded system applications development.
1.6 List of training Modules
2
CHAPTER 2
INTRODUCTION TO MICROCONTROLLERS
Microcontrollers often use EEPROM or EPROM as their storage device to allow field
programmability so they are flexible to use. Once the program is tested to be correct
then large quantities of microcontrollers can be programmed to be used in embedded
systems.
Easy to Use
Assembly language is often used in microcontrollers and since they usually follow
RISC architecture, the instruction set is small. The development package of
microcontrollers often includes an assembler, a simulator, a programmer to "burn" the
chip and a demonstration board. Some packages include a high level language
compiler such as a C compiler and more sophisticated libraries.
A Timer module to allow the microcontroller to perform tasks for certain time periods.
A serial I/O port to allow data to flow between the microcontroller and other devices
such as a PC or another microcontroller.
An ADC to allow the microcontroller to accept analogue input data for processing.
In 1981, Intel corporation introduced an 8-bit microcontroller called the 8051. This
microcontroller had 128 bytes of on chip ROM, two timers, one serial port and four ports (8bits) all on a single chip. The 8051 is an 8 bit processor by the CPU. The 8051 has a total of
four I/O ports, each 8-bit wide. Although 8051 can have a maximum of 64K bytes of on chip
ROM, many manufacturers put only 4K bytes on the chip.
The 8051 became widely popular after Intel allow another manufactures to make any flavour
of the 8051 they please with the condition that they remain code compatible with . the 8051.
This led to many versions of the 8051 with different speeds and amount of on chip ROM
marketed by the more than half a dozen manufactures. It is important to know that although
there are different flavours of 8051, they are compatible with the original 8051 as far as the
instructions are concerned. This means that if you write your program for one, it will run on
any one of them regardless of the manufacturer. The 8051 manufactures are INTEL, ATMEL.
DALLAS semiconductors, Philips corporation, Infineon.
2.4 AT89C52 from ATMEL Corporation
This popular 8051 clip has on-chip ROM in the form of flash memory. This is ideal for fast
development since flash memory can be erased in seconds compared to twenty minutes or
more needed for the earlier versions of the 8051. To use the AT89C52 to develop a
microcontroller-based system requires a ROM burner that supports flash memory. However, a
ROM eraser is not needed. Notice that in a flash memory you must erase the entire contents
of ROM in order to program it again. The PROM burner does this erasing of flash itself and
this is why separate burner is not needed. To eliminate the need for a PROM burner Atmel is
working on a version of AT89C51 that can be programmed by serial COM port of the PC.
externally. EA which stands for external Access is pin no 31 in the DIP packages. It is input
pin and must be connected to either Vcc or GND in others words it must not be lied unconnected.
2.6.6 PSEN
This is an output pin. PSEN stands for Program Store Enable . It is the read store to the
external program memory. When the microcontroller is executing from external memory
PSEN is activated twice in each machine cycle.
2.6.7 ALE
ALE stands for Address Latch Enable. It is an O/P pin and is active high. When connecting
a microcontroller to a external memory, port P0 provides both address and data. In the other
words the microcontroller multiplexes data and address through port P0 to save pins. The
ALE pin is used for de-multiplexing the address by connecting to the G pin of the 74LS373
chip.
2.6.8 I/O port pins and their functions
The four ports P0, P1, P2, P3, we use eight pins, making them 8 -bit ports. All the port upon
RST are configured as O/P, ready to be used as O/P ports. To use any of these as I/P port it
must be programmed.
2.6.8.1 Port 0
Port 0 occupies a total of 8 pins (pins 32 to 39). It can be used for input or output. To use the
pins of port 0 as both input and output ports, each pin must be connected to a 10 K-ohm pullup resistors. This is due to fact that port 0 is an open drain, unlike P1, P2 and P3. With
external pull up resistors connected upon reset, port 0 is configured as output port. In order to
make port 0 as input, port must be programmed by writing 1to all the bits of it. Port 0 is also
designed as AD0-AD7, allowing it be used as bots data and address. When connecting a
microcontroller to an external memory, port 0 provides both data and address. The
microcontroller multiplexes address and data through port 0 to save pins. ALE indicates if P0
has address or data. When ALE=1, it provides address(A0-A7) and when ALE-0, it provides
data(D0-D7). Therefore ALE is used for demultiplexing address and data with the help of
latch 74LS373.
2.6.8.2 Port 1
Port 1 occupies a total of 8 pins (pins 1 to 8). It can be used for input or output .In contrast to
port 0, this port doesnt requires pull up resistor. Since it has already pull up resistor
internally. Upon reset, port1 configured as an O/P port. Similar to port 0, port1 can be used as
an input port by writing 1 in the program.
2.6.8.3 Port 2
Port 2 occupies a total of 8 pins (pins 21 to 28). It can be used for input or output. Just like
P1, port 2 doesnt requires pull up resistor. Since it has already pull up resistor internally.
Upon reset, port2 configured as an O/P port. Similar to port 1, port2 can be used as an input
port by writing 1 in the program.
8
2.6.8.4 Port 3
Port 3 occupies a total of 8 pins (pins 10 to 17). It can be used for input or output. Just like
P1, port 3 doesnt requires pull up resistor. Since it has already pull up resistor internally.
Upon reset, port3 configured as an O/P port. Similar to port 1, port3 can be used as an input
port by writing 1 in the program.
2.7 Registers
In the CPU, registers are used to store information temporarily. That information could be a
byte of data to be processed, or an address pointing to the data to be fetched. In the 8051
there is only one data type: 8 bits. With an 8 bit data type, any data larger than 8 bits has to be
broken into 8-bit chunks before it is processed.
The most commonly used registers of the 8051 are A (accumulator), B, R0, R1, R2, R3, R4,
R5, R6, R7, DPTR (data pointer) and PC (program counter). All the above registers are 8-bit
registers except DPTR and the program counter. The accumulator A is used for all arithmetic
and logic instructions.
2.8 Program Counter and Data Pointer
The program counter is a 16- bit register and it points to the address of the next instruction to
be executed. As the CPU fetches op-code from the program ROM, the program counter is
incremented to the next instruction. Since the PC is 16 bit wide, it can access program
addresses 0000 to FFFFH, a total of 64K bytes of code. However, not all the members of the
8051 have the entire 64K bytes of on-chip ROM installed.
The DPTR register is made up of two 8-bit registers, DPH and DPL, which are used to
furnish memory addresses for internal and external data access. The DPTR is under the
control of program instructions and can be specified by its name, DPTR. DPTR does not have
a single internal address, DPH and DPL are assigned an address each.
2.9 Flag bits and PSW Register
Like any other microprocessor, the 8051 have a flag register to indicate arithmetic conditions
such as the carry bit. The flag register in the 8051 is called the program status word (PSW)
register.
The program status word (PSW) register is an 8-bit register. It is also referred as the flag
register. Although the PSW register is 8-bit wide, only 6 bits of it are used by the
microcontroller. The two unused bits are user definable flags. Four of the flags are
conditional flags, meaning they indicate some conditions that resulted after an instruction as
executed. These four are CY (carry), AC (auxiliary carry), P (parity) and OV (overflow).
CY, The Carry Flag
This flag is set whenever there is a carry out from the d7 bit. This flag bit is affected after an
8-bit addition or subtraction. It can also be set to 1 or 0 by an instruction such as SETB C
and CLR C, where SETB C stands for set bit carry and CLR C stands for clear carry.
10
CHAPTER 3
INTERFACING OF MICROCONTROLLER
11
BRIDGE
RECTIFIER
SHUNT
CAPACITOR
VOLTAGE
REGULATOR
passing an a/c current through the primary coil creates a changing voltage in the primary coil
and a changing magnetic field in the core. This in turn indicates a varying a/c voltage in the
secondary coil.
The a/c voltage is then fed to the bridge rectifier. The rectifier circuit used in the most
electronic power supplies is the single phase bridge rectifier with capacitor filtering, usually
followed by a linear voltage regulator. A rectifier circuit is necessary to convert a signal
having zero average value into a non-zero average value. A rectifier transforms alternating
current into direct current by limiting or regulating the direction of flow of current. The
output resulting from a rectifier is a pulsating D.C. voltage. This voltage is not appropriate for
the components that are going to work through it.
13
1N 4007
12-0-12 V
7805
14
15
For(j=0;j<=70;j++)
{
_nop_( );
}
}
}
void sec_delay(unsigned char n)
{
unsigned char i,j;
for(i=0;i<=n;i++)
{
For(j=0;j<=250;j++)
{
ms_delay(4);
}
}
}
void main( )
{
while(1)
{
P1=0xff;
sec_delay(1);
P1=0x00;
Sec_delay(1);
}
}
void main( )
{
unsigned char i,a;
while(1)
{
a=0xff;
for(i=0;i<=8;i++)
{
P1=a;
a=a<<1;
sec_delay(1);
}
}
}
}
}
}
19
Pin
Symbol
I/O
Description
VSS
Ground
VCC
VEE
RS
R/W
I/O
Enable
PB0
I/O
PB1
I/O
DB2
I/O
10
DB3
I/O
11
DB4
I/O
12
DB5
I/O
13
DB6
I/O
14
DB7
I/O
EN (enable)
The enable pin is used by the LCD to latch information presented to its data pins. When data
is supplied to data pins, a high-power, high to low pulse must be applied to this pin in order to
for the LCD to latch in the data presented at the data pins.
D0-D7 (data lines)
The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of
the LCDs internal registers. To display the letters and numbers, we send ASCII codes for the
letters A-Z, a-z, and numbers 0-9 to these pins while making RS=1. There are also command
codes that can be sent to clear the display or force the cursor to the home position or blink the
cursor.
We also use RS=0 to check the busy flag bit to see if the LCD is ready to receive the
information. The busy flag is D7 and can be read when R/W=1 and RS=0, as follows: If
R/W=1 and RS=0, when D7=1 (busy flag=1), the LCD is busy taking care of internal
operations and will not accept any information. When D7=0, the LCD is ready to receive new
information.
An Example of Hardware Configuration
As weve mentioned, the LCD requires either 8 or 11 I/O lines to communicate with. For the
sake of this tutorial, we are going to use an 8-bit data bus, so, well be using 11 of the 8051s
I/O pins to interface with the LCD.
Status command the LCD will immediately raise DB7 if its still busy executing a command
or lower DB7 to indicate that the LCD is no longer occupied. Thus our program can query the
LCD until DB7 goes low, indicating the LCD is no longer busy. At that point, we are free to
continue and send the next command.
(HEX)
Register
0x01
0x02
Return home
0x04
0x05
0x06
0x07
0x08
0x0A
0x0C
0x0E
0x0F
0x10
0x14
0x18
0x1C
0x80
0xC0
0x38
16x2 display
22
Display(COMMUNICATION);
}
}
24
(i)
(ii)
Figure 3.6: (i) Common anode configuration. (ii) Common cathode configuration
25
Figure 3.7: Circuit diagram of Interfacing of Seven Segment Display with Microcontroller
}
}
If(P21==0|| P22==0)
Break;
27
}
If(P21==0)
{
while(1)
{
unsigned char a,i,b,c;
a=b=c=0xFF;
for(i=0;i<9;i++)
{
P1=c;
B=~a;
a=a<<1;
c=a+b;
sec_delay(1);
if(P20==0|| P22==0)
break;
}
29
(ii). Separately Excited D.C. Motor: These motors have field coils similar to those of a
shunt wound machine, but the armature and field coils are fed from different supply sources
and may have different voltage ratings.
(iii). Series wound D.C. motor: As the name indicates, the field coils consisting of few turns
of a thick wire are connected in series with the armature. The cross sectional area of the wire
used for the field has to be fairly large to carry the armature current, but owing to the higher
current, the number of turns of wire in them need not to be large.
(iv). Shunt wound D.C. motor: These motors are so named because they are basically
operated with field coils connected in parallel with the armature.
The field winding consists of alarge number of turns of comparatively fine wires so as to
provide large resistance. The field current is much less than the armature current, sometimes
as low as 5%.
(v). Compound wound D.C. motor: A compound wound D.C. motor has both shunt and
series coils. The shunt field is normally stronger of the two. Compound wound motor are of
two types:
(a) cumulative compound wound motor.
(b) Differential compound wound motor.
3.7.4 Program for Interfacing DC Motor.
3.7.4.1PROGRAM to control the Speed of the DC motor with the MICROCONTROLLER.
#include<reg51.h>
#include<intrins.h>
Void dc_speed (unsigned int n)
{
m=2.5*n;
P10=0;
Ms_delay(m);
P10=1;
Ms_delay(100-m);
}
Void main()
{
If(P20==0)
{
30
Dc_speed (10);
}
If(P21==0);
{
Dc_speed(20);
}
If (P22==0)
{
Dc_speed(0);
}
Getch();
}
3.8 INTERFACING OF STEPPER MOTOR WITH MICROCONTROLLER.
3.8.1 Stepper Motor
A stepper motor is an electromechanical device which converts electrical pulses into discrete
mechanical movements. Stepper motor is a form of ac motor. The shaft or spindle of a stepper
motor rotates in discrete step increments when electrical command pulses are applied to it in
the proper sequence. The motors rotation has several direct relationships to these applied
input pulses.
31
A stepper motor is an electromechanical device which converts electrical pulses into discrete
mechanical movements. Stepper motor is a form of ac motor. The shaft or spindle of a stepper
motor rotates in discrete step increments when electrical command pulses are applied to it in
the proper sequence. The motors rotation has several direct relationships to these applied
input pulses. The sequence of the applied pulses is directly related to the direction of motors
shaft rotation. The speed of the motor shaft rotation os directly related to the frequency of the
input pulses and the length of rotation is directly to the number of input pulses applied.
For every input pulse, the motor shaft turns through a specified number of degrees, called a
step. Its working principle is one step rotation for one input pulse. The range of step size may
vary from 0.72 degree to 90 degree. In position control application, if the number of input
pulses sent to the motor is known, the actual position of the driven job can be obtained.
A stepper motor (SM) differs from a conventional motor (CM) as under:
a. Input to SM is in the form of electric pulses whereas input to the CM is invariable
from a constant voltage source.
b. A CM has a free running shaft whereas the shaft of SM moves through angular steps.
c. In control system applications, no feedback loop is required when SM is used but a
feedback loop is required when CM is used.
d. A SM is a digital electromechanical device whereas a CM is an analog
electromechanical device.
32
Winding C
Winding B
1
2
3
Winding A
Winding D
Winding B
1
0
1
0
Winding C
1
1
0
1
Winding D
1
1
1
0
Movement associated with a single step, depends on the internal construction of the motor, in
particular the number of teeth on the stator and the rotor. The step angle is the minimum degree
of rotation associated with a single step.
Step per revolution is the total number of steps needed to rotate one complete rotation or 360
degrees (example: 180 steps * 2 degrees = 360) [31].
Since the stepper motor is not ordinary motor and has four separate coils, which have to be
energized one by one in step wise fashion. We term them as coil A,B,C,D. At a particular
instant the coil A should get the supply and then after some delay the coil B should get supply
and then coil C and then coil D and so on the cycle continues. The more the delay is introduced
between the energizing of the coils the lesser the speed of the motor and vice versa.
3.8.5 Program for Interfacing Stepper Motor.
ms_delay(100);
P2=0x04;
ms_delay(100);
P2=0x08;
ms_delay(100);
P2=0x01;
ms_delay(100);
P2=0x02;
}
void close()
{
P2=0x00;
ms_delay(100);
P2=0x08;
ms_delay(100);
P2=0x04;
ms_delay(100);
P2=0x02;
ms_delay(100);
P2=0x01;
ms_delay(100);
P2=0x08;
ms_delay(100);
35
P2=0x04;
ms_delay(100);
P2=0x02;
ms_delay(100);
P2=0x01;
ms_delay(100);
P2=0x08;
ms_delay(100);
P2=0x04;
}
void main()
{
while(1)
{
close();
sec_delay(5);
open();
}
}
}
36
37
1.
Create a project, select the target chip from the device database, and configure the tool
settings.
2.
3.
4.
5.
Figure 3.14:
3. Go to the project & click on new project
38
39
10. Add the source file and Select the XTAL frequency.
11. Click on output and select the option Create HEX File.
40
12. Open the New File and Write the Program in it.
41