[go: up one dir, main page]

0% found this document useful (0 votes)
15 views26 pages

MPMC 5

The document covers interfacing various components with the 8051 microcontroller, including LEDs, LCDs, ADCs, DACs, external memory, and keyboards. It provides assembly language programs for controlling these devices, detailing the necessary connections and programming techniques. Additionally, it discusses serial communication standards and the differences between synchronous and asynchronous data transmission methods.

Uploaded by

puppyking041
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views26 pages

MPMC 5

The document covers interfacing various components with the 8051 microcontroller, including LEDs, LCDs, ADCs, DACs, external memory, and keyboards. It provides assembly language programs for controlling these devices, detailing the necessary connections and programming techniques. Additionally, it discusses serial communication standards and the differences between synchronous and asynchronous data transmission methods.

Uploaded by

puppyking041
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

UNIT-5 I/O, MEMORY INTERFACE AND SERIAL

COMMUNICATION
Interfacing with display devices:
LED’s
LCD unit
A/D
D/A
External memory interface to ROM and RAM
keyboard interfacing

8051 Interfacing with LED:

Light Emitting Diode (LED) interfacing is directly connected to the port pins of the
microcontroller.There are two ways which we can interface LED to the
Microcontroller 8051. But the connections and programming techniques will be
different. This article provides the information on LED interfacing with 8051.
GO: MOV A, #FFh
MOV P0, A
ACALL DELAY

MOV A, #00h
MOV P0, A
ACALL DELAY

SJMP GO

DELAY: MOV R2, #FFh


UP: DJNZ R2, UP
RET

SINGLE LED GLOW WITH DELAY

MOV A, #80H
UP: MOV P1,A
ACALL DELAY
RR A
SJMP UP
DELAY: MOV R2, #FFh
HERE: DJNZ R2, HERE
RET
END
8051 Interfacing with LCD:
16×2 character LCD display is very basic module.
It can display 2 lines of 16 characters.
Each character is displayed using 5×7 or 5×10 pixel matrix.

pin Symbol I/O Description


1 VSS -- Ground
2 VDD -- +5V Power Supply
3 VEE -- Power Supply to Control Contrast
4 RS I RS=0 to Select Command Register

Rs=1 to Select Data Register


5 R/W I R/W=0 for Write

R/W=1 for Read


6 E I/O Enable
7- D7-D0 I/O The 8-bit data bus
14
15 LEDA -- To Turn On the back light apply 5V to LEDA and make LEDK Ground
16 LEDK --

LCD operation
Activate the enable pin (pin 6),
after enabling select the Register Select pin (pin4) in write mode by making this pin
high (RS=1),
after selecting the Register Select you have to configure the R/W to write mode that is
R/W should be low (R/W=0).
FOR DATA REGISTER :
E=1; enable pin should be high
RS=1; Register select should be high
R/W=0; Read/Write pin should be low.
FOR COMMAND REGISTER:
E=1; enable pin should be high
RS=0; Register select should be low
R/W=0; Read/Write pin should be Low.
LCD COMMANDS:

Interface 16X2 LCD with 8051. Write an Assembly language program to display
‘MPMC’ on LCD.
To send any of the commands to the LCD, make pin RS=0. For data, make RS=1.
Then send a high-to-low pulse to the E pin to enable the internal latch of the LCD.

P1.0-P1.7 are connected to LCD data pins D0-D7


P3.5 is connected to RS pin of LCD
P3.4 is connected to R/W pin of LCD
P3.3 is connected to E pin of LCD
Interface 16X2 LCD with 8051. Write an Assembly language program to display
‘MPMC’ on LCD.

MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX


ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time

MOV A,#0EH ;display on, cursor on


ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time

MOV A,#01 H ;clear LCD


ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time

MOV A,#06H ;shift cursor right


ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time

MOV A,#80H ;cursor at line 1, pos. 0


ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time

MOV A,#’M’ ;display letter M


ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time

MOV A,#’P’ ;display letter P


ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time

MOV A,#’M’ ;display letter M


ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time

MOV A,#’C’ ;display letter C


ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time

COMNWRT: ;send command to LCD


MOV P1, A ;copy reg A to port 1
CLR P3.5 ;RS=0 for command
CLR P3.4 ;R/W=0 for write
SETB P3.3 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P3.3 ;E=0 for H-to-L pulse
RET

