0% found this document useful (0 votes)
10 views16 pages

Unit 2 Notes

The document provides detailed instructions on interfacing various components with the 8051 microcontroller, including LEDs, 7-segment displays, LCDs, ADC0809, and 4x4 keypads. It includes assembly language programs for each interfacing example, demonstrating how to control these components through the microcontroller. Additionally, it explains the operational principles and configurations necessary for successful interfacing.

Uploaded by

216301051
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)
10 views16 pages

Unit 2 Notes

The document provides detailed instructions on interfacing various components with the 8051 microcontroller, including LEDs, 7-segment displays, LCDs, ADC0809, and 4x4 keypads. It includes assembly language programs for each interfacing example, demonstrating how to control these components through the microcontroller. Additionally, it explains the operational principles and configurations necessary for successful interfacing.

Uploaded by

216301051
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/ 16

Dept. of Electronics & Telecommunication engg.

Microcontrollers

Interfacing of LEDS:

 Fig. shows Interfacing of 8 LEDs with 8051 microcontroller.


 Anodes of the LEDs are Connected to the port pins and cathodes are
connected to common ground connection.
 To turn on particular LED we will need to make value of that pin
“High” i.e “1”.
 After making a particular pin high or low a small delay is executed to
make that LED light visdible.

ASM Program:

ORG 0000H
START:
MOV P0, #00000000B
CALL DELAY
MOV P0, #00000001B
CALL DELAY
MOV P0, #00000010B
CALL DELAY
MOV P0, #00000011B
CALL DELAY
MOV P0, #00000100B
CALL DELAY

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

MOV P0, #00000101B


CALL DELAY
MOV P0, #00000110B
CALL DELAY
MOV P0, #00000111B
CALL DELAY
MOV P0, #00001000B
CALL DELAY
MOV P0, #00001001B
CALL DELAY
CALL START
DELAY:
MOV R0, #0FH
L3:MOV R2, #0FFH
L1:MOV R1,#0FFH
L2: DJNZ R1, L2
DJNZ R2, L1
DJNZ R0, L3
RET
END

Interfacing of 7-Segment Display:


 Figure shows interfacing diagram of 8051 microcontroller and Seven
segment display. It also shows structure of Seven segment display.
 There are two types of LED 7-segment displays: common cathode
(CC) and common anode (CA). The difference between the two
displays is the common cathode has all the cathodes of the 7-
segments connected directly together and the common anode has all
the anodes of the 7-segments connected together.
 In this diagram common anode seven segment display is used. So
when we want to make any segment glow on, we will just make
respective I/O pin low i.e. 0.
 There are total 4 seven segment displays are used. Transistors T1,
T2, T3, T4 are used to trigger particular seven segment display ON
and OFF.
 With the help of seven segment display we can display alphabetical
characters such as A,B,C,D,E,F and numerical characters such as
0,1,2,3,4,5,6,7,8,9.

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

 Assembly Language Program to display all the hexadecimal


characters is given below.

Program:

ORG 0000H
MOV P1, #00001111B
CALL DELAY
MOV P0, #11111111B
START:
MOV P0, #11000000B ; DISPLAY 0
CALL DELAY
MOV P0, #11111001B ; DISPLAY 1
CALL DELAY
MOV P0, #10100100B ; DISPLAY 2
CALL DELAY
MOV P0, #10110000B ; DISPLAY 3
CALL DELAY
MOV P0, #10011001B ; DISPLAY 4
CALL DELAY
MOV P0, #10010010B ; DISPLAY 5
CALL DELAY
MOV P0, #10000010B ; DISPLAY 6
CALL DELAY
MOV P0, #11111000B ; DISPLAY 7
CALL DELAY
MOV P0, #10000000B ; DISPLAY 8

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

CALL DELAY
MOV P0, #10010000B ; DISPLAY 9
CALL DELAY
CALL START

DELAY:
MOV R0, #0FH
L3:MOV R2, #0FFH
L1:MOV R1,#0FFH
L2: DJNZ R1, L2
DJNZ R2, L1
DJNZ R0, L3
RET
END
Interfacing of 16x2 LCD:

 Liquid Crystal Display (LCD) is very commonly used electronic display module
