Escolar Documentos
Profissional Documentos
Cultura Documentos
PTU JALANDHAR
PUNJAB
INDIA
ACKNOWLEDGEMENT
It was highly educative and interactive to take training at SOFCON India. Pvt. Ltd.,delhi.
A person technically lacks without having practical knowledge but here it was a good chance for
learning and practicing new things to update our self. In a fully equipped environment and well
experienced trainers, it was a qualitative program for being known with engineering
requirements. Trainers guided me very well and updated me with all the valuable information
regarding my course and latest technology.
I am highly thankful to the respected Training and Placement Officer and respected Head of
Department of Electronics and Communication Department Ms. Nancy Kaur for allowing me to
join YOUR TRAINING INST. and motivating me to do the right things. I also take the
opportunity to thanks to Mr.Akshay and Mr. Preetfor his precious guidance in field of
microcontrollers and interfacing circuits and devices and also sorting out our problems.
TABLE OF CONTENTS
8-9
10-12
5.1 AT 89C51
5.2 Pin Diagram of AT89C51
5.3 Pin Description of 8051
13-15
16-28
29-34
Topic 9 Bibliography
Topic 1
Company Profile (SOFCON India Pvt. Ltd.)
Labs N Racks is the first and only professional CISCO training institute around Haryana, Punjab,
Uttaranchal, HP, J & K,and Rajasthan which is providing CCIE training, led by a team of highly
qualified CISCO trainers. Labs N Racks was born when experts from the field of
internetworking who had significant experience both in industry as well as educational training
came together to start their own institute.
Labs N Racks is providing CISCO training from the basic level to the advanced level, so the
students who want to enter into the field of IT do not find any difficulty in acquiring and
developing the required expertise.
The leadership of Labs N Racks possesses sound technical knowledge to ensure that Labs N
Racks trainers are masters in the internetworking technologies in general and are SMEs (Subject
Matter Experts) for the courses they deliver. It is the only institute in the region which has CCIE
trainers having a past experience of more than 8 years in the training industry.
Labs N Racks aims to strategize relations with global IT majors which set the trends and raise
our bar to internationally acclaimed IT power house. Association with the standard setters will
facilitate the students getting hands on experience and ready resources for complete all round IT
training to excel in any of the large list of fields the ITindustry has.
Apart from the networking, Labs N Racks is also an Embedded And Robotic Training Institute
certified from Vibe Tech Solutions Limited.
Topic 2
Introduction to Embedded Systems
An embedded system is a special-purpose system in which the computer is completely
encapsulated by the device it controls. Unlike a general-purpose computer, such as a personal
computer, an embedded system performs pre-defined tasks, usually with very specific
requirements. Since the system is dedicated to a specific task, design engineers can optimize it,
reducing the size and cost of the product. Embedded systems are often mass-produced, so the
cost savings may be multiplied by millions of items.
Handheld computers or PDAs are generally considered embedded devices because of the nature
of their hardware design, even though they are more expandable in software terms. This line of
definition continues to blur as devices expand.
Physically, embedded systems range from portable devices such as digital watches and MP3
players, to large stationary installations like traffic lights, factory controllers. Complexity varies
from low, with a single microcontroller chip, to very high with multiple units, peripheralsand
networks mounted inside a large chassis or enclosure.
Embedded systems contain processing cores that are either microcontrollers or digital signal
processors (DSP). The key characteristic, however, is being dedicated to handle a particular task.
Since the embedded system is dedicated to specific tasks, design engineers can optimize it to
reduce the size and cost of the product and increase the reliability and performance. Some
embedded systems are mass-produced, benefiting from economies of scale.
Robotics and automation are a part of embedded systems itself. Robot development and
automation needs study of embedded systems.
XI.
videogame consoles
Topic 3
Characteristics of Embedded Systems
1. Embedded systems are designed to do some specific task, rather than be a generalpurpose computer for multiple tasks. Some also have real-timeperformance constraints
that must be met, for reasons such as safety and usability; others may have low or no
performance requirements, allowing the system hardware to be simplified to reduce costs.
2. The program instructions written for embedded systems are referred to as firmware, and
are stored in read-only memory or Flash memory chips. They run with limited computer
hardware resources: little memory, small or non-existent keyboard or screen.
3. Many embedded systems consist of small, computerized parts within a larger device that
serves a more general purpose. For example- a line follower autonomous robot which
follows a specific path and moves accordingly to the path.
4. The embedded systems are special purpose computer systems designed to perform only
the specific purposes. For Example- a system designed to display numbers cannot be used
to operate motors.
5. Embedded systems range from no user interface at all dedicated only to one task to
complex graphical user interfaces that resemble modern computer desktop operating
systems. Simple embedded devices use buttons, LEDs, graphic or character LCDs (for
example popular HD44780 LCD) with a simple menu system.
Topic 4
Processors in Embedded Systems
Embedded processors can be broken into two broad categories. Ordinary microprocessors (P)
use separate integrated circuits for memory and peripherals. Microcontrollers (C) have many
more peripherals on chip, reducing power consumption, size and cost. In contrast to the personal
computer market, many different basic CPU architectures are used, since software is customdeveloped for an application and is not a commodity product installed by the end user. RISC as
well as non-RISC processors are found. Word lengths vary from 4-bit to 64-bits and beyond,
although the most typical remain 8/16-bit.
Microprocessors
1. A Microcontroller (sometimes
abbreviated C, uC or MCU) is a small computer
on a single integrated circuit containing a
processor core, memory, and
programmable input/output peripherals.
2. Microcontrollers are designed to perform
specific tasks. Specific means applications where
the relationship of input and output is defined.
Depending on the input, some processing needs to
be done and output is delivered. For example,
keyboards, mouse, washing machine, digicam,
pen drive, remote, microwave, cars, bikes,
telephone, mobiles, watches, etc.
3. Since the applications are very specific, they
need small resources like RAM, ROM, I/O ports
etc. and hence can be embedded on a single chip.
PIC- Programmable Interface Controller is usually referred as PIC. They are slightly older than
8051 microcontrollers but excel cause of their small low pin count devices. They perform well
and are affordable. The Microchip technology fabricated the single chip microcontroller PIC
with Harvard architecture. The programming part is very tedious and hence it is not
recommended for beginners.
AVR(Advanced Version RISC) - In 1996, Atmel fabricated this single chip microcontroller with
a modified Harvard Architecture. This chip is loaded with C- compiler, Free IDE and many more
features. This microcontroller is a bit difficult for the starters to handle.
Topic 5
8051 Microcontroller
The most commonly used microcontroller is 8051 families AT89C51 microcontroller which is
produced by Atmel. It is widely used in most of the application for having an advantage of
simple programming and low cost.
5.1 AT89C51
AT89C51 is an 8-bit, 40 pin microcontroller that belongs to Atmel's 8051 family. ATMEL
89C51 has 4KB of Flash programmable and erasable read only memory (PEROM) and 128 bytes
of RAM. It can be erased and program to a maximum of 1000 times.
In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit
bi-directional ports, i.e., they can be used as both input and output ports. Except P0 which needs
external pull-ups, rest of the ports have internal pull-ups. When 1s are written to these port pins,
they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit
addressable and so their bits can also be accessed individually.
5.1.1 Salient Features of AT89C51-
40-pin DIP
10
Figure 5.1
11
12
Topic6
Architecture of 8051 Microcontroller
6.1 Block Diagram of 8051 Microcontroller
Figure 6.1
Address bus-For a device (memory or I/O) to be recognized by the CPU, it must beassigned an
address. The address assigned to a given device must be unique. The CPU puts the address on the
address bus, and the decoding circuitry finds the device.
Data bus-The CPU either gets data from the deviceor sends data to it.
Control bus-Provides read or write signals to the device to indicate if the CPU is asking for
information or sending it information.
13
Figure 6.2
Generally for normal operations, Register bank Bank0 is set by default. But we can switch to
other banks by using PSW Commands.
Figure 6.3
14
6.2.1 SFRs (Special Function Register) - These Registers are in extra 128 bytes of the memory.
This part of memory is not user accessible and these registers are used for special purposes.
These
registers range from 80h to FFh. There are a total of only 21 SFRs in this range and all other
addresses from 80h to FFh are invalid and there use can cause errors and not valuable results.
Some of the SFRs are TCON, SBUF, ACC, B, SCON, TMOD SP, P0, PSW, TL0, and TL1.
These all the registers have some specific function that has to be performed after they are
programmed.
(i) Byte Addressable SFR with byte address
SP Stack printer 81H
DPTR Data pointer 2 bytes
DPL Low byte 82H
DPH High byte 83H
TMOD Timer mode control 89H
TH0 Timer 0 Higher order bytes 8CH
TL0 Timer 0 Low order bytes 8AH
TH1 Timer 1 High bytes = 80H
TL1 Timer 1 Low order byte = 86H
SBUF Serial data buffer = 99H
PCON Power control 87H.
6.2.2 DPTR - Data Pointer in 8051
16 bit register; it is divided into two parts DPH and DPL.
DPH for Higher order 8 bits, DPL for lower order 8 bits.
DPTR, DPH, DPL these all are SFRs in 8051.
15
Topic7
8051 Assembly Language Programming
7.1 How to Program an 8051 microcontroller
[Label:] mnemonic [operands] [; comment]
Mnemonics -Assembly level instructions are called mnemonic like MOV R5
Operands -On which the operation is performed.
Example:
Loop: MOVR1, #25H; transfer 25H into R1
Instructions
MOV A, B
MOV 30H,A
MOV A,@R0
MOV A,#80H
SJMP +127/-128 of PC
AJMP within 2K
LJMP FAR
MOVC A,@A+PC
Table 7.1
16
17
Absolute Addressing Mode-In Absolute Addressing mode, the absolute address, to which the
control is transferred, is specified by a label. Two instructions associated with this mode of
addressing are ACALL and AJMP instructions. These are 2-byte instructions.
Example:
ACALL
PORT_INIT;
PORT_INIT should be located within 2k bytes.
PORT_INIT:
PORT_INIT subroutine
Long Addressing Mode-This mode of addressing is used with the LCALL and LJMP
instructions. It is a 3-byte instruction and the last 2 bytes specify a 16-bit destination location
where the program branches to. It allows use of the full 64K code space.
Example:
LCALL TIMER_INIT;
TIMER_INIT address (16-bits long) is specified as the operand; In
C, this will be a function call: Timer_Init ().
TIMER_INIT: ORL TMOD, #01H;
TIMER_INIT subroutine
Indexed Addressing Mode-The Indexed addressing is useful when there is a need to retrieve data
from a look-up table (LUT). A 16-bit register (data pointer) holds the base address and the
accumulator holds an 8-bit displacement or index value. The sum of these two registers forms the
effective address for a JMP or MOVC instruction.
Example:
MOV A, #08H; Offset from table start
MOV DPTR, #01F00H; Table start address
MOVC A, @A+DPTR; Gets target value from the table starts address + offset and puts it in A.
18
Arithmetic Instructions of 8051 are shown as follows [@ RI] implies contents of memory location pointed to by R0 or R1.
Rn refers to registers R0-R7 of the currently selected register bank.
Logical Instructions-Logical instructions perform standard Boolean operations such as AND,
OR, XOR, NOT (compliment). Other logical operations are clear accumulator, rotate
accumulator left and right, and swap nibbles in accumulator.
Examples:
ANL A, #02H;Mask bit 1
ORL TCON, A;
TCON=TCON OR A
Data Transfer Instructions- Data transfer instructions can be used to transfer data between an
internal RAM location and an SFR location without going through the accumulator.
It is also possible to transfer databetween the internal and externalRAM by using indirect
addressing. The upper 128 bytes of data RAMare accessed only by indirectaddressing and the
SFRs areaccessed only by direct addressing.
Figure 7.1
Boolean Variable Instructions-The Boolean Variable operations include set, clear, as well as
and, or and complement instructions. Also included are bitlevel moves or conditional jump
instructions. All bit accesses use direct addressing.
Examples:
SETB TR0; Start Timer0.
POLL: JNB TR0, POLL; Wait until timer overflows.
The following table contains all the Boolean Variable Instructions of 8051 microcontroller.
19
Table 7.2
Program Branching Instructions- Program branching instructions are used to control the flow
of program execution. Some instructions provide decision making capabilities before
transferring control to other parts of the program e.g. conditional and unconditional branches.
the following table contains all the branching instructions
20
Table 7.3
The four 8-bit I/O ports P0, P1, P2 and P3 each use 8 pins.
All the ports upon RESET are configured as input, ready to be used as input ports.
When the first 0 is written to a port, it becomes an output.
To reconfigure it as an input, a 1 must be sent to the port.
To use any of these ports as an input port, it must be programmed.
7.3.1 Port 0
It can be used for input or output; each pin must be connected externally to a 10K ohm
pull-up resistor.
This is due to the fact that P0 is an open drain, unlike P1, P2, and P3.
Open drain is a term used for MOS chips in the same way that open collector is used for
TTL chips.
Figure 7.2
21
7.3.2 Port 1
Port 1 can be used as input or output.
In contrast to port 0, this port does not need any pull-up resistors since it already has pullup resistors internally.
Upon reset, port 1 is configured as an input port.
To make port 1 an input port, it must be programmed as such by writing 1 to all its bits.
7.3.3 Port 2
Port 2 can be used as input or output.
Just like P1, port 2 does not need any pull-up resistors since it already has pull-up
resistors internally.
Upon reset, port 2 is configured as an input portP0.4.
Port 2 is also designated as A8 A15,indicating its dual function.Port 0 provides the
lower 8 bits via A0 A7.
7.3.4 Port 3
Port 3 can be used as input or output.
Port 3 does not need any pull-up resistors.
Port 3 is configured as an input port upon reset; this is not the way it is most commonly
used.
Port 3 has the additional function of providing some extremely important signals
P3
Functio
Pin
n
P3.0
Rxd
10
P3.1
Txd
P3.2
11
Serial Communication
12
Int0
P3.3
13
P3.4
Int1
T0
14
P3.5
T1
15
P3.6
External Interrupts
Timers
16
Wr
P3.7
Rd
Table 7.4
22
Figure 7.3
23
MSB
Gate
LSB
C/T
M0
M1
GATE
Timer 1
C/T
M0
MI
Timer 0
Figure 7.4
TF1
TIMER 1
LSB
TF0
TR1
TR0
IE1
TIMER 0
IE0
TIMER1
IT1
IT0
TIMER0
Figure 7.5
TF1: Timer 1 overflows flag
TF1=1: Timer/counter 1 overflows.
TF1=0: processor vectors to the interrupt services.
TR1: Timer 1 run control bit
TR1=1: turn Timer 1 ON
TR1=0: turn Timer 1 OFF
IE1: External interrupt 1 edge flag
IE1=1: external interrupt is detected.
IE1=0: when interrupt is processed.
IT1: Interrupt 1 type control bit
IT1=1: falling edge.
IT1=0: low level triggered external interrupt.
Gate=0, SETB TR1 _Run Timer 1
SETB TR0 _Run Timer 0
24
Timer Mode 0
Timer Mode 2
Mode 2: 8-bit auto reload Timer/counter mode (00 ~ FFH).
In auto reload, TH is loaded with the initial count and a copy of it is given to TL.
This reloading leaves TH unchanged still holding a copy of original values.
This mode has many applications, including setting the baud rate in serial communication.
Mode 2 Programming
8 bit - 00 ~FFH
TH copy to TL
Start SETB TR0, or TR1
TL increased FFH (OV monitoring)
TH reloads to TL.
7.4.2 Counters
Counter is used to count input pulses.
C/T=0: As Time, using 8051s crystal as the source ofthe frequency.
C/T=1: As counter, a pulse outside of the 8051 that increments the TH and TL register.
When the C/T=1, the counter counts up as pulses are fed from Pins P3.4 (for counter 0) or P3.5
(for counter 1).
Parallel Communication
Figure 7.6
25
It is possible to write software to useeither of these methods, but the programs can be tedious and
long
There are special IC chips made by manymanufacturers for serial communications
UART (universal asynchronous Receiver transmitter)
USART (universal synchronous-asynchronous Receiver-transmitter)
The rate of data transfer in serial data communication is stated in bps (bits per second).
Another widely used terminology for bps is baud rate.
7.5.1 SCON
Figure 7.7
RI(Receive Interrupt Flag)-Set by hardware on receiving. Must be cleared by software
TI (Transmit Interrupt Flag) -Set by hardware on transmitted, must clear by hardware
RB8 (Receive bit 8)
Mode 2,3 : copy of bit 8
Mode 1 & SM2 clear : copy of stop bit
TB8 Transmit bit 8- The 9th data bit of mode 2, 3. Set or clear by software
REN Receive Enable- Set by software to enable reception, if is cleared reception will be
blocked.
SM2 Serial Mode (bit 2) -Use in mode 2,3 for multiprocessor communications.
SM1 & SM0 Serial Mode (bit 6 & 7)
Operating modes
Mode 0- 8-bit shift register, f/12
1Mbit with 12 MHz Oscillator Frequency
Mode 1- 8-bit UART, variable baud rate
Mode 2 -9-bit UART, f/64 or f/32
187.5K and 375K with 12MHz Oscillator Frequency
26
7.5.2 SBUF
These are two separate data buffers for transmit and receive.
The register SBUF is used to hold both the transmitter and receiver serial port data.
To transmit the data, load SBUF register with data.
MOV SBUF, source
When transmission is complete the TI bit will be set in the SCONregister.
When a data frame is received the RI bit in SCON is set high.
The received data may then be loaded from SBUF
MOV destination, SBUF
Data reception is double buffered.
7.5.3 SMOD
7.6 INTERUPTS
An interrupt is an external or internal event that interrupts the microcontroller to inform it that a
device needs its service.
The advantage of interrupts is that the microcontroller can serve many devices.
Each device can get the attention of the microcontroller based on the assigned priority.
The microcontroller can also ignore (mask) a device request for service.
7.6.1 Hardware and Software interrupt
The interrupts in a controller can be either hardware or software. If the interrupts are generated
by the controllers inbuilt devices, like timer interrupts; or by the interfaced devices, they are
called the hardware interrupts. If the interrupts are generated by a piece of code, they are termed
as software interrupts.
The 8051 controller has six hardware interrupts of which five are available to the programmer.
1. RESET Interrupt - This is also known as Power on Reset (POR). When the RESET interrupt
is received, the controller restarts executing code from 0000H location. This is an interrupt which
is not available to or, better to say, need not be available to the programmer.
2. Timer interrupts - Each Timer is associated with a Timer interrupt. A timer interrupt notifies
the microcontroller that the corresponding Timer has finished counting. Therefore these are two
interrupts for the timers.
27
3. External interrupts - There are two external interrupts EX0 and EX1 to serve external
devices. Both these interrupts are active low. In AT89C51, P3.2 (INT0) and P3.3 (INT1) pins are
available for external interrupts 0 and 1 respectively. An external interrupt notifies the
microcontroller that an external device needs its service.
4. Serial interrupt - This interrupt is used for serial communication. When enabled, it notifies
the controller whether a byte has been received or transmitted.
Figure 7.8
The interrupts must be enabled by software in order for the microcontroller to respond to them.
Interrupt Enable Register- There is a register called IE (interrupt enable) that is responsible for
enabling(unmasking) and disabling (masking) theinterrupts.
EA
--------
ET2
ES
ET1
EX1
ET0
EX0
Figure 7.9
To enable any of the interrupts, first the EA bit must be set to 1. After that the bits
EA bit acts as a lock bit. If any of the interrupt bits are enabled but EA bit is not set, the interrupt
will not function. By default all the interrupts are in disabled mode.
28
TOPIC 8
INTERFACING DEVICES WITH 8051 MICROCONTROLLER
8.1 LED INTERFACING
Interfacing an LED with 8051 is easy. The I/O pins are used as output pins. When any of the bit
is set to 1, the LED glows if LED n side is connected to ground and p side with bit. And if p side
is connected to power and n side to bit, then on bit low, the LED glows.
CodeORG 0000h
loop:
CLR P2.0
CALL DELAY
SETB P2.0
CALL DELAY
JMP loop
delay:
mov R7,#100
L1_delay: djnz r7, L1_delay
Ret
29
Figure 8.1
Figure 8.2
30
CodeORG 000H
START: MOV A, #00001001B
MOV B, A
MOV R0, #0AH
LABEL: MOV A, B
INC A
MOV B,A
MOVC A,@A+PC
MOV P1, A
ACALL DELAY
DEC R0
MOV A, R0
JZ START
SJMP LABEL
DB 3FH
DB 06H
DB 5BH
DB 4FH
DB 66H
DB 6DH
DB 7DH
DB 07H
DB 7FH
DB 6FH
DELAY: MOV R4,#05H
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET
END
31
Figure 8.3
32
Code-
Figure 8.4
33
Figure 8.5
Figure 8.6
CodeORG 00H // initial starting address
MAIN: MOV P1,#00000001B // motor runs clockwise
ACALL DELAY // calls the 1S DELAY
MOV P1,#00000010B // motor runs anti clockwise
ACALL DELAY // calls the 1S DELAY
SJMP MAIN // jumps to label MAIN for repaeting the cycle
DELAY: MOV R4,#0FH
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
34
RET
END
BIBILOGRAPHY
I.
II.
III.
IV.
V.
VI.
VII.
ENGINEERSGARAGE.COM
WIKIPEDIA.ORG
ATMEL.COM
DATASHEETS.COM
CIRCUITSTODAY.COM
PDFs FROM VARIOUS SITES
GOOGLE.COM
35