DATAWRT: ;write data to LCD


MOV P1, A ;copy reg A to port 1
SETB P3.5 ;RS=1 for data
CLR P3.4 ;R/W=0 for write
SETB P3.3 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P3.3 ;E=0 for H-to-L pulse
RET

AGAIN: SJMP AGAIN ;stay here

DELAY: MOV R3, #50


HERE2: MOV R4, #255
HERE: DJNZ R4,HERE
DJNZ R3, HERE2
RET
END

8051 Interfacing with ADC Interface (0808):


The ADC 0808 is a popular 8-bit ADC with a step size of 19.53 millivolts. It does not
have an internal clock. Therefore, it requires a clock signal from an external source.
It has eight input pins, but only one of them can be selected at a time because it has
eight digital output pins. It uses the principle of successive approximation for
calculating digital values, which is very accurate for performing 8-bit analog to digital
conversions. The 8 analog input channels are multiplexed and selected according to
table below using three address pins, A, B, and C.

C B A Selected Analog channel


0 0 0 IN0
0 0 1 IN1
0 1 0 IN2
0 1 1 IN3
1 0 0 IN4
1 0 1 IN5
1 1 0 IN6
1 1 1 IN7

Step 1: Set the port you connected to the output lines of the ADC as an input port.
Step 2: Make the Port connected to EOC pin high. The reason for doing this is that the ADC
sends a high to low signal when the conversion of data is complete. So this line needs to be
high so that the microcontroller can detect the change.
Step 3: Clear the data lines which are connected to pins ALE, START, and OE as all these
pins require a High to low pulse to get activated.
Step 4: Select the data lines according to the input port you want to select. To do this, select
the data lines and send a High to Low pulse at the ALE pin to select the address.
Step 5: Now that we have selected the analog input pin, we can tell the ADC to start the
conversion by sending a pulse to the START pin.
Step 6: Wait for the LOW on EOC pin.
Step 7: Extract the converted data by sending a High to low signal to the OE pin.
ale equ P2.4
oe equ P2.5
start equ P2.6
eoc equ P2.7
sel_a equ P2.0
sel_b equ P2.1
sel_c equ P2.2
adc_data equ P1
org 0H
;Data port to input
mov adc_data, #0FFH
;EOC as Input
setb eoc
;rest of output signals
clr ale
clr oe
clr start
;Select Analog Channel 1
again: clr sel_a
clr sel_b
clr sel_c
;Latch channel select
setb ale
;Start conversion
setb start
clr ale
clr start
;Wait for end of conversion
again: jnb eoc,again
//means jump to same location
setb eoc
;Assert read signal
setb oe
; Read Data
mov A, adc_data
Mov p1,a
clr oe
;Start over for next conversion
sjmp again
end

8051 Interfacing with DAC interfacing (MC1408):


In 1408 the digital inputs are converted to current.
The output current is known as Iout by connecting a resistor to the output to convert
into voltage.
The total current provided by the Iout pin is basically a function of the binary
numbers at the input pins D0 - D7 (D0 is the LSB and D7 is the MSB) of DAC0808
and the reference current Iref. The following formula is showing the function of Iout

PROGRAM: Interface MC 1408 with 8051 and Write an Assembly Language Program
to generate a square wave
Start MOV A,#00h
MOV P1,A
ACALL DELAY
MOV A,#FFh
MOV P1,A
ACALL DELAY
SJMP Start

downward ramp wave


MOV A,#FFh
GO MOV P1,A
DEC A
SJMP GO

upward ramp wave


MOV A,#00h
GO MOV P1,A
INC A
SJMP GO

PROGRAM: Assume XTAL = 11.0592 MHz, write a program to generate a square

wave of 50 kHz frequency on P1.


Timer value to be loaded for TL &TH:
(a) T = 1 / 50 = 20 ms, the period of square wave.
(b) 1 / 2 of it for the high and low portion of the pulse is 10 ms.
(c) 10 ms / 1.085 us = 9216 and 65536 – 9216 = 56320 in decimal,
and in hex it is DC00H.
TL = 00 and TH = DC (hex).

MOV TMOD,#10H
AGAIN: MOV TL1,#00
MOV TH1,#0DCH
SETB TR1
BACK: JNB TF1,BACK
CLR TR1
CLR TF1
RET

