0% found this document useful (0 votes)
9 views

Unit-3 MPMC Final

Uploaded by

sruthisruhi54
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Unit-3 MPMC Final

Uploaded by

sruthisruhi54
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

UNIT-3

I/O And Memory


Interface
Microcontroller 8051 Peripheral devices
LED Interfacing to Microcontroller
• LEDs are most commonly used in many applications for indicating the output.
They find huge range of applications as indicators during test to check the
validity of results at different stages. They are very cheap and easily available
in a variety of shape, color and size.
Source code:
#include<reg51.h>
void main()
{
unsigned int i;
while(1)
{
P0=0x00;
for(i=0;i<30000;i++);
P0=0xff;
for(i=0;i<30000;i++);
}
}
7-Segment Display interfacing

• A Seven segment display is the most basic electronic display.


• It consists of eight LEDs which are associated in a sequence manner so as to
display digits from 0 to 9 when proper combinations of LEDs are switched on.
• A 7-segment display uses seven LEDs to display digits from 0 to 9 and the 8th
LED is used for dot.
• A typical seven segment looks likes as shown in figure below.
Interfacing Circuit
Source Code:
#include<reg51.h>
sbit a= P3^0;
void main()
{
unsigned char n[10]= {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned int i,j;
a=1;
while(1)
{
for(i=0;i<10;i++)
{
P2=n[i];
for(j=0;j<60000;j++);
}
}
}
LCD-Interfacing Using 8051
• A 16×2 LCD means it can display 16 characters per line and there are 2 such
lines. In this LCD each character is displayed in a 5×7 pixel matrix.

• This LCD has two registers, namely, Command and Data. The command
register stores the command instructions given to the LCD.

• A command is an instruction given to LCD to do a predefined task like


initializing it, clearing its screen, setting the cursor position, controlling the
display, etc.

• The data register stores the data to be displayed on the LCD. The data is the
ASCII value of the character to be displayed on the LCD.
• The LCD display module requires 3 control lines as well as either 4 or 8 I/O lines for the data
bus.

• The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus.

• If a 4-bit data bus is used the LCD will require a total of 7 data lines (3 control lines plus the 4
lines for the data bus).

• If an 8-bit data bus is used the LCD will require a total of 11 data lines (3 control lines plus the 8
lines for the data bus).
• LCD COMMANDS:
Interfacing LCD with 8051 Microcontroller – CIRCUIT
DIAGRAM

RS is connected to Port 0.0 (P0.0)


RW is connected to Port 0.1 (P0.1)
EN is connected to Port 0.2 (P0.2)
Data lines are connected to Port 2 (P2)
void cmd(unsigned char a)
Program {
void lcd_delay()
{
Code:
#include <reg51.h> lcd_data=a; unsigned int lcd_delay;
#define lcd_data P2 rs=0; for(lcd_delay=0;lcd_delay<=6000;lcd_delay++);
rw=0; }
sbit rs=P0^0;
en=1;
sbit rw=P0^1; lcd_delay(); int main()
sbit en=P0^2; en=0; {
void lcd_init(); } unsigned int j;
void cmd(unsigned char a); void dat(unsigned char b) lcd_init();
void dat(unsigned char b); { while(1)
void show(unsigned char *s); lcd_data=b; {
void lcd_delay(); rs=1; rw=0; cmd(0x80);
void lcd_init() en=1; show(" Welcome To ");
lcd_delay(); cmd(0xc0);
{
en=0; show(" MRECW");
cmd(0x38); } for(j=0; j<30000; j++);
cmd(0x0e); void show(unsigned char *s) cmd(0x01);
cmd(0x01); { for(j=0; j<30000; j++);
cmd(0x06); while(*s) }
cmd(0x0c); { }
cmd(0x80); dat(*s++);
} }
}
Keyboard-Interfacing Using 8051
4X4 Matrix Keypad:
• Matrix keypad consists of set of Push buttons, which are interconnected.

• In 4X4 matrix keypad, in which there are 4 push buttons in each of four rows. And the terminals of the
push buttons are connected according to diagram.

• In first row, one terminal of all the 4 push buttons are connected together and another terminal of 4
push buttons are representing each of 4 columns, same goes for each row.

• So we are getting 8 terminals to connect with a microcontroller.


Interfacing keypad with 8051 microcontroller- Circuit Diagram
Steps to Identify the location of the pressed button

1. First we have made all the Rows to Logic level 0 and all the columns to Logic level 1.
2. Whenever we press a button, column and row corresponding to that button gets
shorted and makes the corresponding column to logic level 0. Because that column
becomes connected (shorted) to the row, which is at Logic level 0. So we get the column
no. See main() function.
3. Now we need to find the Row no., so we have created four functions corresponding to each
column. Like if any button of column one is pressed, we call function row_finder1(), to find the
row no.
4. In row_finder1() function, we reversed the logic levels, means now all the Rows are 1 and
columns are 0. Now Row of the pressed button should be 0 because it has become connected
(shorted) to the column whose button is pressed, and all the columns are at 0 logic. So we have
scanned all rows for 0.
5. So whenever we find the Row at logic 0, means that is the row of pressed button. So now we
have column no (got in step 2) and row no., and we can print no. of that button using lcd_data
function.
Program Code:
External RAM & ROM -Interfacing Using 8051
Why need External Memory Interfacing in 8051 Microcontroller:

1. Limited internal memory: The 8051 microcontroller has a limited amount of internal memory, including 128 bytes of

RAM and 4KB of on-chip ROM. This memory may not be sufficient for some applications that require larger program

memory or more data storage.

2. Larger programs: For applications that require larger programs, such as complex algorithms or multiple functions,

external memory interfacing can provide the necessary program memory space to store these programs.

3. Data storage: Applications that require the storage of large amounts of data, such as data logging or data analysis,

may require external memory interfacing to store the data.

4. Flexibility: External memory interfacing provides greater flexibility in the design of embedded systems, allowing for

customization and adaptability to meet specific application requirements.

5. Cost-effective: External memory devices such as RAM and ROM are relatively inexpensive, making it cost-effective to

interface them with the microcontroller instead of using more expensive on-chip memory.
External RAM -Interfacing Using 8051
• External memory interfacing in 8051 microcontroller involves connecting external memory devices such as
RAM and ROM to the microcontroller to provide additional memory space.

• This allows the microcontroller to execute larger and more complex programs, store more data, and perform
more complex operations.

• External memory interfacing typically involves connecting the memory devices to the microcontroller
through a data bus and an address bus.

• The data bus is used to transfer data between the microcontroller and the memory device, while the address
bus is used to select a specific memory location in the memory device.

• To interface with external memory, the 8051 microcontroller uses dedicated pins such as ALE (Address Latch
Enable), PSEN (Program Store Enable), and RD (Read) and WR (Write) signals.

• These signals are used to control the flow of data between the microcontroller and the external memory
device.
External RAM -Interfacing Using 8051

You might also like