You are on page 1of 92

EMBEDDED SYSTEM

• Special-purpose computer system designed to


perform a dedicated function.

• Performs one or a few pre-defined tasks,


usually with very specific requirements, and
often includes task-specific hardware and
mechanical parts not usually found in a general-
purpose computer.

Advance Tech. India Pvt Ltd


Wireless Communications

Telematics System for Automobiles

Hand-held GPS Units

Y. Williams Csci-339, Spring 2002 20


4
COMPONENT OF EMBEDDED SYSTEM
Analog Components
Sensors (LDR,LM35 etc.)
Digital Components
Processor, Coprocessors
Memories
Controllers, Buses
Application Specific Integrated Circuits
Converters – A2D, D2A, …
Software
Application Programs
Exception Handlers

Advance Tech. India Pvt Ltd


EMBEDDED SYSTEM BLOCK
DIAGRAM
Control
(Output) Motor/Light

System Bus
Observe Temperature
(Input) Sensor
Processor

mem

6
EMBEDDED DESIGN
1. Core hardware

2. Firmware tools

3. Programming tools

4. Hardware tools

Advance Tech. India Pvt Ltd


CORE HARDWARE
• 8051 Microcontroller

• PIC (Peripheral Interface Control ) Microcontroller

• AVR Microcontroller

• ARM (Advance risc machine ) Microcontroller

• ARDUINO (UNO,MEGA,NANO)

• FPGA(Field Programmable Gate Array)

• CPLD(Complex Programmable Logic Device)

Advance Tech. India Pvt Ltd


DESIGN
1. Core hardware

2. Firmware tools

3. Programming tools

4. Hardware tools
Advance Tech. India Pvt Ltd
FIRMWARE TOOLS
• 8051- KEIL Compiler, IAR, Eclipse

• PIC - Mikro C, Mplab

• AVR – Code Vision AVR, AVR Studio, IAR

• ARM - KEIL advanced versions, IAR

Advance Tech. India Pvt Ltd


PROGRAMMING TOOLS
• 8051 – Flash Magic , ECE Flash,SST

• PIC - Matrix pppv3 , pickit2

• AVR – Pony Prog, USBASP

• ARM – Flash Utility

Advance Tech. India Pvt Ltd


WE WILL WORK OVER
1. Core hardware
(8051 MICROCONTROLLER)

2. Firmware tools
KEIL

3. Programming tools (nuvoton)


4. Hardware tools
8051 Board

Advance Tech. India Pvt Ltd


WHAT IS A MICROCONTROLLER?

A microcontroller (sometimes
abbreviated µC or MCU) is a small
computer on a single IC containing
a processor core, memory, and
programmable input/output
peripherals.

Itis a decision making device


used widely in embedded systems
and all intelligent devices.
DIFFERENCE BETWEEN MICROCONTROLLER
AND MICROPROCESSOR
 Microcontroller has I/O ports, Memory, timers etc
all integrated on a single chip itself

 In Microprocessors, I/O ports, memory, timer etc


are to be connected externally
BLOCK DIAGRAM TO SHOW THE
DIFFERENCE
WHAT IS A 8-BIT MICROCONTROLLER?

 8-bit means it can process 8-bit data per clock cycle.


 It has 8-bit data bus.
 It can process 8 bits of data at a time.
KEIL
8051
Micro-controller VCC
Architecture HEX FILE

PROGRAMMER

RESET

LCD
MOTOR MD ROM