and having a wide range of applications such as calculators, laptops, mobile
phones etc.
 16×2 character lcd display is very basic module which is commonly used in
electronics devices and projects.
 It can display 2 lines of 16 characters. Each character is displayed using 5×7 or
5×10 pixel matrix.
 LCD can be interfaced with microcontroller in 4 Bit or 8 Bit mode. These differs
in how data is send to LCD.
 In 8 bit mode to write a character, 8 bit ASCII data is send through the data lines
D0 – D7 and data strobe is given through E of the LCD.
 LCD commands which are also 8 bit are written to LCD in similar way.
 The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines. The
number on data lines depends on the mode of operation.
 If operated in 8-bit mode then 8 data lines + 3 control lines i.e. total 11 lines are
required. And if operated in 4-bit mode then 4 data lines + 3 control lines i.e. 7
lines are required.

Pin Symbol Function
1 Vss Ground
2 Vdd Supply Voltage
3 Vo Contrast Setting
4 RS Register Select
5 R/W Read/Write Select
6 En Chip Enable Signal
7-14 DB0-DB7 Data Lines
15 A/Vee Gnd for the backlight
16 K Vcc for backlight

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

Program:

ORG 0000H
MOV A,#38H
ACALL CMD
MOV A,#0EH
ACALL CMD
MOV A,#01H
ACALL CMD
MOV A,#06H
ACALL CMD
MOV A,#80H
ACALL CMD
MOV A,#'S'
ACALL DISP
MOV A,#'N'
ACALL DISP
MOV A,#'J'
ACALL DISP
MOV A,#'B‘
ACALL DISP

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

L1: SJMP L1

CMD: ACALL INIT


MOV P1,A
CLR P3.5
CLR P3.4
SETB P3.3
CALL DELAY
CLR P3.3
RET

DISP: ACALL INIT


MOV P1,A
SETB P3.5
CLR P3.4
SETB P3.3
ACALL DELAY
CLR P3.3
RET

INIT: CLR P3.3


CLR P3.5
MOV P1, #0FFH
SETB P3.4
L1: SETB P3.3
JB P1.7, L1
CLR P3.3

DELAY: MOV R3, #10


L1: MOV R4, #250
L2: DJNZ R4, L2
DJNZ R3, L1
RET
END

Interfacing of ADC0809 with 8051:

 Normally analogue-to-digital converter (ADC) needs interfacing through a


microprocessor to convert analogue data into digital format. This requires
hardware and necessary software, resulting in increased complexity and hence
the total cost. The circuit of A-to-D converter shown here is configured around
ADC 0809, avoiding the use of a microprocessor. The ADC 0809 is an 8-bit A-to-D
converter, having data lines D0-D7. It works on the principle of successive
approximation. It has a total of eight analogue input channels, out of which any
one can be selected using address lines A, B and C. Here, in this case, input
channel IN0 is selected by grounding A, B and C address lines.
 Usually the control signals EOC (end of conversion), SC (start conversion), ALE
(address latch enable) and OE (output enable) are interfaced by means of a

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

microprocessor. However, the circuit shown here is built to operate in its


continuous mode without using any microprocessor. Therefore the input control
signals ALE and OE, being active-high, are tied to Vcc (+5 volts). The input
control signal SC, being active-low, initiates start of conversion at falling edge of
the pulse, whereas the output signal EOC becomes high after completion of
digitization. This EOC output is coupled to SC input, where falling edge of EOC
output acts as SC input to direct the ADC to start the conversion.
 As the conversion starts, EOC signal goes high. At next clock pulse EOC output
again goes low, and hence SC is enabled to start the next conversion. Thus, it
provides continuous 8-bit digital output corresponding to instantaneous value of
analogue input. The maximum level of analogue input voltage should be
appropriately scaled down below positive reference (+5V) level.
 The ADC 0808 IC requires clock signal of typically 550 kHz, which can be easily