8051 Interfacing with External Memory RAM and ROM :


Address/Data Multiplexing
Data, Address and Control bus for 8051

8051 Connection to External Program ROM

8051 Connection to External Data ROM


8051 Connection to External Data ROM and External Program ROM

8051 Connection to External Data RAM

8051 Connection to External Program ROM, Data RAM and Data ROM
8051 Interfacing with Keyboard:
At the lowest level , keyboards are organized in a matrix of rows and columns.
The CPU assesses both rows and columns through ports.When a key is pressed , a
row and a column make a contact otherwise there is no connection between rows and
columns.
Scanning and identifying the key
1.4x4 matrix connected to two ports.
2.Rows are connected to an output port and the columns are connected to an input
port.
3.If no key has been pressed, reading the input port will yield 1’s for all columns since
they are connected to VCC
4.If all the rows are grounded and a key is pressed,one of the columns will have 0
since the key pressed provides the path to the ground.
5.It is the function of the microcontroller to scan the keyboard continuously to detect
and identify the key pressed.

Flowchart of keyboard Interfacing


PROGRAM FOR KEY BOARD INTERFACING
MOV P2,#0FFH .......P2 as Input port
K1: MOV P1,#0
MOV A,P2
ANL A ,#00001111B
CJNE A,#00001111B,K1
K2: ACALL DELAY
MOV A,P2
ANL A ,#00001111B
CJNE A,#00001111B,OVER
SJMP K2
OVER: ACALL DELAY
MOV A,P2
ANL A ,#00001111B
CJNE A,#00001111B,OVER1
SJMP K2
OVER1: MOV P1,#11111110B
MOV A,P2
ANL A ,#00001111B
CJNE A,#00001111B,ROW-0
MOV P1,#11111101B
MOV A,P2
ANL A ,#00001111B
CJNE A,#00001111B,ROW-1
MOV P1,#11111011B
MOV A,P2
ANL A ,#00001111B
CJNE A,#00001111B,ROW-2
MOV P1,#11110111B
MOV A,P2
ANL A ,#00001111B
CJNE A,#00001111B,ROW-3
LJMP K2
ROW-0: MOV DPTR,#KCODE0
SJMP FIND
ROW-1: MOV DPTR,#KCODE1
SJMP FIND
ROW-2: MOV DPTR,#KCODE2
SJMP FIND
ROW-3: MOV DPTR,#KCODE3
SJMP FIND
FIND: RRC A
JNC MATCH
INC DPTR
SJMP FIND
MATCH: CLR A
MOVC A,@A+DPTR
MOV P0,A
LJMP K1
ORG 300H
KCODE0:DB ‘0’, ‘1’, ‘2’, ‘3’
KCODE1:DB ‘4’, ‘5’, ‘6’, ‘7’
KCODE2:DB ‘8’, ‘9’, ‘A’, ‘B’
KCODE3:DB ‘C’, ‘D’,’E’,’F’
END

Serial communication and bus Interface:


1.Serial Communication Standards
2.Serial Data transfer Scheme
3.On board Communication intrfaces-I2C BUS,SPI BUS,UART
4.External Communication Interfaces-RS232,USB
1.Serial Data transfer Scheme
Serial Vs Parallel Communication
In general computers can transfer the data in two ways

Parallel data transfer:


Group of wires will transfer the data with in a short distance range.
Fastest data transfer
Cost is high
Serial data transfer:
Single wire is used to transfer the data to long distances.
Bit by bit data transmission.
Data transfer is in slower manner
Cost is less
The microcontroller will transmit the parallel data with the help of buses.
To transfer serial data serial port is available (TXD, RXD).
Serial data communication uses two techniques to transfer serial data
Synchronous: Block of data is transmitted at a time
Asynchronous: Byte of data is transmitted at a time
Synchronous Transmission:
Synchronous Transmission, data flows in a full duplex mode in the form of blocks or
frames. Synchronization between the sender and receiver is necessary so that the
sender know where the new byte starts (since there is no gap between the data).
Synchronous Transmission is efficient, reliable and is used for transferring a large
amount of data.
Asynchronous Transmission:
Asynchronous serial data communication is widely used for character-oriented
transmissions.Each character is placed in between start and stop bits, this is called
framing.The start bit is always one bit, but the stop bit can be one or two bits
The start bit is always a 0 (low) and the stop bit(s) is 1 (high)

