Professional Documents
Culture Documents
Embedded Systems With 8051 Micro-Controller Using Embedded C
Embedded Systems With 8051 Micro-Controller Using Embedded C
micro-controller using
Embedded c
ENTREPRENEURSHIP
By K.Rasagnya
www.task.telangana.gov.in
Contents
EDUCATION
4. Microcontroller vs Microprocessor
5. Embedded software
• Higher level coding
www.task.telangana.gov.in
Contents
EDUCATION
6. Introduction to Microcontroller
• 8051 Microcontroller
EMPLOYABILITY
• Different manufacturers
• Choosing a Microcontroller
8. Keil microvision
• Uses
• LED blink
• 1 LED blink
17. Timers
ENTREPRENEURSHIP
www.task.telangana.gov.in
Introduction to Embedded systems
EDUCATION
• A system is a group of units, joined together to work in a specific routine and perform
some fixed operation.
EMPLOYABILITY
• An embedded system is that system which has computer hardware with software
embedded in it.
• It has a programmable element inside it, which is developed to perform one dedicated
ENTREPRENEURSHIP
task (EX: MP3 player, which can be used for playing audio).
www.task.telangana.gov.in
Components of Embedded System
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Components of Embedded System
EDUCATION
• An Embedded System consists of four main components. They are the Processor
EMPLOYABILITY
Processor :
ENTREPRENEURSHIP
• Based on the functionality of the system, the processor can be anything like a General Purpose
Processor, a single purpose processor, an Application Specific Processor, a microcontroller or
an FPGA.
www.task.telangana.gov.in
EDUCATION
Memory :
• It is divided in to RAM and ROM. Memory in an Embedded System (ROM to be specific) stores the
main program and RAM stores the program variables and temporary data.
Peripherals :
ENTREPRENEURSHIP
• In order to communicate with the outside world or control the external devices, an Embedded System
must have Input and Output Peripherals.
• Some of these peripherals include Input / Output Ports, Communication Interfaces, Timers and
Counters, etc.
www.task.telangana.gov.in
EDUCATION
Software :
• All the hardware work according to the software (main program) written. Software
EMPLOYABILITY
www.task.telangana.gov.in
Applications of Embedded systems
EDUCATION
• Even with the development of many advanced and superior Microcontrollers, 8051
EMPLOYABILITY
1. Communication :
• Mobile Phones
ENTREPRENEURSHIP
• Satellite systems
• Telephone systems
• ATM machines
www.task.telangana.gov.in
Applications of Embedded systems
EDUCATION
• Sensors • Clocks
• Microwave oven
• Exercise Equipment's
www.task.telangana.gov.in
Applications of Embedded systems
EDUCATION
4. Medical : 5. Industrial :
EMPLOYABILITY
• Dialysis machine
www.task.telangana.gov.in
Applications of Embedded systems
EDUCATION
6. Defense : 7. Automobiles :
EMPLOYABILITY
www.task.telangana.gov.in
EDUCATION
www.task.telangana.gov.in
Microcontroller Vs Microprocessor
EDUCATION
• Microprocessor :
1. Microprocessor acts as a heart of computer system.
EMPLOYABILITY
2. CPU is stand-alone. It is a processor in which memory(RAM &ROM) and I/O component is connected
externally.
3. Designer can decide the amount of RAM, ROM & I/O ports.
4. A processor is installed or mounted on Mother Board and Microprocessor on its own does not do anything.
ENTREPRENEURSHIP
5. In order to function this Microprocessor, we need a Mother Board with number of different chips on board.
www.task.telangana.gov.in
Microcontroller Vs Microprocessor
EDUCATION
• Microcontroller :
1. Microcontroller acts as a heart of embedded system.
EMPLOYABILITY
2. A Microcontroller is a single chip system( on a single integrated circuit) which has many
other components on it ( peripherals embedded on to a single chip ).
4. It is a controlling device in which memory and I/O component is present internally. Due this
the circuit will be small.
www.task.telangana.gov.in
Embedded Software
EDUCATION
• It is generally 2 types
www.task.telangana.gov.in
Embedded Software
EDUCATION
3. The issue is it takes lot of time to study the entire assembly instruction set of a
particular microcontroller.
www.task.telangana.gov.in
Embedded Software
EDUCATION
1. In higher level language, program is written using higher level languages such as c, c+
+, java etc.
2. While there are many embedded languages available, C is most popular of them all.
ENTREPRENEURSHIP
www.task.telangana.gov.in
Microcontroller
EDUCATION
• Microcontroller is a single chip system, which has all the peripherals on that chip. It
has RAM, ROM and some other peripherals such as timers, counters etc.
ENTREPRENEURSHIP
www.task.telangana.gov.in
8051 Microcontroller
EDUCATION
• The 8051 Microcontroller is one of the most popular and most commonly used
microcontrollers in various fields like embedded systems, consumer electronics,
EMPLOYABILITY
automobiles, etc.
• 8051 Microcontroller has many features like Serial Communication, Timers, Interrupts, etc.
ENTREPRENEURSHIP
• Because of their low power consumption, smaller size and simple architecture, 8051 IP
Cores (Intellectual Property Cores) are used in FPGAs (Field Programmable Gate Array)
and SoCs (System on Chip) instead of Advanced ARM Architecture based MCUs.
www.task.telangana.gov.in
EDUCATION
• Atmel • Infineon
• Phillips • NXP
• ST Microelectronics
www.task.telangana.gov.in
Choosing a Microcontroller
EDUCATION
• Depending upon the application, first choose a microcontroller. It depends on the hardware that you
want to connect with. Also the software requirements should be kept in kind while choosing
EMPLOYABILITY
microcontroller.
6. Power consumption.
www.task.telangana.gov.in
Microcontroller Architecture
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Microcontroller pin diagram
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Important features of 8051
EDUCATION
1. 4K bytes ROM
EMPLOYABILITY
3. Four 8 bit I/O ports (P0, P1, P2, P3). All I/O ports are bidirectional.
6. There is a CPU along with interrupts control unit( INT0, INT1) and an on chip
oscillator (Although the oscillator is on chip, we need to connect crystal externally).
www.task.telangana.gov.in
Important features of 8051
EDUCATION
7. RST (reset) needs a positive signal whenever the microcontroller gets powered ON that’s
why it is a power-on reset. So, on applying a high pulse to RST, the microcontroller will
EMPLOYABILITY
8. EA (External Access and initially it is active low). For 8051, EA pin is connected to Vcc.
9. PSEN ( Program Store Enable) is an output pin and used for external ROM. It is used
ENTREPRENEURSHIP
10. ALE ( Address Latch Enable) is an output pin and is active high. It is used for
demultiplexing the address and data.
www.task.telangana.gov.in
8051 Microcontroller Basic Circuit
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Proteus ISIS
EDUCATION
www.task.telangana.gov.in
Proteus ISIS
EDUCATION
• Proteus ISIS is the software used to draw schematics and simulate the
EMPLOYABILITY
www.task.telangana.gov.in
Installation of Proteus ISIS
EDUCATION
https://drive.google.com/u/0/uc?id=14ERAQzsyKfj6eJUtcmXHZRN3exYGVBSn&export=download
• Go to E drive and open proteus folder, then right click on pro-setup77 and click on
ENTREPRENEURSHIP
Run as administrator.
• It will ask you to install, click on yes, next click on ok, click on next.
www.task.telangana.gov.in
Installation of Proteus ISIS
EDUCATION
• It will show “no license key is selected”, click on next and select Browse for
ENTREPRENEURSHIP
Key File
• Go to drive ( E drive ) where proteus software is present open it then open crack
and select the license key and click on open .
www.task.telangana.gov.in
Installation of Proteus ISIS
EDUCATION
• Click on install next click on yes and then close that window.
EMPLOYABILITY
• You will have LXK proteus 7.7 SP2 ENG v1.0.0 , right click on it and select
Run as administrator.
www.task.telangana.gov.in
Installation of Proteus ISIS
EDUCATION
• It will show the license for proteus, click on browse and select computer, next
EMPLOYABILITY
www.task.telangana.gov.in
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
Proteus ISIS
www.task.telangana.gov.in
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP Proteus ISIS
www.task.telangana.gov.in
Keil microvision
EDUCATION
2. Easy to use
4. Easy to debug
www.task.telangana.gov.in
Installation of Keil microvision
EDUCATION
• Open http://www.keil.com/c51/
EMPLOYABILITY
• After filling, click on submit and you will have .EXE, click on it, then click on
start download.
www.task.telangana.gov.in
Installation of Keil microvision
EDUCATION
• It will take a minute to finish and select the given 2 options and click on finish.
www.task.telangana.gov.in
C Programming for Microcontroller
EDUCATION
• The ‘c’ programming language was developed for UNIX operating system, by
EMPLOYABILITY
www.task.telangana.gov.in
Example :
EDUCATION
if syntax : int a, b ;
Scanf(“%d%d”, &a, &b)
EMPLOYABILITY
if(condition) if(a>b)
{ {
} }
ENTREPRENEURSHIP
if(b>a)
{
printf(“b is greater”);
}
www.task.telangana.gov.in
Example :
EDUCATION
if(condition) if(a>b)
{ {
} }
ENTREPRENEURSHIP
else else
{ {
} }
www.task.telangana.gov.in
Example :
EDUCATION
while(condition) int a ;
{ a=1;
do this ; while(a<=10)
increment ; {
ENTREPRENEURSHIP
} printf(“hello”);
a++;
}
}
www.task.telangana.gov.in
Example :
EDUCATION
{ for(a=1;a<=10;a++)
do this ; {
} printf(“hello”);
ENTREPRENEURSHIP
}
}
www.task.telangana.gov.in
switch syntax : Example :
EDUCATION
main()
switch( integer expression)
{
{
EMPLOYABILITY
int a=1 ;
case 1 :
switch(a)
Do this ;
case 1 :
case 2 :
printf( “one”) ;
Do this ;
case 2 :
ENTREPRENEURSHIP
default :
printf( “two”) ;
Do this ;
default :
}
printf( “default”) ;
}
www.task.telangana.gov.in
EDUCATION
• Infinite loops :
EMPLOYABILITY
For embedded systems, infinite loops are always required for MCU based
applications.
Ex: while(1)
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing of LED with 8051 micro-controller
EDUCATION
• Basics of LED :
EMPLOYABILITY
• LED’s are (Light Emitting Diode) components which can emit a specific light.
• The LED’s are having two leads, they are called as Anode and Cathode.
www.task.telangana.gov.in
Interfacing of LED with 8051 micro-controller
EDUCATION
• Basics of LED :
EMPLOYABILITY
www.task.telangana.gov.in
Interfacing of LED with 8051 micro-controller
EDUCATION
www.task.telangana.gov.in
Interfacing of LED with 8051 micro-controller
EDUCATION
Programs :
EMPLOYABILITY
1. LED Blink
www.task.telangana.gov.in
EDUCATION
{ while(1)
unsigned int i; {
while(count) P2 = 0xFF;
{ delay(1000);
i = 115; P2 = 0x00;
while(i > 0) delay(1000);
ENTREPRENEURSHIP
i--; }
count--; }
}
}
www.task.telangana.gov.in
EDUCATION
P2 = 0x00;
{ while(1)
P2 = 0x00; {
while(1) P2 = 0xF0;
delay(1000);
{
P2 = 0x0F;
ENTREPRENEURSHIP
led1 = 0; delay(1000);
delay(500); }
led1 = 1; }
delay(500);
}
}
www.task.telangana.gov.in
EDUCATION
P2 = 0x00;
while(1)
{
P2 = 0xAA;
delay(1000);
ENTREPRENEURSHIP
P2 = 0x55;
delay(1000);
}
}
www.task.telangana.gov.in
Interfacing of LED with 8051 micro-controller
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing of switch with 8051 micro-controller
EDUCATION
• Basics of Switch :
• Close
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing of switch with 8051 micro-controller
EDUCATION
• Basics of Switch :
www.task.telangana.gov.in
Interfacing of switch with 8051 micro-controller
EDUCATION
Application of Switch :
EMPLOYABILITY
• The different types of switches which are widely used across industries such as
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing of switch with 8051 micro-controller
EDUCATION
Push Button :
EMPLOYABILITY
• The circuit is powered up with battery. When the push button is pressed,
a current will flow through the LED and LED will glow.
www.task.telangana.gov.in
EDUCATION
Push Button :
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing of switch with 8051 micro-controller
EDUCATION
Programs :
EMPLOYABILITY
2. 2 switch and 1 LED (sw1 pressed led on, sw2 pressed led off)
4. 2 switch and 2 LED (sw1 pressed both led on, sw2 pressed both led off)
www.task.telangana.gov.in
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing of relay
EDUCATION
• Basics of Relay :
EMPLOYABILITY
www.task.telangana.gov.in
EDUCATION
• Basics of Relay :
• C is Common or Vo
3. When the coil is not energized NC & C
• NC is Normally Closed
will connect.
• NO is Normally Open
www.task.telangana.gov.in
Interfacing of relay
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
1. By default NC is connected to Vo ( not
EDUCATION
www.task.telangana.gov.in
Interfacing of relay
EDUCATION
EMPLOYABILITY
www.task.telangana.gov.in
Interfacing of relay
EDUCATION
on relay coil and it gets magnetized and then common(C) connects to Normally
Opened( NO ).
• Resistor(330 to 1K ohm) in series with transistor used to have safe on and off of
transistor.
www.task.telangana.gov.in
Interfacing of relay
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
ULN2803
EDUCATION
EMPLOYABILITY
Power = +12V
www.task.telangana.gov.in
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing of DC motor using L293D with
EDUCATION
8051 micro-controller
• DC motor :
EMPLOYABILITY
movement or motion.
www.task.telangana.gov.in
EDUCATION
• DC motor connection :
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
EDUCATION
3. SW-SPST
ENTREPRENEURSHIP
www.task.telangana.gov.in
EDUCATION
www.task.telangana.gov.in
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
• H Bridge :
www.task.telangana.gov.in
EDUCATION
Basics of L293D :
(clockwise or anticlockwise).
www.task.telangana.gov.in
Interfacing diagram of DC Motor
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing of LCD with 8051
micro-controller
EDUCATION
• Basics of LCD :
EMPLOYABILITY
3. A 16X2 LCD means it can display 16 characters per line and there are 2 such
lines. So for 16X2 LCD, it can display 32 characters at a time.
www.task.telangana.gov.in
EDUCATION
• Data
6. The command register stores the command instructions given to the LCD.
ENTREPRENEURSHIP
8. 16X2 LCD is the most widely used LCD and it is very popular because of its
simplicity.
www.task.telangana.gov.in
EDUCATION
Applications of LCD :
• Mobile Phones
EMPLOYABILITY
• Billing machines
• Calculators
• TV set
ENTREPRENEURSHIP
• Ticket Machine
www.task.telangana.gov.in
Interfacing of LCD with 8051 micro-controller
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Functions for 8051 Interfacing
EDUCATION
en = 1; en = 1;
delay(500); delay(500);
en = 0; en = 0;
} }
www.task.telangana.gov.in
Interfacing diagram of LCD
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
EDUCATION
Commands of LCD :
• 38 : use 2 lines & 5*7 matrix
EMPLOYABILITY
• 01 : clear display
• 02 : return home
www.task.telangana.gov.in
Interfacing of Stepper motor using with
EDUCATION
8051 micro-controller
• Stepper motor :
EMPLOYABILITY
• The magnetism of these 4 coils are varied in such a way that the shaft rotate either
in clockwise or anticlockwise direction.
www.task.telangana.gov.in
EDUCATION
• Stepper motors can be used in various areas of your microcontroller projects such as making
robots, robotic arm, automatic door lock system, medical scanners,blood analysis machinery,
cameras for automatic digital camera focus and zoom functions etc.
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
EDUCATION
• The unipolar stepper motor has five or six wires and four coils (actually two coils
ENTREPRENEURSHIP
• The center connections of the coils are tied together and used as the power
connection. They are called unipolar steppers because power always comes in on
this one pole.
www.task.telangana.gov.in
Unipolar stepper motor
EDUCATION
• "Unipolar stepper motors" which is most common type of stepper motor available
in the market.
EMPLOYABILITY
www.task.telangana.gov.in
EDUCATION
• The bipolar stepper motor usually has four wires coming out of it. Unlike unipolar
EMPLOYABILITY
steppers, bipolar steppers have no common center connection. They have two
independent sets of coils instead.
1. When we energize a coil of stepper motor, The shaft of stepper motor (which is
actually a permanent magnet) align itself according to poles of energized coil.
2. So when motor coils are energized in a particular sequence, motor shaft tend to
align itself according to pole of coils and hence rotates.
www.task.telangana.gov.in
EDUCATION
• Step Sequence :
• In one-phase - full step, Fig1, the motor is operated with only one phase energized at a
time. This mode requires the least amount of power from the driver of any of the
excitation modes.
www.task.telangana.gov.in
EDUCATION
• In two-phase - full step, Fig2, the motor is operated with both phases energized at
the same time. This mode provides improved torque and speed performance.
EMPLOYABILITY
ENTREPRENEURSHIP
Fig 1 : one phase – full step Fig 2 : two phase – full step
www.task.telangana.gov.in
Full Step Sequence Table
EDUCATION
Step A B C D
EMPLOYABILITY
0(0x0C) 1 1 0 0
1(0x06) 0 1 1 0
2(0x03) 0 0 1 1
ENTREPRENEURSHIP
3(0x09) 1 0 0 1
www.task.telangana.gov.in
EDUCATION
• Half step excitation mode is a combination of one phase on and two phase on
EMPLOYABILITY
full step modes. This results in half the basic step angle. This smaller step angle
provides smoother operation due the increased resolution of the angle.
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing diagram of Stepper Motor
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing diagram of 7 segment display
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Timer
EDUCATION
Timer :
EMPLOYABILITY
4. But the microcontroller does not have any clock to see the time, so it basically
counts the pulses given to the timer module.
www.task.telangana.gov.in
Timer
EDUCATION
www.task.telangana.gov.in
Interfacing diagram of Timer
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
Interfacing diagram of Timer : output
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
www.task.telangana.gov.in
EDUCATION
EMPLOYABILITY
ENTREPRENEURSHIP
Thank you
www.task.telangana.gov.in