derived from an Astable multi-vibrator constructed using 7404 inverter gates. In
order to visualize the digital output, the row of eight LEDs (LED1 through LED8)
have been used, where in each LED is connected to respective data lines D0
through D7. Since ADC works in the continuous mode, it displays digital output
as soon as analogue input is applied. The decimal equivalent digital output value
D for a given analogue input voltage Vin can be calculated from the relationship.

Program:
ALE EQU P3.4
OE EQU P3.7

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

START EQU P3.5


EOC EQU P3.6
SEL_A EQU P3.1
SEL_B EQU P3.2
SEL_C EQU P3.3
ADC_DATA EQU P1
ORG 0000H
MOV ADC_DATA, #0FFH ;DATA PORT AS A INPUT
SETB EOC ;EOC AS A INPUT
CLR ALE ;REST AS A OUTPUT
CLR OE
CLR START
SIGNALS
MAIN:
SETB SEL_A ;SELECT ANALOG CHANNEL 1
CLR SEL_B
CLR SEL_C
SETB ALE ;LATCH CHANNEL SELECT
SETB START ;START CONVERSION

CLR ALE
CLR START
HERE: JB EOC, HERE ; WAIT FOR END OF CONVERSION
HERE1:JNB EOC, HERE1
SETB OE ;ASSERT READ SIGNAL
MOV A, ADC_DATA ;READ DATA
CLR OE ;START OVER FOR NEXT CONVERSION
SJMP MAIN
END

Interfacing of 4x4 Keypad with 8051:

Hex key pad is essentially a collection of 16 keys arranged in the form of a 4×4 matrix.
Hex key pad usually have keys representing numerics 0 to 9 and characters A to F. The
simplified diagram of a typical hex key pad is shown in the figure below.

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

The hex keypad has 8 communication lines namely R1, R2, R3, R4, C1, C2, C3 and C4. R1
to R4 represents the four rows and C1 to C4 represents the four columns. When a
particular key is pressed the corresponding row and column to which the terminals of
the key are connected gets shorted. For example if key 1 is pressed row R1 and column
C1 gets shorted and so on. The program identifies which key is pressed by a method
known as column scanning. In this method a particular row is kept low (other rows are
kept high) and the columns are checked for low. If a particular column is found low then
that means that the key connected between that column and the corresponding row
(the row that is kept low) is been pressed.

Interfacing hex keypad to 8051:

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

The circuit diagram for demonstrating interfacing hex keypad to 8051 is shown
below. AT89S51 is the microcontroller used here. The circuit will display the
character/numeric pressed on a seven segment LED display. The circuit is very simple
and it uses only two ports of the microcontroller, one for the hex keypad and the other
for the seven segment LED display.
The hex keypad is interfaced to port 1 and seven segment LED display is
interfaced to port 0 of the microcontroller. Resistors R1 to R8 limits the current through
the corresponding segments of the LED display. Capacitors C1, C2 and crystal X1
completes the clock circuitry for the microcontroller. Capacitor C3, resistor R9 and push
button switch S1 forms a debouncing reset mechanism.

Assembly Language Program:

ORG 0000H

MOV P1, #11111111B


ACALL DELAY

; ITERATION FOR ROW 1 SCANNING


MOV P1, #01111111B ; SCAN FOR ROW 0
L0: CJNE P1, #01110111B, L1
MOV P0, #01100000B ; DISPLAY 1
ACALL L0
L1: CJNE P1, #01111011B, L2
MOV P0, #11011010B ; DISPLAY 2
ACALL L0

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

L2: CJNE P1, #01111101B, L3


MOV P0, #11110010B ; DISPLAY 3
ACALL L0

L3: CJNE P1, #01111110B, L4


MOV P0, #11101110B ; DISPLAY A
ACALL L0

; ITERATION FOR ROW 2 SCANNING

L4: MOV P1, #10111111B


CJNE P1, #10110111B, L5
MOV P0, #01100110B ; DISPLAY 4
ACALL L0

L5: CJNE P1, #10111011B, L6


MOV P0, #10110110B ; DISPLAY 5
ACALL L0

L6: CJNE P1, #10111101B, L7


MOV P0, #10111110B ; DISPLAY 6
ACALL L0