MAX CPU`
COMP BUZZER
232

SWITCH
RAM
INTERRUPT
8051 LED

O
GND S
C
8051 Microcontroller Programing

Input file
For
MCU
8051
Microcontroller
Transferring file Compiling &
Using
Suitable medium
Building
Like USB or Of the Code
RS-232cable

Source Code
In
C- Language
Let’s check how to put brain in our
device
8051 BASIC
COMPONENT
 4K bytes internal ROM
 128 bytes internal RAM
 Four 8-bit I/O ports (P0 - P3).
 Two upto16-bit timers/counters
 One serial interface.
 5 interrupts.
COMPARISON

Feature 8051 8052 8031

ROM 4k 8k 0k

RAM 128 byte 256 128

TIMERS 2 3 2

I/O PORT 32 32 32

SERIAL PORT 1 1 1

INTERRUPT 5 8 6
PIN P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
DISCRIPTION P1.2 3 38 P0.1(AD1)
OF P1.3
P1.4
4
5
37
36
P0.2(AD2)
P0.3(AD3)
8051 P1.5 6 35 P0.4(AD4)
P1.6 7 34 P0.5(AD5)
P1.7 8 8051 33 P0.6(AD6)
RST 9 (8031) 32 P0.7(AD7)
(RXD)P3.0 10 (8751) 31 EA
(TXD)P3.1 11 30 ALE
(8951)
(INT0)P3.2 12 29 PSEN
(INT1)P3.3 13 28 P2.7(A15)
(T0)P3.4 14 27 P2.6(A14)
(T1)P3.5 15 26 P2.5(A13)
(WR)P3.6 16 25 P2.4(A12)
(RD)P3.7 17 24 P2.3(A11)
XTAL2 18 23 P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)
PINS OF 8051
 VCC(pin 40):
– VCC provides supply voltage to the chip.
– The voltage source is +5V.

 GND(pin 20):ground
 XTAL1 and XTAL2(pins 19,18):
– These 2 pins provide external clock.
– XTAL 1:Input to the inverting oscillator amplifier and
input to the internal clock generator circuits
– XTAL 2:Output from the inverting oscillator amplifier

Advance Tech. India Pvt Ltd


XTAL CONNECTION TO 8051
• Using a quartz crystal oscillator

C2
XTAL2
30pF

C1
XTAL1
30pF

GND

Advance Tech. India Pvt Ltd


Example
Find the machine cycle for
(a) XTAL = 11.0592 MHz
(b) XTAL = 16 MHz.

Solution:

(a) 11.0592 MHz / 12 = 921.6 kHz;


machine cycle = 1 / 921.6 kHz = 1.085 s
(b) 16 MHz / 12 = 1.333 MHz;
machine cycle = 1 / 1.333 MHz = 0.75 s

Advance Tech. India Pvt Ltd


PINS OF 8051

 RST(pin 9):reset
– It is an input pin and is active high
(normally low).
• The high pulse must be high at
least 2 machine cycles.
• Upon applying a high pulse to
RST, the microcontroller will
reset and all values in registers
will be lost.

Advance Tech. India Pvt Ltd


PINS OF I/O PORT
 The 8051 has four I/O ports
– Port 0 (pins 32-39)
– Port 1(pins 1-8)
– Port 2(pins 21-28)
– Port 3(pins 10-17)

– Each port has 8 pins in 8051.

 Each port can be used as input or output (bi-direction).

Advance Tech. India Pvt Ltd


WRITING “1” TO OUTPUT PIN P1.X

Read latch Vcc


TB2
Load(L1) 2. output pin
1. write a 1 to the is Vcc
pin 1
Internal D Q P1.X
CPU bus P1.X pin
0 output 1
Write to Clk M1
latch Q

TB1
Read pin

8051 IC
WRITING “0” TO OUTPUT PIN P1.X

Read latch Vcc


TB2
Load(L1) 2. output pin
1. write a 0 to the is ground
pin 0
Internal D Q P1.X
CPU bus P1.X pin
1 output 0
Write to Clk M1
latch Q

TB1
Read pin

8051 IC
PINS OF 8051
 /EA(pin 31):external access
– There is no on-chip ROM in 8031 and 8032 .
– The /EA pin is connected to GND to indicate the code is stored
externally.
– /PSEN & ALE are used for external ROM.
– For 8051, /EA pin is connected to VCC.
 /PSEN(pin 29):program store enable
– This is the read pin for external program memory. When the
device is executing from internal program memory, /PSEN is
inactive (HIGH). When the device is executing code from
external program memory, PSEN is activated (low).
– This is an output pin and is connected to the OE pin of the
ROM.

NOTE: “/” means active low.

Advance Tech. India Pvt Ltd


PINS OF 8051
• The ALE pin is used for de-multiplexing the address and
data by connecting to the G pin of the 74LS373 latch.
– When ALE=0, P0 provides data D0-D7.
– When ALE=1, P0 provides address A0-A7.
– The reason is to allow P0 to multiplex address and data.

Advance Tech. India Pvt Ltd


PORT 0
8051 NANO BOARD
CONNECTIONS FOR EXPERIMENTS

LIQUID CRYSTAL DISPLAY BUZZER

DATA P2 BUZZER PORT P0.4


RS P3.6
E P3.7
STEPPER MOTOR

SEVEN SEGMENT DISPLAY PORT P 0.1


PORT P 0.2
CONTROL PORT: P3.2, P3.3, P3.4, PORT P 0.3
P3.5 PORT P 0.4
DATA PORT: P0

DIP SWITCH (DIGITAL INPUT)


LIGHT EMITTING DIODE’S
PORT P2
PORT P1
PROGRAAMING IN
EMBEDED C
LED
INTERFACING
WITH 8051
Light Emitting Diodes (LEDs)
Function
LEDs emit light when an
electric current passes
through them.

Circuit symbol:

Advance Tech. India Pvt Ltd


Testing an LED
It will be destroyed almost instantly because
too much current will pass through and burn
it out.

LEDs must have a resistor in series to limit


the current to a safe value, for quick testing
purposes a 1k resistor is suitable for most
LEDs.

Never connect an LED directly to a battery or


power supply!
Advance Tech. India Pvt Ltd
LED Interfacing with PIC
1st Method
P1 = 0x00 // LED OFF
P1 = 0 xff// LED ON
P1=0x00 // All LEDs OFF
2nd
Method
P1 = oxff // LED ON
P1 = 0x00// LED OFF

P1=0xff// All LEDs ON


Advance Tech. India Pvt Ltd
RESITOR VALUE
 Commonly, used LEDs will have voltage drop of 1.7v and
current of 10mA to glow at full intensity.

 The negative terminal of the LED is connected to the ground


through a resistor. Value of this resistor is calculated using
the following formula.

R= (V-1.7)/10mA, where V is the input voltage.

 Generally, microcontrollers output a maximum voltage of


5V. Thus the value of resistor calculated for this is 330
Ohms. Thus this can be connected either to the cathode or
anode of the LED.
LED BLINKING
#include<reg51.h>
int i;
void main()
{
P1=0xff; // LED ON
for(i=0;i<=30000;i++); // DELAY
P1=0x00; // LED OFF
for(i=0;i<=30000;i++); // DELAY
}
Switch Circuitry

A switch generates a
high to low pulse.
The pulse acts as
input to
microcontroller.
Microcontroller
senses the transition
and perform
appropriate task.

Advance Tech. India Pvt Ltd


LED ON and OFF using switch

#include<reg51.h>
sbit sw=P2^0;
sbit led=P1^0;
void main()
{
sw=0;
led=0;
while(1)
{
if(sw==1) led=1;
else led=0;
}}

Advance Tech. India Pvt Ltd


Interfacing of with
seven segment

Advance Tech. India Pvt Ltd


Contents
About seven segments.

Interfacing

Programming of seven segment.

Advance Tech. India Pvt Ltd


LED Displays
LEDs can be combined together in a single
package to produce displays such as bar
graphs, strips, arrays and 7-segment displays.

Bar 7-segment Starburst Dot matrix


graph Advance Tech. India Pvt Ltd
7-segment Display

There are two important


types of
7-segment LED digital
display.

Advance Tech. India Pvt Ltd


The Common Cathode The Common Anode
Display (CCD) Display (CAD)
All cathodes are common All anodes are
and ground is being common and VCC is
provided.
being provided.

Advance Tech. India Pvt Ltd


Interfacing common anode
display

Advance Tech. India Pvt Ltd


7 Segment Program

#include<reg51.h>
char arr[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void delay(void)
{
int f;
for(f=0;f<30000;f++);
}
void main(void)
{ int a;
for(a=0;a<10;a++)
{
P2=arr[a];
delay();
}}
PROGRAM COUNT 00 TO 99
#include<reg51.h>
char arr[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void delay(void)
{
int f;

for(f=0;f<10000;f++);
}
void main(void)
{
int a,b,c;
for(a=0;a<10;a++)
{ for(b=0;b<10;b++)
{ for(c=0;c<30;c++)
{
P3=0x40;
P0=arr[b];
delay();
P3=0x80;
P0=arr[a];
delay();} }}}}}
Interfacing
of 8051
with LCD

Advance Tech. India Pvt Ltd


Liquid Crystal Display
Liquid Crystal Displays
HD44780(LCDs)
 cheap and easy way to
display text, Displays
numbers, letters and fixed
symbols
Various configurations (1
Line, 2 Line or 4 Line LCDs ).
Integrated controller
Data lines (DB7-DB0) used
to transfer data and
commands
Advance Tech. India Pvt Ltd
Inside LCD
DDRAM - Display Data RAM
Display data RAM (DDRAM) stores display data
represented in 8-bit character codes.

CGRAM - Character Generator RAM


CGRAM area is used to create custom characters
in LCD. In the character generator RAM, the user
can rewrite character patterns by program.

Advance Tech. India Pvt Ltd


Inside LCD
Instruction Register (IR)
Instruction register corresponds to the
register where you send commands to LCD
e.g. LCD shift command, LCD clear, LCD
address etc.

Data Register (DR)


Data register is used for storing data
which is to be displayed on LCD.

Advance Tech. India Pvt Ltd


Pin Information of LCD:

Advance Tech. India Pvt Ltd


UNDERSTANDING LCD Pins
8 data pins D7:D0
Bi-directional data/command pins.
Alphanumeric characters are sent in ASCII
format.

Advance Tech. India Pvt Ltd


UNDERSTANDING LCD Pins
•RS: Register Select
RS = 0 -> Command Register is selected
RS = 1 -> Data Register is selected
•R/W: Read or Write
0 -> Write, 1 -> Read
•E: Enable (Latch data)
Used to latch the data present on the data
pins. A high-to-low edge is needed to
latch the data.
•VEE : contrast control

Advance Tech. India Pvt Ltd


LCD Initialization Commands:
1.Specify function set:
Send 38H for 8-bit,double line and 5x7 dot character
format.

2.Display On-Off control:


Send 0EH for display and blink cursor on.

3.Entry mode set:


Send 06H for cursor in increment position and shift is
invisible.

4. Clear display:
Send 01H to clear display and return cursor to home
position.

Advance Tech. Pvt Ltd


LCD Commands:

Advance Tech. India Pvt Ltd


Algorithm to send data to LCD:

1. Place data byte on data register


2. Make RS=0 ;if data byte is command
RS=1 ;if data byte is data
3. Pulse on E (HIGH to LOW)
4. Repeat the steps to send another data
byte

Advance Tech. India Pvt Ltd


PROGRAM FOR LCD
#include<reg51.h>
sbit RS = P3 ^ 0;
sbit E = P3 ^ 1;
void main(void)
void instwrt(void)
{
{
while(1)
RS=0;
{
E=1;
P2=0x38; instwrt(); delay();
E=0;
P2=0x0E; instwrt(); delay();
}
P2=0x01; instwrt(); delay();
void datawrt(void)
P2=0x06; instwrt(); delay();
{
P2=0x83; instwrt(); delay();
RS=1;
P2='A'; datawrt(); delay();
E=1;
P2='N'; datawrt(); delay();
E=0;
P2='K‘ ; datawrt(); delay();
}
P2='I'; datawrt(); delay();
void delay(void)
P2='T'; datawrt(); delay();
{
}
unsigned int i;
}
for(i=0;i<=30000;i++ )
{}
}
LCD CODE
#include<reg51.h> void data_lcd(char dat)
sbit RS = P3 ^ 6; {
sbit E = P3 ^ 7; P2 = dat;
void delay(unsigned long int h) RS=1;
{ E=1; delay(10);
unsigned long int i,j; E=0;
for(j=0;j<h; j++) }
for(i=0;i<300;i++); void init_lcd()
} { cmd_lcd(0x38);
void cmd_lcd(char dat) cmd_lcd(0x0e);
{ cmd_lcd(0x06);
P2 = dat; cmd_lcd(0x01);
RS=0; }
E=1; delay(10); void lcd_string(unsigned char *str)
E=0; {
} while(*str)
data_lcd(*str++);
}
CONTINUED………..
void main()
{
init_lcd();
while(1)
{
cmd_lcd(0x83);
lcd_string("ANKIT MOHAN");
delay(10);
}
}
CUSTOM CHARACTER ON LCD
When the ASCII code for any character, say ‘A’, is sent to be displayed
on LCD module, the module's controller looks up the appropriate 5x8-pixel
pattern in ROM (read-only memory) and displays that pattern on the
LCD.

ASCII Code Base Address


0 64 0x40
1 72 0x48
2 80 0x50
3 88 0x58
4 96 0x60
5 104 0x68
6 112 0x70
7 120 0x78
FIRST SENDING THE ADDRESS LOCATION (64) TO LCD COMMAND REGISTER.
NEXT, THE BITMAP VALUES (0, 4, 2, 31, 2, 4, 0, 0) ARE SENT TO THE LCD DATA
REGISTER. NOW THE ARROW SIGN GETS STORED AT THE FIRST ADDRESS. NOW
WHENEVER THIS SYMBOL IS TO BE DISPLAYED, ITS LOCATION NEEDS TO BE SENT
TO THE LCD.

Hex values

0x00

0x04

0x02

0x1F

0x02

0x04

0x00

0x00
void main(void)
{
CODE
P2=0x38; instwrt(); delay();
#include<reg51.h> P2=0x0E; instwrt(); delay();
sbit RS =P1 ^ 0; P2=0x01; instwrt(); delay();
sbit E =P1 ^ 1; P2=0x06; instwrt(); delay();
void delay(void) P2=0x40; instwrt(); delay();
{unsigned int i;
for(i=0;i<=20000;i++); P2=0x00; datawrt();
} P2=0x04; datawrt();
void instwrt(void) P2=0x02; datawrt();
{ P2=0x1f; datawrt();
RS=0; P2=0x02; datawrt();
E=1; delay(); E=0; P2=0x14; datawrt();
} P2=0x00; datawrt();
void datawrt(void) P2=0x00; datawrt();
{ while(1)
RS=1; {
E=1; delay(); E=0; P2=0x80; instwrt(); delay();
} P2=0; datawrt(); delay();
}
}
INTERFACING WITH
EXTERNAL ADC

Advance Tech. India Pvt Ltd


Eternal ADC0808

• One of the most commonly used ADC is ADC0808. ADC 0808 is a


Successive approximation type with 8 channels .

• it can directly access 8 single ended analog signals. ADC0808 has


an 8-bit data output just like the ADC804.

• The 8 analog input channels are multiplexed and selected


according to table given below I/O pins using three address pins A,
B, and C.
FEATURES OF ADC 0808

1. Inbuilt 8 analog channels with multiplexer


2. Zero or full scale adjustment is not required
3. 0 to 5V input voltage range with a single polarity
5V supply
4. Output is TTL compatible
5. High speed
6. Low conversion time (100micro second)
7. High accuracy
8. 8-bit resolution
9. Low power consumption (less than 15mW)
10. Easy to interface with all microprocessor
11. Minimum temperature dependence
Calculating Step Size
ADC 0808 is an 8 bit ADC i.e. it divides
the voltage applied at Vref+ & Vref- into 28
i.e. 256 steps.
Step Size = (Vref+ -Vref-)/256
Suppose Vref+ is connected to Vcc i.e. 5V &
Vref- is connected to the Gnd then the
step size will be
Step size= (5 - 0)/256= 19.53 mV.

Calculating Dout
The data we get at the D0 - D7 depends
upon the step size & the Input voltage
i.e. Vin.

Dout = Vin /step Size.

If you want to interface sensors like


LM35 which has output 10mv/°C then I
would suggest that you set the Vref+ to
2.56v so that the step size will be
Step size= (2.56 - 0)/256= 10 mV.
ADDRESS LINE A, B, C - The device contains 8-channels. A particular channel
is selected by using the address decoder line. ·

Address Latch Enable (ALE) - The address is latched on the Low – High
transition of ALE.

·START - To start the ADC conversion

· Output Enable - Whenever data has to be read from the ADC, Output Enable
pin has to be pulled high thus enabling the TRI-STATE outputs, allowing data to
be read from the data pins D0-D7.

·End of Conversion (EOC) - This pin becomes High when the conversion has
ended, so the controller comes to know that the data can now be read from the
data pins.

·Clock - External clock pulses are to be given to the ADC; this can be given
either from LM 555 in Astable mode or the controller can also be used to give the
pulses.
· D0 – D7 - D0- D7 are the digital data output pins since ADC0808 is a parallel
ADC chip.. To calculate the output voltage, we can use following formula
ALGORITHM

1.Start.
2.Select the channel.
3.A Low – High transition on ALE to latch in the address.
4.A Low – High transition on Start to reset the ADC’s SAR.
5.A High – Low transition on ALE.
6.A High – Low transition on start to start the conversion.
7.Wait for End of cycle (EOC) pin to become high.
8.Make Output Enable pin High.
9.Take Data from the ADC’s output
10.Make Output Enable pin Low.
11.Stop
PROGRAM
while(1)
{
#include<reg51.h> ALE=1;
#include"delay.h" SOC=1;
#include"lcd.h" clock();
sbit ALE=P3^2; ALE=0;
sbit SOC=P3^3; SOC=0;
sbit OE=P3^5; clock();
sbit EOC=P3^4; while(!EOC);
sbit CLOCK=P3^6; OE=1;
unsigned char adc_val; adc_val=P1;
unsigned char temp[5]; dummy=P1;
void clock(void); cmd_lcd(0xc3);
void main(void) number_lcd(dummy);}}
{ void clock(void)
int i; {
int dummy; int a,b;
init_lcd(); for(b=0;b<=1000;b++)
cmd_lcd(0x83); {
cmd_lcd(0x01); for(a=0;a<30;a++);
lcd_string("LDR VALUE") ; CLOCK=~CLOCK;}}
Serial
Communication

Advance Tech. India Pvt Ltd


Serial
Communication
Type of Communication

1.Parallel
2.Serial

Advance Tech. India Pvt Ltd


Serial
transmission

Advance Tech. India Pvt Ltd


Synchronous transmission

Advance Tech. India Pvt Ltd


Baud Rates in the 8051

• The 8051 transfers and receives data serially


at many different baud rates by using UART.
• UART divides the machine cycle frequency by
32 and sends it to Timer 1 to set the baud rate.
• Signal change for each roll over of timer 1

11.0592 MHz
Machine cycle 28800 Hz
XTAL frequency ÷ 32
÷ 12 Timer 1
oscillator 921.6 kHz By UART To timer 1
To set the
Advance Tech. India Pvt Ltd Baud rate
Baud Rates in the 8051

• Timer 1, mode 2 (8-bit, auto-reload)


• Define TH1 to set the baud rate.
– XTAL = 11.0592 MHz
– The system frequency = 11.0592 MHz / 12 = 921.6
kHz
– Timer 1 has 921.6 kHz/ 32 = 28,800 Hz as source.
– TH1=FDH means that UART sends a bit every 3
timer source.
– Baud rate = 28,800/3= 9,600 Hz

Advance Tech. India Pvt Ltd


SCON Register
• Serial control register: SCON
SM0, SM1 Serial port mode specified
REN (Receive enable) set/cleared by
software to enable/disable reception.
TI Transmit interrupt flag.
RI Receive interrupt flag.
SM2 = TB8 = RB8 =0 (not widely used)
SM0 SM1 SM2 REN TB8 RB8 TI RI
* SCON is bit-addressable.
Advance Tech. India Pvt Ltd
SM0, SM1
• SM1 and SM0 determine the framing of data.
– SCON.6 (SM1) and SCON.7 (SM0)
– Only mode 1 is compatible with COM port of PC.

SM0 SM1 Mode Operating Mode Baud Rate


0 0 0 Shift register Fosc./12
0 1 1 8-bit UART Variable by timer1
1 0 2 9-bit UART Fosc./64 or Fosc./32
1 1 3 9-bit UART Variable

Advance Tech. India Pvt Ltd


REN (Receive Enable)

• SCON.4
• Set/cleared by software to enable/disable
reception.
– REN=1
• If we want the 8051 to both transfer and
receive data, REN must be set to 1.
– REN=0
• The receiver is disabled.
• The 8051 can not receive data.
Advance Tech. India Pvt Ltd
Transfer Data with the TI flag
• The following sequence is the steps that the
8051 goes through in transmitting a
character via TxD:
1. The byte character to be transmitted is written into
the SBUF register.
2. It transfers the start bit.
3. The 8-bit character is transferred one bit at a
time.
4. The stop bit is transferred.
SBUF
8-bit char
bit by bit
TI UART TxD
Advance Tech. India Pvt Ltd
Steps to transmit data
from 8051 to pc
1.Load SCON register.
2.Laod TMOD register(select timer1 mode 2).
3. Load baud rate in TH1.
4. Start the timer.
5. Place character in SBUF.
6. Monitor TI flag.
7. Clear TI flag.

Advance Tech. India Pvt Ltd


TRANSMITTING CHARACTER A
CONTINUSLY

#include<reg51.h>
void main ()
{
while(1)
{
TMOD=0x20;// timer1 in mode 2
SCON=0x50;// scon register for reciver enable
TH1=0xfd;// baudrate 9600
TR1=1; // start the timer
SBUF='A';// data that has to be sent put in sbuf
while(TI==0);// monitor the transmit flag
TI=0; // clear the timer 1 flag after transmit
}
}
PROGRAM TO TRANSMIT DATA
TO PC
#include<reg51.h>
unsigned char arr[]={“Ankit Mohan”};
void serial_init()
{
void main ()
TMOD=0x20;
{
SCON=0x50;
Int i;
TH1=0xfd;
serial_init();
TR1=1; while(1)
} {
void serial_trans(unsigned char trans) for(i=0;i<=11;i++)
{
{
serial_trans(arr[i]);
SBUF=trans; }
while(TI==0); }
TI=0;
Advance Tech. India Pvt Ltd
}
PROGRAM TO RECEIVED DATA FORM
PC
#include<reg51.h>
void serial_init()
{
void main ()
TMOD=0x20;
SCON=0x50; {
TH1=0xfd; serial_init();
TR1=1; while(1)
TI=0; {
} P1=serial_rec();
unsigned char serial_rec() }
{
while(RI==0);
}
RI=0;
return(SBUF);
}

Advance Tech. India Pvt Ltd


SERIAL PROGRAM
void init_serial(unsigned int br) unsigned char rec_serial()
{ {
TMOD=0x20; RI=0;
SCON=0x50; while(RI==0);
RI=0;
TH1=(256-(28800/br));
return(SBUF);
TR1=1; }
}
void string_serial(unsigned char *str)
unsigned char rec_serial() {
{ while(*str!='\0')
RI=0; {
while(RI==0); trans_serial(*str);
RI=0; str++;
}
return(SBUF);
}
}
PROGRAM
#include<reg51.h>
#include"delay.h"
#include"lcd.h"
#include"serial.h"

void main()
{ int i;
init_lcd();

init_serial(9600);
while(1)

{ lcd_string(" *SERIAL*RECVE* ");


cmd_lcd(0xc0);
for(i=0;i<16;i++)
data_lcd(rec_serial());
cmd_lcd(0x01);
}
}
Thank You