Module - 1
Module - 1
Microprocessor vs Microcontroller
Microcontrollers for Embedded Systems
• An embedded product uses a microprocessor (or microcontroller) to do one task and one task only
• o There is only one application software that is typically burned into ROM
• A PC, in contrast with the embedded system, can be used for any number of applications
• o It has RAM memory and an operating system that loads a variety of applications into RAM and lets the CPU
run them
• o A PC contains or is connected to various embedded products
• Each one peripheral has a microcontroller inside it that performs only one task
• Not all of the addresses from 80h to FFh are used for SFRs, and
attempting to use an address that is not defined, or "empty" results in
unpredictable results.
• • SFRs are named in certain opcodes by their functional names, such as A
or TH0, and are referenced by other opcodes by their addresses, such as
0E0h or 8Ch.
• • Note that any address used in the program must start with a number;
thus address E0h for the A SFR begins with 0.
• • Failure to use this number convention will result in an assembler error
when the program is assembled.
Pinout Description
Pins 1-8 PORT 1. Each of these pins can be configured as an input or an
output.
Pin 9 RESET. A logic one on this pin disables the microcontroller and
clears the contents of most registers. In other words, the
positive voltage on this pin resets the microcontroller. By
applying logic zero to this pin, the program starts execution
from the beginning.
Pins10-17 PORT 3. Similar to port 1, each of these pins can serve as
general input or output. Besides, all of them have alternative
functions
Pin 10 RXD. Serial asynchronous communication input or Serial
synchronous communication output.
Pin 11 TXD. Serial asynchronous communication output or Serial
synchronous communication clock output.
Pin 12 INT0.External Interrupt 0 input
Pin 18, 19 XTAL2, XTAL1. Internal oscillator input and output. A quartz crystal
which specifies operating frequency is usually connected to these pins.
Pin 21-28 Port 2. If there is no intention to use external memory then these port
pins are configured as general inputs/outputs. In case external memory
is used, the higher address byte, i.e. addresses A8-A15 will appear on
this port. Even though memory with capacity of 64Kb is not used, which
means that not all eight port bits are used for its addressing, the rest of
them are not available as inputs/outputs.
Pin 29 PSEN. If external ROM is used for storing program then a logic zero (0)
appears on it every time the microcontroller reads a byte from
memory.
Pin 30 ALE. Prior to reading from external memory, the microcontroller puts
the lower address byte (A0-A7) on P0 and activates the ALE output.
After receiving signal from the ALE pin, the external latch latches the
state of P0 and uses it as a memory chip address. Immediately after
that, the ALE pin is returned its previous logic state and P0 is now
used as a Data Bus.
Pin 31 EA. By applying logic zero to this pin, P2 and P3 are used for data and
address transmission with no regard to whether there is internal
memory or not. It means that even there is a program written to the
microcontroller, it will not be executed. Instead, the program written
to external ROM will be executed. By applying logic one to the EA pin,
the microcontroller will use both memories, first internal then
external (if exists).
Pin 32-39 PORT 0. Similar to P2, if external memory is not used, these pins can
be used as general inputs/outputs. Otherwise, P0 is configured as
address output (A0-A7) when the ALE pin is driven high (1) or as data
output (Data Bus) when the ALE pin is driven low (0).
Pin 40 VCC. +5V power supply.
Input/ Output Pins, Ports, and Circuits
Ports can be accessed directly by instructions during program execution
I/O ports are memory mapped, they are treated as memory locations
All ports are bit addressable
Each PIN consists of a D latch, I/P buffer and O/P driver
SFRs for each port is made of 8-latches
The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins
All the ports upon RESET are configured as output, ready to be used as
output ports
o When the first 0 is written to a port, it becomes an output
o 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
External Memory (ROM & RAM)
interfacing
• Eg. Interfacing of 16 K Byte of RAM and 32 K
Byte of EPROM to 8051
• Number of address lines required for 16 Kbyte
memory is 14 lines and that of 32Kbytes of
memory is 15 lines.
The connections of external memory is shown below.
ROM
Timers/Counters are used generally for
Time reference
Creating delay
Wave form properties measurement
Periodic interrupt generation
The 8051 has two timers/counters, they can be
used either as Timers to generate a time delay
or as Event counters to count events happening
outside the microcontroller
8051 has two timers, Timer 0 and Timer 1.
Timer 0 and Timer 1 are 16 bits.
8051 has an 8-bit architecture, each 16-bits
timer is accessed as two separate registers of
low byte and high byte.
The low byte register is called TL0/TL1 and
The high byte register is called TH0/TH1.
Accessed like any other register.
Timer in 8051 is used as timer, counter and baud rate
generator. Timer always counts up irrespective of whether
it is used as timer, counter, or baud rate generator: Timer is
always incremented by the microcontroller. The time taken
to count one digit up is based on master clock frequency.
If Master CLK=12 MHz,
Timer Clock frequency = Master CLK/12 = 1 MHz
Timer Clock Period = 1micro second
This indicates that one increment in count will take 1
microsecond.
The two timers in 8051 share two SFRs (TMOD and
TCON) which control the timers, and each timer also
has two SFRs dedicated solely to itself (TH0/TL0 and
TH1/TL1).
TMOD Register
Both timers 0 and 1 use the same register, called
TMOD (timer mode), to set the various timer
operation modes
TMOD is an 8-bit register
The lower 4 bits are for Timer 0, the upper 4 bits are
for Timer 1
In each case, the lower 2 bits are used to set the
timer mode, the upper 2 bits to specify the operation.
TMOD Register
TCON register
TCON (timer control) register is an 8bit
register
SERIAL COMMUNICATION
• The 8051 microcontroller is parallel device that transfers
eight bits of data simultaneously over eight data lines to
parallel I/O devices.
• Parallel data transfer over a long is very expensive.
Hence, a serial communication is widely used in long
distance communication.
• In serial data communication, 8-bit data is converted to
serial bits using a parallel in serial out shift register and
then it is transmitted over a single data line.
• The data byte is always transmitted with least significant
bit first.
Basics of serial data communication
Communication Links
1. Simplex communication link: In simplex
transmission, the line is dedicated for
transmission. The transmitter sends and the
receiver receives the data.
2. Half duplex communication link: In half
duplex, the communication link can be used for
either transmission or reception. Data is
transmitted in only one direction at a time.
3. Full duplex communication link: If the data
is transmitted in both ways at the same time, it is
a full duplex i.e. transmission and reception can
proceed simultaneously. This communication
link requires two wires for data, one for
transmission and one for reception.
• SCON register
• SM0, SM1:They determine the framing of data by specifying
the number of bits per character, and the start and stop bits