Asynchronous serial data transfer format


BASIS FOR COMP ASYNCHRONOUS TRAN
SYNCHRONOUS TRANSMISSION
ARISON SMISSION
Meaning Sends data in the form of blocks or frames Sends 1 byte or character at
a time
Transmission Speed Fast Slow
Cost Expensive Economical
Time Interval Constant Random
Gap between the data Absent Present
Examples Chat Rooms, Video Conferencing, Telephonic Letters, emails, forums, etc
Conversations, etc

DATA TRANSFER SCHEMES


Simplex: One way data transmission from transmitter to receiver
Half Duplex: Bi directional data transfer, only one direction at a time
Full Duplex: Bidirectional, both the directions simultaneously.
Serial Communication Standards:
RS232 Standards
To allow compatibility among data communication equipment made by various
manufactures, an interfacing standard called RS232 was developed.An interfacing
standard RS232 was developed by Electronic Industry Association (EIA) in 1960s.
In RS232 ,logic 1 is represented -3 to -25V,while logic 0 is represented by +3 to
+25V ,making -3 to +3 are undefined.
The standard was set long before the advent of the TTL logic family, its input and
output voltage are not TTL compatible. A microcontroller system must use voltage
converters such as MAX232 to convert the TTL logic levels to the RS232 voltage
levels and vice versa. MAX232 IC chips are commonly referred to as Line drivers.
DB9 Connector:

