Unit 2 Notes
Unit 2 Notes
Microcontrollers
Interfacing of LEDS:
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
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
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
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
L1: SJMP L1
Program:
ALE EQU P3.4
OE EQU P3.7
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
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.
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.
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.
ORG 0000H
DELAY:
MOV R3, #10
L20: MOV R4, #250
L21: DJNZ R4, L21
DJNZ R3, L20
RET
END
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.
• 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:
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.
Debugger:
Simulator:
Development Board:
Logic analyser: