MPMC 5
MPMC 5
COMMUNICATION
Interfacing with display devices:
LED’s
LCD unit
A/D
D/A
External memory interface to ROM and RAM
keyboard interfacing
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
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.
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.
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
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
MOV TMOD,#10H
AGAIN: MOV TL1,#00
MOV TH1,#0DCH
SETB TR1
BACK: JNB TF1,BACK
CLR TR1
CLR TF1
RET
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.
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.
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