8051 has two pins that are used specially for transferring and receiving data serially.
These two pins are TXD and RXD and are part of port3
These pins are TTL compatible, therefore they require a line converter to make them
RS232 compatible. Inside MAX232 and its connection to 8051
On board Communication interfaces:
1.Inter Integrated Circuit(I2C) BUS:
The inter integrated circuit bus is a synchronous bi-directional half duplex two wire
serial interface bus.The original intention of I2C bus was to provide an easy way of
connection between microprocessor/microcontroller system and the peripheral chips
in television sets.The I2Cbus comprise of two bus lines namely Serial clock-SCL and
Serial Data-SDA. SCL is responsible for generating synchronous clock pulse and
SDA is responsible for transmitting serial data across the devices.
I2C bus is a shared bus system to which many number of I2C devices can be
connected.Devices connected to the I2C bus can act as a “master” device or slave
device.Master device is responsible for controlling communication by
initiating/terminating data transfer, sending data and generating synchronous clock
pulses.
Slave device wait for the commands from the master and respond upon receiving the
commands. Master and slave devices can act as either transmitter or receiver.
Regardless whether a master act as a transmitter or receiver the synchronous clock
signal is generated by master device only.
The sequence of operations for communication with an I2C slave device is listed
below:
The master device pulls the clock line(SCL) of the bus to ‘high’.
The master device pulls the data line(SDA) ‘low’, when the SCL line is logic
high(this is the ‘start’ condition for data transfer.
The master device sends the address(7 bit or 10 bit wide) of the slave device to which
it wants to communicate, over the SDA line. Clock pulses are generated at the SCL
line for synchronizing the bit reception by the slave device.
The master device sends the read or write bit(bit value=1 read operation and bit
value=0 write operation).
The master device waits for the acknowledgement bit from the slave device whose
address is sent on the bus along with read/write operation commands. Slave device
connected to the bus
Compares the address received with the address assigned to them.
The slave device with the address requested by the master device responds by
sending an acknowledgement bit(bit=1)on SDA line.
Upon receiving the acknowledgement bit, the master device send the 8 bit data to the
slave device over SDA line, if requested operation is ‘write to device’. If the
requested operation is ‘read from device’ , the slave device send data to the master
over the SDA line.
The master device waits for acknowledgement bit from the device upon byte transfer
completed.
The master device terminates the transfer by pulling the SDA line ‘high’, when the
clock line SCL at logic ‘high’.
2. Serial Peripheral Interface(SPI) Bus:
The SPI bus is a synchronous bi-directional full duplex four-wire serial interface bus.
The concept of SPI was introduced by Motorola
SPI is single master multi-slave system.
SPI requires four signal lines for communication. they are
Master out slave in (MOSI): Signal line carrying the data from master to slave
device
Master in slave out (MISO): Signal line carrying the data from Slaver to master
device
serial clock (SCLK): Signal line carrying the clock signals
Slave select (SS): Signal for slave device select. It is a active low signal.
The master device is responsible for generating the clock signal.
It selects the required device by asserting the corresponding slave device slave select
(SS) signal is ’low’.SPI works on the principle of ‘Shift Register’.
The master and slave deices contain a special shift register for the data transmit or
receive.The size of shift register is dependent, normally it is a multiple of 8.
During transmission from master to slave, the data in the master shift register is
shifted out to the MOSI pin and it enters the shift register of the slave device through
MOSI pin of the slave device.
At the same time the shifted out data bit from slave device shift register enters the
shift register of the master device through MISO pin.
3. Universal Asynchronous Receiver transmitter(UART):
UART based data transmission is an asynchronous form of serial data transmission.
UART based serial transmission doesn’t require a clock signal to synchronize the
transmitting end and receiving end for transmission.
Instead it relies upon the pre-defined agreements between the transmitter and
receiver(i.e Baud rate,number of bits per byte,parity,number of start bits and stop bits
and flow control ).
The start and stop of communication inserting through special bits in the data stream.
The least significant bit of data byte follows the ‘start ‘ bit.
The start bit informs the receiver that a data byte is about to arrive.
If parity is enabled for communication, the UART of transmitting device adds a
parity bit.The UART of receiving device calculates the parity of the bits received and
compares it with received parity bit for error checking.
The UART of receiving device discards the ‘start’, ‘stop’ and parity bit from the
received bit stream and converts the received serial bit data to a word.
For proper communication, the transmit line of sending device should be connected to
the receive line of the receiving device.

Asynchronous Serial data


External Communication interfaces:
1. Universal Serial Bus(USB):
USB is a wired high speed serial bus for data communication.
The first version of USB (USB 1.0) was released in 1995 and was created by USB
core group members consists of Intel, Microsoft,IBM etc..
The USB communication system follows a star topology with a USB host at the
center and one or more USB peripheral devices connected to it.
A USB host can support connections upto 127, including slave peripheral devices and
USB hosts.
USB transmits data in the packet format.Each packet has a standard format.
The USB communication is a host initiated one.
The physical connection between a USB peripheral device and master device is
established with a USB cable.
The USB cable support communication upto 5 meters.
The USB standard uses two different types of connectors at the end of the USB cable
for connecting the USB peripheral device and host device.
‘Type A’ connector is used for upstream connection( connection with host) and
‘Type B‘ connector is used for downstream connection(connection with slave device).
Both Type A and Type B connectors contain 4 pins for communication.
Type A Connector- Upstream Connection-with Host
Type B Connector- downstream Connection-with Slave
Both have 4 pins- 1. Vcc
2. D- Differential data carrier line
3. D+ Differential data carrier line
4. GND
Four types of data transfer- control transfer, Bulk transfer, isochronous data transfer,
Interrupt transfer
Control transfer- used by USB System software to query, configure and issue
commands to the USB device.
Bulk transfer- is used for sending a block of data to device.eg.sending block of data
to device-printer
Isochronous- data is transmitted as streams in real time.Audio devices, Medical
equipment
Interrupt – small amount of data- using Polling technique. Frequency of polling -1
to 255 mseconds. Mouse, keypad
2.RS232 Cable:
To allow compatibility among data communication equipment made by various
manufactures, an interfacing standard called RS232 was developed.An interfacing
standard RS232 was developed by Electronic Industry Association (EIA) in 1960s.
In RS232 ,logic 1 is represented -3 to -25V,while logic 0 is represented by +3 to
+25V ,making -3 to +3 are undefined.
The standard was set long before the advent of the TTL logic family, its input and
output voltage are not TTL compatible. A microcontroller system must use voltage
converters such as MAX232 to convert the TTL logic levels to the RS232 voltage
levels and vice versa. MAX232 IC chips are commonly referred to as Line drivers.
DB9 Connector:

8051 has two pins that are used specially for transferring and receiving data serially.
These two pins are TXD and RXD and are part of port3
These pins are TTL compatible, therefore they require a line converter to make them
RS232 compatible. Inside MAX232 and its connection to 8051

You might also like