L7: CJNE P1, #10111110B, L8


MOV P0, #00111110B ; DISPLAY b
ACALL L0

; ITERATION FOR ROW 3 SCANNING

L8: MOV P1, #11011111B


CJNE P1, #11010111B, L9
MOV P0, #11100000B ; DISPLAY 7
ACALL L0

L9: CJNE P1, #11011011B, L10


MOV P0, #11111110B ; DISPLAY 8
ACALL L0

L10: CJNE P1, #11011101B, L11


MOV P0, #11110110B ; DISPLAY 9
ACALL L0

L11: CJNE P1, #11011110B, L12


MOV P0, #10011100B ; DISPLAY C
ACALL L0

; ITERATION FOR ROW 4 SCANNING

L12: MOV P1, #11101111B


CJNE P1, #11100111B, L13

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

MOV P0, #10011110B ; DISPLAY E


ACALL L0

L13: CJNE P1, #11101011B, L14


MOV P0, #11111100B ; DISPLAY 0
ACALL L0

L14: CJNE P1, #11101101B, L15


MOV P0, #10001110B ; DISPLAY F
ACALL L0

L15: CJNE P1, #11101110B, L0


MOV P0, #01111010B ; DISPLAY D
ACALL L0

DELAY:
MOV R3, #10
L20: MOV R4, #250
L21: DJNZ R4, L21
DJNZ R3, L20
RET

END

Software Debugging Tools used in Embedded System:


Integrated development environment (IDE):

• An Integrated Development Environment (IDE) is software that assists


programmers in developing software (and only software!)
• IDEs normally consist of a source code editor, a compiler, a linker/locater and
usually a debugger.
• Sometimes, an IDE is devoted to one specific programming language or one
specific processor or hardware, but more often the IDEs support multiple
languages, processors, etc
• Some commonly used IDEs for embedded systems are the GNU compiler
collection (gcc) , Eclipse , Delphi , Kylix , KDevelop , Matlab, Microsoft Visual
Studio , Netbeans , Powerbuilder , DevC++, Jdeveloper, IntelliJ, etc.

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

Editor:

• A source code editor is a text editor program designed specifically for editing
source code to control embedded systems.
• It may be a standalone application or it may be built into an integrated
development environment (e.g. IDE)
• Source code editors may have features specifically designed to simplify and
speed up input of source code, such as syntax highlighting and auto complete
functionality.
• . These features ease the development of code
• Some commonly used editors for embedded systems are BBEdit (for Mac),
Emacs (GNU), Kate (KDE), Microsoft Visual Studio (built-in editor) and Vi (vim)

Compiler:

• A compiler is a computer program that translates the source code into computer
language (object code).
• Commonly the output has a form suitable for processing by other programs (e.g.,
a linker), but it may be a human-readable text file.
• A compiler translates source code from a high level language to a lower level
language (e.g., assembly language or machine language).
• The most common reason for wanting to translate source code is to create a
program that can be executed on a computer or on an embedded system.

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

• The compiler is called a cross compiler if the source code is compiled to run on a
platform other than the one on which the cross compiler is run.
• For embedded systems the compiler always runs on another platform, so a cross
compiler is needed.
• A cross compiler is a tool that one must use for a platform where it is
inconvenient or impossible to compile on that platform, like micro controllers
that run with a minimal amount of memory for their own purpose.
• Some commonly used compilers for embedded systems are GCC (GNU), Visual
C/C++, CPPBuilder (Delphi/Kylix).

Assembler:

• An assembler is a program that translates symbolic code (assembly language)


into executable object code.
• This object code can be executed with a 80C51-compatible microcontroller.
• This sequence of assembler instructions, known as the source code or source
program, is specified to the assembler when that program is started
• The assembler takes each program statement in the source program and
generates a corresponding bit stream or pattern (a series of 0's and 1's of a given
length).
• The output of the assembler program is called the object code or object program
relative to the input source program.
• The object program can then be run (or executed) whenever desired.

Linker:

