Download as pdf or txt
Download as pdf or txt
You are on page 1of 58

EE8551 – MICROPROCESSORS

AND MICROCONTROLLERS

23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India1
UNIT V
MICRO CONTROLLER PROGRAMMING &
APPLICATIONS

Simple programming exercises – keyboard and display


interface – Control of servo motor – stepper motor
control - Application to automation systems.

23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India2
Programming of 8051
• Programming in the sense of Microcontrollers means writing a
sequence of instructions that are executed by the processor in a
particular order to perform a predefined task. Programming also
involves debugging and troubleshooting of instructions and
instruction sequence to make sure that the desired task is
performed.
• Like any language, Programming Languages have certain words,
grammar and rules. There are three types or levels of
Programming Languages for 8051 Microcontroller.
Machine Language
Assembly Language
High-level Language
23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India3
Programming of 8051

23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India5
Simple Programming Exercises
Example 2
Write a program to add the values of locations 50H and 51H and store
the result in locations in 52h and 53H.

ORG 0000H ; Set program counter 0000H


MOV A,50H ; Load the contents of Memory location 50H into A ADD A,
51H ; Add the contents of memory 51H with Contents of A MOV 52H,A ;
Save the LS byte of the result in 52H
MOV A, #00 ; Load 00H into A
ADDC A, #00 ; Add the immediate data and carry to A
MOV 53H,A ; Save the MS byte of the result in location 53h
END
23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India6
Simple Programming Exercises
Example 3
Write a program to subtract a
16 bit number stored at
locations 51H-52H from
55H-56H and store the result in
locations 40H and 41H.
Assume that the least
significant byte of data or the
result is stored in low address.
If the result is positive, then
store 00H, else store 01H in
42H.

23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India7
Simple Programming Exercises
Example 5
Divide the content of r0 by r1. Store the result in r2 (Quotient)
and r3 (reminder). Then restore the original content of r0.
Mov a, r0                     ; get the content of r0 and r1
Mov b, r1                     ; in register A and B
Div ab                          ; divide A by B
Mov r2, a                     ; store result in r2
Mov r3, b                     ; and reminder in r3
Mov b, r1                     ; again get content of r1 in B
Mul ab                         ; multiply it by answer
Add a, r3                     ; add reminder in new answer
Mov r0, a                     ; finally restore the content of r0

23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India8
Interfacing keyboard with 8051

https://youtu.
be/975CS27w16w
Keyboard Interfacing
23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India9
Interfacing LCD with 8051

https://youtu.be/THmaKk5nJRc
LCD Interfacing

23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India
15
1. Vss – Ground
2. Vcc- power supply of +5 v
3. Vee- power supply backlight connected to resistor
4. Rs-Register select
Command or data

•0-data treated as command


•1-data treated as data

5. Read/Write
0- write operation
1- Read operation
6.Enable pin

Low-data available
High-data not available

7 .8 data pins to carry forward information


Interfacing Stepper Motor
with 8051

https://youtu.be/pRII3dBKIc8
Stepper Motor Interfacing

23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India
20
Interfacing DC Motor with 8051

https://youtu.be/kTtt09uX894
DC Motor Interfacing
23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India
31
23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India
42
Interfacing Servo Motor with 8051

https://www.youtube.com/watch?
v=ditS0a28Sko
23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India
43
Servo Motor
Interfacing Relay with 8051

https://youtu.be/t--71LFuTW4
Relay Interfacing

23 November 2022 KPR Institute of Engineering and Technology, Coimbatore, Tamil Nadu, India
49

You might also like