Академический Документы
Профессиональный Документы
Культура Документы
Dr. M. Gopikrishna
Syllabus
Introduction to microcontrollers and Embedded systems - comparison of microprocessors and microcontrollers - The 8051 architecture - Register set - of 8051 - important operational features - I/O pins, ports and
circuits - external memory - counters and timers interrupts - Instruction set of 8051 - Basic programming
concepts - Applications of microcontrollers - (basic ideas) Embedded systems(basic ideas)
1 Embedded Systems
An embedded system is a system that has embedded software and computer hardware which makes it
a system dedicated for an application(s) or specific part of an application or product or part of a larger
system.
1. It embeds hardware similar to a computer. Its software is usually embedded in the ROM or Flash memory.
2. It embeds main application software. The application software may concurrently perform a series of
tasks or processes or threads.
3. It embeds a real-time operating system (RTOS) that supervises the application software running on hardware and organizes access to a resource according to the priorities of tasks in the system. It provides a
mechanism to let the processor run a process as scheduled and context switch between the various processes.
4. The heart of an embedded system is the processor used. Microprocessor and Microcontrollers are widely
used in embedded system products
Figure 1 shows the schematic of an embedded system.
2 Microprocessor
A microprocessor, as the term has come to be known, is a general purpose digital computer central processing unit (CPU). Although popularly known as a computer on chip, the microprocessor is in no sense a
complete digital computer.
The block diagram of a microprocessor CPU is shown in Figure 3(a). It comprises of a ALU, a program
counter (PC), a stack pointer (SP), some working registers, a clock timing circuit and interrupt circuit.
Dr. M. Gopikrishna
Dept. of Physics, Maharajas College, Ernakulam 682 011, e-mail: gopiikrishna@gmail.com
Dr. M. Gopikrishna
The prime use of a microprocessor is to read data, perform extensive calculations on the data and store
those calculations in a mass storage device or display the results for human use. To make a complete
microcomputer, one must add, to the above configuration, memory (ROM and RAM), memory decoders,
an oscillator and a number of I/O devices such as parallel and serial data ports. In addition, special purpose
devices such as interrupt handlers and counters may be added to relieve the CPU from time consuming
counting or chores.
3 Microcontroller
Figure 3(b) shows a typical microcontroller, which is a true computer on a chip. The design incorporates
all of the features found in a microprocessor CPU: ALU, PC, SP and registers. It also has added the other
features needed to make a complete computer: ROM, RAM, parallel I/O, Serial I/O, counters and a clock
circuit.
Like a microprocessor, a microcontroller is a general purpose device, but one that is meant to read data,
perform limited calculations on the data and control its environment based on those calculations. The prime
use of a microcontroller is to control the operation of a machine using a fixed program that is stored in ROM
and that does not change over the lifetime of the system.
Microprocessor
Microcontroller
Microprocessor is a general purpose device which A dedicated chip which is also called a single chip
is called a CPU
computer
Do not contain on-chip I/O ports, timers, memo- Includes RAM, ROM, serial and parallel interface,
ries etc.
timers, interrupt circuitry (in addition to CPU) in
a single chip
Most commonly used as CPU in computer sys- Used in small minimum component designs pertems
forming control oriented operations
Microprocessor instructions are mainly nibble or Both bit addressable as well as byte addressable
byte addressable
Instruction sets are mainly intended for catering to Have instructions sets catering to the control of
large volumes of data
inputs and outputs
4 8051 Microcontroller
The 8051 is a very popular 8-bit microcontroller introduced by Intel in the year 1981 and it has become almost the academic standards now-a-days. The 8051 is based on 8-bit CISC core with Harvard architecture.
Its 8-bit architecture is optimized for control applications with extensive Boolean processing. It is available
as a 40 pin DIP chip and works at +5V DC. Figure 4 shows the usual CPU components of 8051: ALU,
Program Counter and Working Registers.
Dr. M. Gopikrishna
The first 128 bytes of internal memory is organized as shown in Figure 6, and is referred to as Internal
RAM, or IRAM.
Dr. M. Gopikrishna
Dr. M. Gopikrishna
4.2.12 Accumulator
This is the conventional accumulator that one expects to find in any computer, which is used to the hold
result of various arithmetic and logic operations. Since the 8051 microcontroller is just an 8-bit device, the
accumulator is, as expected, an 8 bit register.
The accumulator, referred to as ACC or A, is usually accessed explicitly using instructions such as:
INC A ; Increment the accumulator
However, the accumulator is defined as an SFR register at address E0h. So the following two instructions
have the same effect:
MOV A, 52h ; Move immediate the value 52h to the accumulator
MOV E0h, 52h ; Move immediate the value 52h to Internal RAM location E0h, which is, in fact, the
accumulator SFR register.
Usually the first method, MOV A, 52h, is used as this is the most conventional (and happens to use less
space, 2 bytes as oppose to 3 bytes!)
10
Dr. M. Gopikrishna
4.2.13 B Register
The B register is an SFR register at addresses F0h which is bit-addressable. The B register is used in two
instructions only: i.e. MUL (multiply) and DIV (divide). The B register can also be used as a generalpurpose register.
11
for the time delay is the crystal frequency of the 8051. When C/T = 1, the counter is set to count pulses
from external input pins (T1 or T0)
GATE : Every timer has a means of starting and stopping. Some timers do this by software, some by
hardware and some have both software and hardware.
The start and stop of the timer are controlled by way of software by the TR (Timer Start) bit TR0 and
TR1 in the TCON (Timer Control) register. The SETB instruction starts it and is stopped by CLR instruction.
Eg:
SETB TR1
CLR TR1
SETB TR0
CLR TR0
These instructions start and stop the timers as long as GATE = 0 in the TMOD register. The hardware
way of starting and stopping the timer by an external source is achieved by making GATE = 1 in the TMOD
register.
TCON is an 8 bit register. The upper four bits are used to store the TF (Timer / Counter Overflow) and
TR (Timer start) bits for both Timer 0 and Timer 1. The lower four bits are set aside for controlling the
12
Dr. M. Gopikrishna
interrupt bits. TCON register is a bit addressable register. i.e., instead of using instructions such as SETB
TR1 and CLR TR1, we could use SETB TCON.6 and CLR TCON.6.
TF1 - is the Timer / Counter overflow flag. When the Timer/ Counter overflow, TF1 goes to logic 1.
TR1 - Timer 1 run control bit. Set/ cleared by software to turn timer / counter ON/ OFF.
TF0 - Timer 0 overflow flag. Set by hardware when the timer/ counter 0 overflows.
TR0 - Timer 0 run control bit. Set/ cleared by software to run timer/ control ON/ OFF.
IE1 External Interrupt 1 Edge Flag. Set by hardware when the external interrupt edge is detected.
Cleared by hardware when the interrupt is processed.
IT1 - External Interrupt 1 signal type control bit. Set/ cleared by software. Specified by falling edge/ low
level triggered external interrupt.
IE0 External Interrupt 0 Edge Flag. Set by hardware when external interrupts edge is detected. Cleared
by hardware when the interrupt is processed.
IT0 - External Interrupt 0 signal type control bit. Set/ cleared by software. Specified by falling edge/ low
level triggerd external interrupt.
4.4 Interrupts
A computer program has only two ways to determine the conditions that exist in internal and external circuits. One method uses software instructions that jump to subroutines on the states of flags and port pins.
The second method responds to hardware signals, called interrupts that force the program to call a subroutine. Software techniques uses up processor time that could be devoted to other tasks. Interrupts take
processor time only when action by the program is needed.
Interrupts may be generated by internal chip operations or provided by external sources. Five interrupts
are provided in the 8051. Three of these are generated automatically by internal operations; Timer Flag 0,
timer Flag 1 and the serial port interrupt (RI or TI). Two interrupts are triggered by external signals provided
by circuitry that is connected to pins INT 0 and INT 1 (port pins P3.2 and P3.3)
All interrupt functions are under the control of the program. The programmer is able to alter the control
bits in the Interrupt Enable (IE) register, the Interrupt Priority (IP) register and the TCON register.
Bits in the IE register are set to 1 if the corresponding interrupt source is to be enabled and set to 0 to
disable interrupt source.
Register IP bits determine if any interrupt is to have a high or low priority. Bits set to 1 give the accompanying interrupt a high priority; a 0 assigns a low priority. Interrupts with high priority can interrupt another
interrupt with low priority; the lower priority interrupt continues after the higher is finished.
13
4.5.1 SBUF
For a byte of data to be transferred via the TxD line, it must be placed in the SBUF register. Similarly,
SBUF holds the byte of the data when it is received by the 8051s RxD line. SBUF can be accessed like any
other register in the 8051. The moment a byte is written in to SBUF, it is framed with the start and stop bits
and transferred serially via the TxD pin. Similarly, when the bits are received serially via RxD, the 8051
deframes it by eliminating the stop and start bits, making bits out of the data received and then placing it in
the SBUF.