• A linker or link editor is a program that takes one or more objects generated by
compilers and assembles them into a single executable program or a library that
can later be linked to in itself.
• All of the object files resulting from compiling must be combined in a special way
before the program can be executed.
• The object files themselves are individually incomplete, most notably is that
some of the internal variable and function references have not yet been resolved.
• The job of the linker is to combine these object files and, in the process, to
resolve all of the unresolved symbols.
• Linkers can take objects from a collection called a library. Some linkers do not
include the whole library in the output.
• They only include its symbols that are referenced from other object files or
libraries. Libraries for diverse purposes exist, and one or more system libraries
are usually linked in by default.
• Unfortunately, the standard library routines often require some changes before
they can be used in an embedded program.
• The problem here is that the standard libraries provided with most software
development tool suites arrive only in object form. So you only rarely have
access to the library source code to make the necessary changes yourself.

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

Debugger:

• A debugger is a computer program that is used to test and debug other


programs.
• The code to be examined might alternatively be running on an instruction set
simulator (ISS), a technique that allows great power in its ability to halt when
specific conditions are encountered but which will typically be much slower than
executing the code directly on the appropriate processor.
• When the program crashes, the debugger shows the position in the original code
if it is a source-level debugger or symbolic debugger.
• Often programmers use bugdatabases. A bugdatabase-program makes it
possible to database of all the bugs with their description.

Simulator:

• A simulator is a software that duplicates some processor in almost all the


possible ways.
• Usually the simulators are used for the testing of new architectures and also to
give training in some complex systems.
• A simulator is a program which runs on the development system (i.e. your PC)
and imitates the architecture of the target processor.
• For example an 8051 simulator will contain simulated registers, RAM and other
stuff on your PC screen.
• example an 8051 simulator will contain simulated registers, RAM and other stuff
on your PC screen. You can run your program in this simulator and verify the
functionality. You can single step your program, run it up to a certain address,
add breakpoints etc.

Hardware Debugging Tools:


In Circuit Emulator:

1. In-circuit emulation (ICE) is used to debug the software of an embedded system.


2. It operates by using a processor with the additional ability to support debugging
operations, as well as to carry out the main function of the system.
3. The ICE is temporarily installed between the embedded system and an
external terminal or personal computer so that the programmer can observe and
alter what takes place in the embedded system, which has no display or
keyboard of its own.
4. An ICE serves as a "surrogate" CPU (central processing unit) for
the microcomputer in an embedded system. The ICE usually has a connector that
fits the CPU socket in the system.

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad


Dept. of Electronics & Telecommunication engg. Microcontrollers

Development Board:

1. A microprocessor development board is a printed circuit board containing


a microprocessor and the minimal support logic needed for an engineer to
become acquainted with the microprocessor on the board and to learn to
program it.
2. It also served users of the microprocessor as a method to prototype applications
in products.
3. Unlike a general-purpose system such as a home computer, usually a
development board contains little or no hardware dedicated to a user interface.
4. It will have some provision to accept and run a user-supplied program, such as
downloading a program through a serial port to flash memory, or some form
of programmable memory in a socket in earlier systems.

Digital storage oscilloscope:

1. A digital storage oscilloscope (often abbreviated DSO) is an oscilloscope which


stores and analyses the signal digitally rather than using analog techniques.
2. It is now the most common type of oscilloscope in use because of the advanced
trigger, storage, display and measurement features which it typically provides.
3. The input analog signal is sampled and then converted into a digital record of the
amplitude of the signal at each sample time.
4. The principal advantage over analog storage is that the stored traces are as
bright, as sharply defined, and written as quickly as non-stored traces.
5. Traces can be stored indefinitely or written out to some external data storage
device and reloaded.

Logic analyser:

1. logic analyzer is an electronic instrument that captures and displays


multiple signals from a digital system or digital circuit.
2. A logic analyzer may convert the captured data into timing diagrams, protocol
decodes, state machine traces, assembly language, or may correlate assembly with
source-level software.
3. Logic Analyzers have advanced triggering capabilities, and are useful when a
user needs to see the timing relationships between many signals in a digital
system.
4.

SNJB’s Late Sau K. B. Jain College of engineering, Chandwad

You might also like