8051 timer counter
Introduction
TMOD Register
TCON Register
Modes of Operation
Counters
The microcontroller 8051 has two 16 bit Timer/ Counter registers namely Timer 0 (T0) and Timer 1 (T1) .
When used as a “Timer” the microcontroller is programmed to count the internal clock pulse.
When used as a “Counter” the microcontroller is programmed to count external pulses.
Maximum count rate is 1/24 of the oscillator frequency.
Time delay programs and assembler directives 8086Dheeraj Suri
Instructor's slides for writing time delay programs in 8086 microprocessor. Also an introduction to assembler directives and their advantage in writing assembly language programs.
8051 timer counter
Introduction
TMOD Register
TCON Register
Modes of Operation
Counters
The microcontroller 8051 has two 16 bit Timer/ Counter registers namely Timer 0 (T0) and Timer 1 (T1) .
When used as a “Timer” the microcontroller is programmed to count the internal clock pulse.
When used as a “Counter” the microcontroller is programmed to count external pulses.
Maximum count rate is 1/24 of the oscillator frequency.
Time delay programs and assembler directives 8086Dheeraj Suri
Instructor's slides for writing time delay programs in 8086 microprocessor. Also an introduction to assembler directives and their advantage in writing assembly language programs.
In communication system, intersymbol interference (ISI) is a form of distortion of a signal in which one symbol interferes with subsequent symbols. This is an unwanted phenomenon as the previous symbols have similar effect as noise, thus making the communication less reliable.
In communication system, the Nyquist ISI criterion describes the conditions which when satisfied by a communication channel (including responses of transmit and receive filters), result in no intersymbol interference(ISI). It provides a method for constructing band-limited functions to overcome the effects of intersymbol interference.
FellowBuddy.com is an innovative platform that brings students together to share notes, exam papers, study guides, project reports and presentation for upcoming exams.
We connect Students who have an understanding of course material with Students who need help.
Benefits:-
# Students can catch up on notes they missed because of an absence.
# Underachievers can find peer developed notes that break down lecture and study material in a way that they can understand
# Students can earn better grades, save time and study effectively
Our Vision & Mission – Simplifying Students Life
Our Belief – “The great breakthrough in your life comes when you realize it, that you can learn anything you need to learn; to accomplish any goal that you have set for yourself. This means there are no limits on what you can be, have or do.”
Like Us - https://www.facebook.com/FellowBuddycom
Digital signal Processing all matlab code with Lab report Alamgir Hossain
Digital signal processing(DSP) laboratory with matlab software....
Problem List :
1.To write a Matlab program to evaluate the impulse response of the system.
2.Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum.
3.To Generate continuous time sinusoidal signal, discrete time cosine signal.
4.To find the DFT / IDFT of given signal.
5.Program for generation of Sine sequence.
6.Program for generation of Cosine sequence.
7. Program for the generation of UNIT impulse signal
8. Program for the generation of Exponential signal.
This presentation covers:
Some basic definitions & concepts of digital communication
What is Phase Shift Keying(PSK) ?
Binary Phase Shift Keying – BPSK
BPSK transmitter & receiver
Advantages & Disadvantages of BPSK
Pi/4 – QPSK
Pi/4 – QPSK transmitter & receiver
Advantages of Pi/4- QPSK
Convolution codes - Coding/Decoding Tree codes and Trellis codes for multiple...Madhumita Tamhane
In contrast to block codes, Convolution coding scheme has an information frame together with previous m information frames encoded into a single code word frame, hence coupling successive code word frames. Convolution codes are most important Tree codes that satisfy certain additional linearity and time invariance properties. Decoding procedure is mainly devoted to correcting errors in first frame. The effect of these information symbols on subsequent code word frames can be computed and subtracted from subsequent code word frames. Hence in spite of infinitely long code words, computations can be arranged so that the effect of earlier frames, properly decoded, on the current frame is zero.
The Presentation includes Basics of Non - Uniform Quantization, Companding and different Pulse Code Modulation Techniques. Comparison of Various PCM techniques is done considering various Parameters in Communication Systems.
In communication system, intersymbol interference (ISI) is a form of distortion of a signal in which one symbol interferes with subsequent symbols. This is an unwanted phenomenon as the previous symbols have similar effect as noise, thus making the communication less reliable.
In communication system, the Nyquist ISI criterion describes the conditions which when satisfied by a communication channel (including responses of transmit and receive filters), result in no intersymbol interference(ISI). It provides a method for constructing band-limited functions to overcome the effects of intersymbol interference.
FellowBuddy.com is an innovative platform that brings students together to share notes, exam papers, study guides, project reports and presentation for upcoming exams.
We connect Students who have an understanding of course material with Students who need help.
Benefits:-
# Students can catch up on notes they missed because of an absence.
# Underachievers can find peer developed notes that break down lecture and study material in a way that they can understand
# Students can earn better grades, save time and study effectively
Our Vision & Mission – Simplifying Students Life
Our Belief – “The great breakthrough in your life comes when you realize it, that you can learn anything you need to learn; to accomplish any goal that you have set for yourself. This means there are no limits on what you can be, have or do.”
Like Us - https://www.facebook.com/FellowBuddycom
Digital signal Processing all matlab code with Lab report Alamgir Hossain
Digital signal processing(DSP) laboratory with matlab software....
Problem List :
1.To write a Matlab program to evaluate the impulse response of the system.
2.Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum.
3.To Generate continuous time sinusoidal signal, discrete time cosine signal.
4.To find the DFT / IDFT of given signal.
5.Program for generation of Sine sequence.
6.Program for generation of Cosine sequence.
7. Program for the generation of UNIT impulse signal
8. Program for the generation of Exponential signal.
This presentation covers:
Some basic definitions & concepts of digital communication
What is Phase Shift Keying(PSK) ?
Binary Phase Shift Keying – BPSK
BPSK transmitter & receiver
Advantages & Disadvantages of BPSK
Pi/4 – QPSK
Pi/4 – QPSK transmitter & receiver
Advantages of Pi/4- QPSK
Convolution codes - Coding/Decoding Tree codes and Trellis codes for multiple...Madhumita Tamhane
In contrast to block codes, Convolution coding scheme has an information frame together with previous m information frames encoded into a single code word frame, hence coupling successive code word frames. Convolution codes are most important Tree codes that satisfy certain additional linearity and time invariance properties. Decoding procedure is mainly devoted to correcting errors in first frame. The effect of these information symbols on subsequent code word frames can be computed and subtracted from subsequent code word frames. Hence in spite of infinitely long code words, computations can be arranged so that the effect of earlier frames, properly decoded, on the current frame is zero.
The Presentation includes Basics of Non - Uniform Quantization, Companding and different Pulse Code Modulation Techniques. Comparison of Various PCM techniques is done considering various Parameters in Communication Systems.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
CFD analysis is incredibly effective at solving mysteries and improving the performance of complex systems!
Here's a great example: At a large natural gas-fired power plant, where they use waste heat to generate steam and energy, they were puzzled that their boiler wasn't producing as much steam as expected.
R&R and Tetra Engineering Group Inc. were asked to solve the issue with reduced steam production.
An inspection had shown that a significant amount of hot flue gas was bypassing the boiler tubes, where the heat was supposed to be transferred.
R&R Consult conducted a CFD analysis, which revealed that 6.3% of the flue gas was bypassing the boiler tubes without transferring heat. The analysis also showed that the flue gas was instead being directed along the sides of the boiler and between the modules that were supposed to capture the heat. This was the cause of the reduced performance.
Based on our results, Tetra Engineering installed covering plates to reduce the bypass flow. This improved the boiler's performance and increased electricity production.
It is always satisfying when we can help solve complex challenges like this. Do your systems also need a check-up or optimization? Give us a call!
Work done in cooperation with James Malloy and David Moelling from Tetra Engineering.
More examples of our work https://www.r-r-consult.dk/en/cases-en/
About
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Technical Specifications
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
Key Features
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface
• Compatible with MAFI CCR system
• Copatiable with IDM8000 CCR
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
Application
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
2. INTRODUCTION TO TIMERS
• 8051 microcontroller have two timers timer 0 and timer 1.These are
16 bit timers, but 8051 is a 8 bit controller so they are referred are
lower byte and higher byte shown below TL0, TH0, TL1,TH1.
• They can be used as either timers to generate time delay or as
counters to count events.
• The required delay is obtained by loading the number machine cycles
into those registers. Normally delay count value will be decremented
in software delay program, but count value will be incremented in
timers. i.e.( means delay count need to be subtracted from max count
value and then timer has to be activated.)
4. TMOD REGISTER
• Both the timers,timer0 and timer 1 use TMOD register to set various
timer operation modes.
• TMOD is an 8 bit register with lower 4 bits set aside for timer 0 and
higher 4 bits for timer 1.
• Lower two bits are used are to set the timer mode and higher 2 bits
specify the operation.
5. TMOD REGISTER
Gate Bit:
• Timer control will be decided through this bit value
• Gate-=0 : indicates that timer can be controlled through program by
TR and TF bit’s in TCON register.
• Bit TR is used to start the timer by making TR=1 and stop the timer by
making TR=0.This is called software control.
• Gate=1: indicates that timer control is done by external source. This is
called hardware control.
6. C/T (Counter/ Timer) Bit:
This bit in the TMOD register is used to decide whether the timer is
used As a delay generator or an event counter.
• If C/T =0, Then timer is working as delay generator
• If C/T=1, Then that timer is working as event counter
TMOD REGISTER
7. M1, M0:
• These two bits are used to select different timer modes. The below
table 1 shows the different modes.
TMOD REGISTER
8. Indicate which mode and which timer/counter are
selected for each of the following
a) MOV TMOD,#01h TMOD=00000001H,mode 1 timer 0 is selected.
b) MOV TMOD,#20h TMOD=00100000H,mode 2 ,timer 1 is selected.
c) MOV TMOD,#69h TMOD=01101001,counter1 is selected with mode2
and software gating control. Timer 0 is selected with mode1 and gating
control is through external
9. TIMER MODE-1 PROGRAMMING
• Load the TMOD register value indicating which timer (timer 0 or timer 1) is
to be used and which timer mode (0 or 1) is selected.
• Load registers TL and TH with initial count value. Since it’s a 16 bit timer
values from 0000h to FFFFh can be loaded into timer register.
• Start the timer using “SETB TR0” and “SETB TR1” for timer0 and timer1
respectively.
• Keep monitoring the timer overflow flag (TF) with the “JNB TFx, target
“instruction to check if it is raised.
• Stop the timer using “CLR TR0” and “CLR TR1” instructions for timer0 and
timer1 respectively.
• Clear the TF flag for the next round.
• Go back to Step 2 to load TH and TL again
11. Example 1: In the following program, we create a square wave of 50%
duty cycle (with equal portions high and low) on the P1.5 bit. Timer 0 is
used to generate the time delay. Analyze the program.
MOV TMOD,#01 Timer 0, mode 1(16-bit mode)
HERE: MOV TL0,#0F2H TL0=F2H, the low byte
MOV TH0,#0FFH TH0=FFH, the high byte
CPL P1.5 toggle P1.5 to create a square wave.
ACALL DELAY call a delay subroutine
SJMP HERE
DELAY: SETB TR0 start the timer 0
AGAIN: JNB TF0,AGAIN monitor timer flag 0 until it rolls over
CLR TR0 stop timer 0
CLR TF0 clear timer 0 flag
RET Return from subroutine.
12. DELAY CALCULATION
• The timer works with a clock frequency of 1/12 of the XTAL frequency; therefore,
we get 11.0592 MHz / 12 = 921.6 kHz as the timer frequency.
• So each clock has a period of T = 1/921.6kHz = 1.085us. Delay = number of counts
× 1.085us.
• The number of counts for the roll over is FFFFH – FFF2H = 0DH (13 decimal).
• However, we add one to 13 because of the extra clock needed when it rolls over
from FFFF to 0 and raise the TF flag.
• This gives 14 × 1.085us = 15.19us for half the pulse.
• For the entire period it is T = 2 × 15.19us = 30.38us as the time delay generated
by the timer.
• The count to be loaded can be calculated using the formula Initial count value=
[Maximum value – Required delay *crystal freq/12]
13. Find the delay generated in the following
program.
CLR P2.3
MOV TMOD,#01
HERE: MOV TL0,#3EH
MOV TH0, #0B8H
SETB P2.3
SETB TR0
AGAIN: JNB TF0, AGAIN
CLR TR0
CLR TF0
CLR P2.3
17. Finding values to be loaded into timer
• Divide the desired time delay by 1.0856us
• Perform 65536-n, where n is the decimal value from first step.
• Convert the result from step 2 to hexadecimal , where yyxx is the
initial value to be loaded.
• Set TL = xx, TH = yy.
18. Assume crystal frequency = 11.059Mhz.What value is to be loaded to timer register
if we want delay of 5ms? Show the program for timer 0 to create a pulse width of
5ms on P2.3.
• Calculation :
XTAL = 11.0592Mhz , Delay =5ms
-- 5ms/1.085us = 4608 clocks
-- 65536-4608= EE00H.
-- therefore, TH = EEh, TL = 00h
20. Generate a square wave with ON time of 3ms and
OFF time of 10ms on port0. Assume XTAL=22Mhz
MOV TMOD, #01H
BACK: MOV TL0, #075H
MOV TH0, #0B8H
MOV P0, #00H
ACALL DELAY
MOV TL0,#8AH
MOV TH0, #0EAH
MOV P0, #0FFH
ACALL DELAY
SJMP BACK
ORG 300H
DELAY: SETB TR0
AGAIN: JNB TF0, AGAIN
CLR TR0
CLR TF0
RET
END
OFF time = 10ms/0.546 = 18315 cycles.
65536-18315=47221=B875h
21. TIMER-MODE 2 PROGRAMMING
• It is an 8-bit timer, therefore allows only values of 00 to FFh to be
loaded to timer register TH.
• After TH is loaded with 8-bit value, 8051 copies it to TL. Then timer is
started . Done by SETB TR0/TR1.
• After timer is started it starts to count up by incrementing TL register.
• Once it reaches FFh and rolls to 00, TF flag is set high.
• When TL rolls over from FF to 0, TF is set high and TL is automatically
reloaded with original value kept by TH register. To repeat we just
have to clear TF. This auto-reload.
23. STEPS FOR MODE-2 PROGRAMMING
1. Load the TMOD value register indicating which timer (timer 0 or
timer 1) is to be used, and the timer mode (mode 2) is selected.
2. Load the TH registers with the initial count value.
3. Start timer.
4. Keep monitoring the timer flag (TF) with the JNB TFx, target
instruction to see whether it is raised .Get out of the loop when TF
goes high
5. Clear the TF flag.
6. Go back to Step4; since mode 2 is auto reload.
24. Assume XTAL = 11.0592 MHz, find the frequency of the square wave
generated on pin P1.0 in the following program. Also find the smallest
achievable frequency in this program and TH value to do that.
ORG 00H
MOV TMOD,#20H ;T1/8-bit/auto reload
MOV TH1,#5; TH1 = 5
SETB TR1 start the timer 1
BACK: JNB TF1,BACK till timer rolls over
CPL P1.0 Create square wave
CLR TF1 clear Timer 1 flag
SJMP BACK Since mode 2 is auto-reload jump to label back to monitor the overflow flag .
END
25. SOLUTION
Now (256 - 05) × 1.085 us = 251 × 1.085 us = 272.33 us is the high
portion of the pulse. Since it is a 50% duty cycle square wave, the
period T is twice that; as a result T = 2 × 272.33 us = 544.67 us
Frequency (F) = 1.83597 kHz.
26. Write an 8051 ALP to generate a square wave of
frequency 10Khz on pin P1.4.Use timer 0 mode2
with XTAL Frequency=22MHz.
• Time period of square wave =1/f=1/10K=0.1ms Ton=Toff=0.05ms Count
value=256-(0.05m/0.54µ) =256-94 =A4h
ORG 00H
MOV TMOD,#02H
MOV TH0,#0A4H
SETB TR0
BACK: JNB TF0,BACK
CPL P1.4
CLR TF0
SJMP BACK
END
27. Write an 8051 ALP to generate a square wave of
frequency 10Khz on pin P1.4.Use timer 0 mode2
with XTAL Frequency=22MHz.
MOV TMOD, #02H
MOV TH0, #0A4H
SETB TR0
HERE : SET P1.4
BACK: JNB TF0, BACK
CPL P1.4
CLR TF0
SJMP HERE
END
28. Write an 8051 ALP to toggle all bits of port 2
continuously every 50ms.Use timer1 mode2 with
XTAL Freq=11.0592MHz.
Calculation:
• Maximum delay possible in mode 2 is 0.277ms but given is 50ms .So
we have to go for multiple delay count. Take 0.25ms,now to get 50ms
,50ms/0.25ms=200. Count value to be loaded to get 0.25ms delay i.e.,
=256-0.25m/1.085µ =20h or 26 in decimal
30. C PROGRAMMING IN 8051
Write a C program to toggle P1.5 every 50ms. Use Timer 0, mode 1to
create a delay of 50ms.
31. Write a C program to toggle P1.5 every 50ms. Use
Timer 0, mode 1 to create a delay of 50ms.
# include<reg51.h>
void T0M1delay(void);
Sbit mybit = P1^5;
void main(void)
{ while(1)
{ mybit = ~mybit;
T0M1delay();
}
}
32. Write a C program to toggle P1.5 every 50ms. Use
Timer 0, mode 1 to create a delay of 50ms.
void T0M1 delay(void)
{
TMOD = 0X01;
TL0 = 0XFD;
TH0 = 0X4B;
TR0 = 1;
while(TF0==0)
TR0 = 0;
TF0 = 0;
}
33. A switch is connected to pin P1.2.Write an 8051 C program to monitor
SW and create the following frequencies on pin P1.7:
SW=0:500Hz SW=1:750Hz.Use timer 0, mode1.
For 500Hz-count value to be loaded-FC67h
For 750 Hz-count value to be loaded-FD9Ah
38. BASICS OF SERIAL COMMUNICATION
• Computer transfers data in two ways parallel and serial.
• In parallel data transfer often 8 or more lines are used to transfer data
to a device.
• Examples of parallel data transfer are printer and hard disk using
cable wire strips. A lot of data can be transferred within short time
but distance cannot be great.
• To transfer to a device located many meters away serial
communication is used.
• In serial data is sent one bit at a time , in parallel data is sent in bytes.
39.
40. INTRODUCTION
• When a processor communicates with outside world provides data in
byte sized chunks.
• In case of printers information can be grabbed and presented. But if
cable is not too long, it can diminish and distort the signals.
• For transferring data between two systems located far away serial
communication is used.
• In serial communication there are two methods synchronous and
asynchronous. Synchronous method transfer block of data at a time
while asynchronous transfer single byte at a time.
• For serial communication parallel-in-serial-out and serial-in-parallel-
out registers must be used.
41. HALF AND FULL-DUPLEX
• In data transmission if data can be transmitted and received, it is
duplex transmission.
• In printers we use simplex transmission only computer sends data.
• Duplex transmission can be full duplex or half duplex depending on
whether data is passed simultaneously.
• If data is transmitted one way it is half or else full duplex.
42.
43. ASYNCHRONOUS SERIAL COMMUNICATION AND DATA FRAMING
• Data coming in at the receiving end is all 0’s and 1’s both sender and
receiver should agree on a set of protocols.
• Start and stop bits:
Asynchronous serial data communication is widely used for character
oriented method while block oriented is used for synchronous method.
In asynchronous each character is placed between start and stop. This
is called framing.
The start bit is always low and stop bit is high. LSB is sent out first.
44.
45. ASYNCHRONOUS SERIAL COMMUNICATION AND DATA FRAMING
• In modern PC, use of stop bit is standard ASCII character use stop bit,
total 10 bits gives 20% overhead.
• Some of the system include parity bit. Parity is calculated including
parity bit.
46. DATA TRANSFER RATE
• The rate of data transfer in serial data communication is bits per
second (bps) another widely used term is baud rate.
• In modem technology it is defined as number of signal
changes/second.
• If a serial port has 9600 baud , then serial port is capable of
transferring max 9600 bits per second.
47. RS232
• To allow compatibility among data communication equipment made
by various manufactures, an interfacing standard called RS232 was set
by the Electronics Industries Association (EIA) in 1960.
• The standard was set long before the advent of logic family, so its
input and output voltage levels are not TTL compatible.
• In RS232, a logic one (1) is represented by -3 to -25V and referred as
MARK while logic zero (0) is represented by +3 to +25V and referred
as SPACE.
• To connect any RS232 to a microcontroller system voltage converters
such as MAX232 to convert the TTL logic level to RS232 voltage levels
and vice-versa are used. MAX232 IC chips are commonly referred as
line drivers.
50. DATA COMMUNICATION CLASSIFICATION
• DTE (data terminal equipment) refers to terminal and computers that
send and receive data.
• DCE (data communication equipment) refers to communication
equipment, such as modems.
• The simplest connection between a PC and microcontroller requires a
minimum of three pins, TxD, RxD, and ground.
51. RS232 HANDSHAKING SIGNALS
To ensure fast and reliable communication data transfer must be
coordinated.
• DTR (data terminal ready): When terminal is turned on, it sends out
signal DTR to indicate that it is ready for communication.
• DSR (data set ready): When DCE is turned on and has gone through
the self-test, it assert DSR to indicate that it is ready to communicate.
• RTS (request to send) When the DTE device has byte to transmit, it
assert RTS to signal the modem that it has a byte of data to transmit.
• CTS (clear to send): When the modem has room for storing the data
it is to receive, it sends out signal CTS to DTE to indicate that it can
receive the data now .
52. RS232 HANDSHAKING SIGNALS
• 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.
• RI (ring indicator): An output from the modem and an input to a PC
indicates that the telephone is ringing.It goes on and off in
synchronous with the ringing sound
53. 8051 CONNECTION TO RS232
• The 8051 has two pins that are used specifically for transferring and
receiving data serially. These two pins are called TXD, RXD. Pin 11 of
the 8051 (P3.1) assigned to TXD and pin 10 (P3.0) is designated as
RXD.
• These pins TTL compatible; therefore they require line driver (MAX
232) to make them RS232 compatible.
• MAX 232 converts RS232 voltage levels to TTL voltage levels and vice
versa. One advantage of the MAX232 is that it uses a +5V power
source which is the same as the source voltage for the 8051.
55. 8051 CONNECTION TO RS232
• MAX232 has two sets of drivers for transferring and receiving data.
• Line drivers used as T1 and T2(Txd) and for receiving Rxd(R1 and R2).
• In many applications T1 and R1 are used together , second one is left
unused.
• T1 in pin is TTL side and converted to TXD of MC and T1 out is RS232
converted to RXD pin.
• MAX232 requires 4 capacitors ranging from 1 to 22uf. Most widely
used is 22uf.
56. 8051 SERIAL PORT PROGRAMMING IN ASSEMBLY
• To allow data transfer and between PC and 8051 system without any error
we must make sure baud rate of 8051 and PC port matches.
• Baud rate in 8051: 8051 receives and transfers data serially at different
baud rates.
• 8051 divides the crystal frequency by 12.
• In case of Xtal = 11.0592Mhz then machine cycle= 921.6Khz
• 8051 serial communication UART circuit divides machine cycle of 921.6Khz
by 32 before it is used by timer 1 to set baud rate.
• 921.6khz/21 = 28,800Hz
• This the number used to find TH1 to set baud rate.
• When timer 1 is used to set baud rate it must be programmed in mode 2,8-
bit auto reload.
58. BAUD RATE CALCULATION
With XTAL = 11.0592 MHz, find the TH1 value needed to have the
following baud rates. (a) 9600 (b) 2400 (c) 1200 .
SOLUTION:
The machine cycle frequency of 8051 = 11.0592 / 12 = 921.6 kHz, and
921.6 kHz / 32 = 28,800 Hz is frequency by UART to timer 1 to set baud
rate.
(a) 28,800 / 3 = 9600 where -3 = FD (hex) is loaded into TH1.
(b) 28,800 / 12 = 2400 where -12 = F4 (hex) is loaded into TH1.
(c) 28,800 / 24 = 1200 where -24 = E8 (hex) is loaded into TH1
60. SERIAL CONTROL REGISTER(SCON)
• SM0, SM1 They determine the framing of data by specifying the
number of bits per character and the start and stop bits.
61. SERIAL CONTROL REGISTER(SCON)
• SM2: This enables the multiprocessing capability of the 8051
• REN (receive enable): It is a bit-addressable register When it is high, it
allows 8051 to receive data on RxD pin .If low, the receiver is disable.
• TI (transmit interrupt): When 8051 finishes the transfer of 8-bit character.
It raises TI flag to indicate that it is ready to transfer another byte. TI bit is
raised at the beginning of the stop bit.
• RI (receive interrupt): When 8051 receives data serially via RxD, it gets rid
of the start and stop bits and places the byte in SBUF register. It raises the
RI flag bit to indicate that a byte has been received and should be picked up
before it is lost. RI is raised halfway through the stop bit.
62. SERIAL CONTROL REGISTER(SCON)
• TB8 : Used for serial mode 2&3.
• Rb8 : In serial mode 1, this bit gets a copy of stop bit when 8 bit data
Is received . It is also used in 2 & 3 mode.
63. SERIAL BUFFER REGISTER
• SBUF is a 8-bit register for serial communication in 8051.
• For a byte of data to be transferred via TXD line, it must be placed in
SBUF register.
• Similarly SBUF holds the byte of data when it is received by 8051 via
RXD line.
• Eg: MOV SBUF, #’D’
• MOV SBUF, A
64. SERIAL PROGRAMMING IN ASSEMBLY
STEPS:
• The TMOD register is loaded with the value 20H, indicating the use of the
Timer 1 mode 2 (8-bit auto reload) to set the baud rate.
• The TH1 is loaded with one of the values in table 5.1 to set the baud rate
for serial data transfer.
• The SCON register is loaded with the value 50H, indicating serial mode 1,
where an8-bit data is framed with start and stop bits.
• TR1 is set to 1 start timer 1.
• TI is cleared b the “CLR TI” instruction.
• The character byte to be transferred serially is written into the SBUF
register.
• The TI flag bit is monitored with the use of the instruction JNB TI, target to
see if the Character has been transferred completely.
• To transfer the next character, go to step 5
65. IMPORTANCE OF TI FLAG
• The byte character to be transferred is written into SBUF.
• Start bit is transferred.
• 8-bit is transferred one at a time.
• Stop bit is transferred. It is during this transfer of stop bit 8051 raises
TI flag indicating last character, ready to transfer next character.
• By monitoring TI Flag, we make sure we are not overloading SBUF.
• If we write another byte into SBUF before TI is raised , untransmitted
portion of previous byte will be lost.
• After SBUF is loaded with a new byte TI must be forced ‘0’ by CLR TI in
order for new byte to be transferred.
66. PROGRAMMING 8051 TO RECEIVE DATA SERIALLY
• The TMOD register is loaded with the value 20H, indicating the use of
the Timer 1 imode 2 (8-bit auto reload) to set the baud rate.
• The TH1 is loaded with one of the values in table 5.1 to set the baud
rate for serial data transfer.
• The SCON register is loaded with the value 50H, indicating serial
mode 1, where an8-bit data is framed with start and stop bits.
• TR1 is set to 1 start timer 1.
• RI is cleared by the “CLR RI” instruction.
• RI is monitored with “JNB RI, XX”
• When RI is raised , SBUF has byte contents are moved to safe place.
• To receive next character , go to step 5.
67. IMPORTANCE OF RI FLAG
• It receives the start bit indicating that next bit is the first bit of
character.
• 8-bit is received one at a time.
• Stop bit is received . When receiving RI=1, indicating that entire
character byte has been received and must be picked before
overwriting.
• By checking RI, a character is received copy SBUF to safe place.
• After copying RI is forced to ‘0’ by CLR RI, to allow next instruction.
68. Write an 8051 ALP to receive data serially and put
them in P1. Set the baud rate as 4800, 8bit data,
1stop and start bit.
69. Write an 8051 ALP to receive data serially and put
them in P1. Set the baud rate as 4800, 8bit data,
1stop and start bit.
MOV TMOD,#20H
MOV TH1,#-6
MOV SCON,#50H
SETB TR1
HERE: JNB RI,HERE
MOV A, SBUF
MOV P1,A
CLR RI
SJMP HERE
70. WRITE A PROGRAM TO TRANSFER ‘Y’ SERIALLY AT
9600 baud , also ‘N’ through PORT 0 Connected to
Device.
• Here one byte of data is transmitted serially through pin 11(p3.1) and
another parallel form.
8051
DISPLAY
‘Y’
P3.1
‘N’
P0
71. PROGRAM
MOV TMOD, #20H
MOV TH1, #-3
MOV SCON, #50H
SETB TR1
Again: MOV SBUF, #’Y’
HERE: JNB TI, HERE
CLR TI
MOV P0, #’N’
SJMP Again
72. Take data in ports 0,1,2 one after the other
and transfer data serially
MOV TMOD, #20H
MOV TH1, -6
MOV SCON, #50H
MOV P0, #0FFH
MOV P1, #0FFH
MOV P2, #0FFH
SETB TR1
73. Continued
rpt : MOV A, P0
ACALL SEND
MOV A, P1
ACALL SEND
MOV A , P2
ACALL SEND
SJMP rpt
SEND: MOV SBUF, A
HERE: JNB T1, HERE
CLR TI
RET
74. Write an ALP to implement following operation do a once, and b & c continuously
4800 baud rate. a. Send to the PC message “we are ready ’ b. Receive an data sent b
PC and put it on LED’s connected to P1 c. Get data on switches connected to P2 and
send to PC