Esoit Unit 1 Last Part
Esoit Unit 1 Last Part
Systems
1.62 and loy
P3.2 - INTO
P3.3 - INTI
P3.4 - TO
P3.5 - T1
P3.6 - WR
P3.7 - RD
These pins can be individually programmed.
DO
Serial Transfer
D7
Parallel Transfer
Serial data communication uses two mnethods for transferring data such as
1. Asynchronous
2. Synchronous
The asynchronous method transfers a single byte at a time while synchronous
method transfers a block of data at a time. There are special IC chips available for
serial data communications such as follows.
1. UART - Universal Asynchronous Receiver Transmitter
2. USART - Universal Synchronous-Asynchronous Receiver Transmitter
Types of Transmission
If the data can be transmitted and received, then it is called Duplex transmissior.
It has two types.
1. Half Duplex
2. Full Duplex
Embedded.
1.64| Systems and ic
as Half
is transmitted one way at atime, it is referred to Duplex. If
If data
time, it is full duplex.
the day
can go both ways at the same
Receiver
Transmiter
Transmitter
Receiver
The data can be transferred not yet received. Such transmission is called as
simplex transmission.
Transmitter Receiver
4
Start Mark
Stop 1 0 0 bit
bit
Space
DO
D7 goes out first
goes out last
1 13
25
14
To ensure fast and reliable data transmission between two devices, the data
transfer must be cOordinated. Many of the pins of the RS232 connector are used for
handshaking signals such as follows.
1. DTR (Data Terminal Ready)
When a terminal is turned on,after going through a self-test, it sends out signal
DTRto indicate that it is ready for communication.
If there is something wrong with the COM Port, this signal will not be activated.
This is an active low signal and can be used to inform the modem that the computer
is alive and kicking.
DTR acts as output pin for DTE and input to the modem.
2. DSR (Data Set Ready)
It is an active low signal. When DCE is turned on and gone through the self-test, it
asserts DSR to indicate that it is ready to communicate.
This acts as output pin for DCE and input to DTE. For any reason, the DCE
cannot make a connection to the telephone until this signal remains inactive.
3. RTS (Request To Send)
When the DTE device has a byte to transmit, it asserts RTS to signal the modem
that it has a byte of data to transmit. RTS is an active low output from the DTE and
an input to the modem.
4. CTS (Clear to Send)
In response to RTS, when the modem has room for storing the data it is to receive,
it sends out signalCTS to the DTE to indicate that it can receive the data now. It is
input to the DTE and used by the DTE to start transmission.
5. DCD (Data Carrier Detect)
The modem asserts signal DCD to inform the DTE that a valid carrier has been
detected and that contact between it and the other modem is established.
Embedded. Systems
|1.68 and Ior
6. RI (Ring Indicator)
An output from the modem and an input to a PC indicate that the telephone i
synchronization with the ringing
sound.
ringing. It goes on and off in
compatible.
8051 with RS 232. Because RS 232 is not TTL
MAX232
Voc
16
1
3 2
MAX232 6
c2
5
TiN Tlour
8051 MAX232
11
11 11 14
TXDO
D
R1N Rlout
12 13
10 12 13 3
RXDO
10
T2N T2ouT
R2N R2oUT
TTL
- RS232
side Side
13 11
14 15
12
MAX233 16
|17 20
T1iN TloUT
3 8051 MAX233
RlouT Ri1N
2 5
TXDO
T2N T2OUT
o 18
RXDO
10 3 4 3
20
R2IN R2OUT 19 DB -9
TTL RS232
side side
(a) (b)
Fig. 1.24. (a) MAX 233 and (b) its connection to 8051
The 8051 two registers are used to perform Serial communication. Such registers
are 1. SBUF register 2. SCON register
Embedded. Systems
1.70
and lo
1. SBUF Register
communicationin the 8051. For a
SBUF is an 8 bit register used for serial byte ot
data to be transferred via the TXD line and it must be placed in the SBUF register.
the 8051l's RXD line. SBUF
SBUF holds the byte of data when it is received by
can be accessed like any other register in the 8051.
sCON (SerialControl) Register
The SCON register is an 8 bit register used to programme the start bit, stop bbit and
data bits of data framing. It has following bit format. 0
7
RB8 TI RI
SMO SM1 SM2 REN TB8
This is important flag bit in the SCON register. When the 8051 receives data
serially via RXD, it gets rid of the start and stop bit and places the byte in the SBUF
register.
1.71
8- Bit Embedded Processor
TI (Transmit Interrupt)
Whenthe 8051 finishes the
This is an important flag bit in the SCON register. indicate that it is ready to
transfer of the 8-bit character, it
raises the TI 1ag to
beginning of the stop bit.
transfer another byte. The TI bit is raised at the
RB8 (Receive bit 8)
stop bit. when an 8-bit data is received.
Inserial mode 1, this bit getsa copy of the
This bit is rapidly used any more.
TB8 (Transfer Bit 8)
It is used for serial modes 2 and 3.
REN (Receive Enable)
on the RXD pin of
When the REN bit is high, it allows the 8051 to receive data
receive data, by
the 8051. If REN = 1, the 8051 will perform both transfer and
making
REN =0 the receiver is disabled.
SM2
These two bits determine the framing of data by specifying the number of bits per
character and the start and stop bits.
SMO SM1
0 Serial Mode 0
0 1 Serial Mode 1, 8-bit data, 1 stop bit, 1 start bit
1 Serial Mode 2
1 1 Serial Mode 3
Programming the 8051 to transfer data serially
The following steps to be taken to transfer character bytes serially.
1. The TMOD register is loaded with the value 20 H, indicating the use of
Timer 1 in mode 2 to set the baud rate.
Embedded. Systems annd
1.72
the values shown in below table
THI is loaded with one of
2. The
data transter.
baud rate for serial
3. The SCON register is loaded withthe value 50H, indicating serial mode
and stop bits.
where an 8-bit data
is framed with start
start timer-1.
4. TRI is set to lto
is cleared by the "CLR TI" instruction.
6.5. ItThe character byte to be transferred serially 1S WTItten into the SEBUF
register. instruction **
monitored with the
use of the JNB TI, xX"
7. The TI flag bit is transferred completely.
character has been
to see if the
character, go to Step ).
8. To transfer the next
Register Values for various Baud Rates
Tablel.2. Timer 1 THI
THI(Decimal) THI(Hex)
Baud Rate
FD
-3
9600 FA
4800 -6
F4
2400 -12
E8
1200 -24
1. InterTupts
2. Polling
device notifies
the interrupt method, whenever any device needs its service, the
In
microcontroller by sending it an interrupt signal. Upon receiving an interrupt
the
doing and serves the device. The
signal, the microcontroller interrupts whatever it is
interrupt service Routine ((SR) or
program associated with the interrupt is called the
interrupt handler.
status of a given
InPolling method, the microcontroller continuously monitors the
device. When the status condition is met, it performs the service. After
that, it moves
can mnonitor the
on to monitor the next device until each one is serviced. Polling
met, it is
status of several devices and serve each of them as certain conditions are
not an efficient use of the microcontroller.
Interrupts Vs Polling
The advantage of interrupt is the microcontroller can serve many devices and each
device can get the attention of the microcontroller based on the priority assigned to it.
The polling method cannot assign priority because it checks all devices in a
round-robin fashion.
In the interrupt method, the microcontroller can also ignore a device request for
service. But this is not possible with the polling method.
The polling method wastes much of the microcontroller time by polling devices
that do not need service. So in order to avoid such things, the interrupt method is
used.
For every interrupt, there must be an interrupt service routine (ISR) or interrupt
handler. When an interrupt is invoked, the microcontroller runs the interrupt service
routine.
Embedded S
1.74| Systems and
memory that holds the
For every interrupt, there is a fixed location in
its ISR. The group of memory locations set to
hold the addresses of ISRs address y
interrupt vector table
called the
1.17.1. SOURCES OF INTERRUPT
interrupts can be
The 8051has five interrupt sources. Each of these
to two priority levels. The interrupt sources are
programmea
Destination
S.No Source
1. INTO External request from P3.2 pin.
2.
Overflow from Timer 0 activates the Interrupt Request
Timer 0
Flag TFO
3. INTI External request from P3.3
4
Overflow from Timer l activates the Interrupt Request
Timer 1
Flag TF1.
5.
Serial Completion of transmission or reception ofa serial frame
port activates the flags T1 or R1.
Each of these interrupt sources can be individually enabled or disabled by sett
or clearing a Interrupt Enable Register (IE).
All these sources can be programmed either to a high priority level or to a
low priority level by setting or clearing the Interrupt Priority Register (IP)
$ Low priority source can be interrupted by another high priority interrupL
But high priority interrupt cannot be interrupted by another high or low
priority interrupt.
Priority of interrupts
Source Priority Level
External interrupt 0 Highest
Timer 0 overflow
External interrupt I
Timer 1 overflow.
Serial port Lowest
|1.75|
Processor
- Bit Embedded cycle and
during cach machine
Scanned
All these interrupts are separately
are prioritized by S6 of any machine cycle.
all the interrupts state of the next
service in the first
go to the interrupt
The process will of the following instructions.
blocked by any
machine cycle. It is not already in progress.
level is
higher priority
1. An interrupt of equal or instruction in
will be responded to until the
request
2. No interrupt
progress is completed.
In this case, the
instruction in progress is RETl or IE or IP.
3 The at least one more
response will come only after executing
instruction.
Response Time
factor in control
to an external interrupt is a very critical
The response time
required.
applications where an immediate action is
three cases or
response time will depend on the above-mentioned
The
conditions.
not blocked by any of the above three conditions, then
Once an interrupt is
processor, after the program
a hardware call is generated internally by the
branches to a predefined location.
Interrüpt Control Registers
registers such as
& The Interrupt Request Flags are in two different
1. IE Interrupt Enable Register.
2. IP Interrupt Priority Register.
External interrupts control bits are in two formats.
ITO in TCON-0
ITI in TCON -2
Control bits are set or cleared by software.
is enabled.
* IfETl =0, timer 1 interrupt is disabled and if ETI = 1, timer intermup
enabled.
If EXI = 0, the External Interrupt is disabled and if EX1 -\,i
enabled.
IfET0 =0, the Timer 0Interrupt is disabled and if ETO =1, it tis enabled,
If EX0 = 0, the External Interrupt 0 is disabled and if EXO = 1, it i
enabled.
D,
TFI TRI TFO
Do
TRO IEI ITI IEO ITO
1.79