Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 54

Microcontroller & embedded system

MICROCONTROLLER

&

EMBEDDED SYSTEM

LABMANUAL
Microcontroller & embedded system

Programs based on data transfer Instructions.


Microcontroller & embedded system

1. Write a program to load accumulator A,DPH & DPL with 30h

Address Hex code Label Mnemonic Comment


100 MOV A,#30H
MOV DPH, A
MOV DPL, A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


A=00h A=
DPH=00h DPL=
DPL=00h DPL=

2. Write a program to put the number 90h in R2 & R3.

Address Hex code Label Mnemonic Comment


100 MOV R2, #90H
MOV R3, #90H
HERE SJMP HERE

OUTPUT:-

Before execution After execution


R2=00h R2=
R3=00h R3=

3. Write a program to set timer 1 to initial value 12ADh.

Address Hex code Label Mnemonic Comment


100 MOV TL1, #0ADH
MOV TH1, #12H
HERE SJMP HERE
Microcontroller & embedded system

OUTPUT:-

Before execution After execution


TL1=00h TL1=
TH1=00h TH1=

4. Write a program to copy the content of R5 to external memory location 032Fh.

Address Hex code Label Mnemonic Comment


100 MOV A,R5
MOV DPTR, #032FH
MOVX @DPTR,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


R5=25h R5=
[032Fh]=00h [032Fh]=

5. Write a program to store DPTR in external RAM locations 0123h(DPL) &


02BCh(DPH)

Address Hex code Label Mnemonic Comment


100 MOV R0,DPL
MOV R1,DPH
MOV DPTR,#0123H
MOV A,R0
MOVX @DPTR, A
MOV DPTR, #02BCH
MOV A,R1
MOVX @DPTR, A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


DPTR=12A6H DPTR=
Microcontroller & embedded system

[0123H]=00H [0123H]=
[02BCH]=00H [02BCH]=

6. Write a program to exchange both low nibbles of registers R0 & R1.

Address Hex code Label Mnemonic Comment


100 MOV A,R0
MOV 08H,R1
MOV R0,#08H
XCHD A, @R0
MOV R0,A
MOV R1,08H
HERE SJMP HERE

OUTPUT:-

Before execution After execution


R0=89H R0=
R1=76H R1=

7. Write a program to SWAP the bytes in timer 0: i.e. put TL0 in TH0 and TH0 in
TL0.

Address Hex code Label Mnemonic Comment


100 MOV A, TL0
MOV R0, TH0
XCH A,R0
MOV TL0,A
MOV TH0, R0
HERE SJMP HERE

OUTPUT:-

Before execution After execution


TL0=34H TL0=
TH0=A0H TH0=
Microcontroller & embedded system

8. Write a program to Store the content of register R3 at the internal RAM address
contained in R2.

Address Hex code Label Mnemonic Comment


100 MOV A,R2
MOV R0,A
MOV A,R3
MOV @R0,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


R3=2Ah R3=
R2=08h R2=
[08h]=00h [08h]=
Microcontroller & embedded system

Programs Based on Arithmetic Instructions.


Microcontroller & embedded system

1. Write a program to add the bytes in RAM locations 34h & 35h, put the result in
registers R5(LSB) & R6(MSB).

Address Hex code Label Mnemonic Comment


100 MOV R6,#00H
MOV A,34H
ADD A,35H
MOV R5,A
MOV A,#00H
ADDC A,R6
MOV R6,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


[34h]=FFh [34h]=
[35h]=FFh [35h]=
R5=00h R5=
R6=00h R6=

2. Write a program to add the bytes in external RAM locations 02CDH to internal
RAM location 19h, put the result into external RAM location 00C0h(LSB) &
00C1H(MSB).

Address Hex code Label Mnemonic Comment


100 MOV R6,#00H
MOV DPTR,#02CDH
MOVX A, @DPTR
ADD A,19H
MOV DPTR,#00C0H
MOVX @DPTR,A
MOV A,#00H
ADDC A, R6
INC DPTR
MOVX @DPTR,A
HERE SJMP HERE
Microcontroller & embedded system

OUTPUT:-

Before execution After execution


[02CDH]=FFh [02CDH]=FFH
[19h]=01h [19h]=01H
[00C0H]=00H [00C0H]=
[00C1H]=00H [00C1H]=

3. Write a program to subtract the contents of R2 from the number F3h, put the result in
external RAM location 028Bh.

Address Hex code Label Mnemonic Comment


100 CLR C
MOV A,#0F3H
SUBB A,R2
MOV DPTR, #028BH
MOVX @DPTR,A
HERE SJMP HERE

OUTPUT:-
Before execution After execution
R2=55H R2=
[028BH]=00H [028BH]=

4. Write a program to subtract the contents of RAM location 13h from RAM location
2Bh, put the result in RAM location 3Ch.

Address Hex code Label Mnemonic Comment


100 CLR C
MOV A,2BH
MOV R0,13H
SUBB A,R0
MOV 3CH,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


[13H]=25H [13H]=25H
[2BH]=11H [2BH]=11H
Microcontroller & embedded system

[3CH]=00H [3CH]=

5. Write a program to add a 1 to every external RAM address from 00h to 06h.

Address Hex code Label Mnemonic Comment


100 MOV R0,#00H
MOVX A, @R0
INC A
MOVX @R0,A
INC R0
MOVX A, @R0
INC A
MOVX @R0,A
INC R0
MOVX A, @R0
INC A
MOVX @R0,A
INC R0
MOVX A, @R0
INC A
MOVX @R0,A
INC R0
MOVX A, @R0
INC A
MOVX @R0,A
INC R0
MOVX A, @R0
INC A
MOVX @R0,A
INC R0
MOVX A, @R0
INC A
MOVX @R0,A
HERE SJMP HERE
OUTPUT:-

Before execution After execution


[00H]=00H [00H]=
[01H]=02H [01H]=
Microcontroller & embedded system

[02H]=03H [02H]=
[03H]=22H [03H]=

[04H]=23H [04H]=

[05H]=F0H [05H]=

[06H]=FFH [06H]=

6. Write a program to decrement external RAM locations 0123h & 01BDh.

Address Hex code Label Mnemonic Comment


100 MOV DPTR,#0123H
MOVX A,@DPTR
DEC A
MOVX @DPTR,A
MOV DPTR,#01BDH
MOVX A,@DPTR
DEC A
MOVX @DPTR,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


[0123H]=00H [0123H]=
[01BDH]=55H [01BDH]=

7. Write a program to square the content of R5, put the result in R0(Higher byte) &
R1(Lower byte).

Address Hex code Label Mnemonic Comment


100 MOV A,R5
MOV B,A
MUL AB
MOV R1,A
MOV R0,B
HERE SJMP HERE

OUTPUT:-

Before execution After execution


R5=[02H] R5=
R0=00H R0=
R1=00H R1=
Microcontroller & embedded system

8. Write a program to divide the number in RAM 15h by the data in RAM location 16h,
put the resulting quotient in external RAM locations 7Ch.

Address Hex code Label Mnemonic Comment


100 MOV A,15H
MOV B,16H
DIV AB
MOV R0,#7CH
MOVX @R0,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


[15H]=04H [15H]=
[16H]=02H [16H]=
External RAM [7Ch]=00h External RAM [7Ch]=00h
Microcontroller & embedded system

Programs Based on Logical Instructions.


Microcontroller & embedded system

1. Write a program to set port 0,bits 1,3,5 & 7 to 1;set the rest to 0.

Address Hex code Label Mnemonic Comment


100 MOV A,#0AAH A=10101010B
MOV P0,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


P0=FFH P0=
A=00H A=

2. Write a program to clear bit 3 of RAM location 22h without affecting any other bit.

Address Hex code Label Mnemonic Comment


100 CLR 13H 13H is bit address of

clear bit 3 of RAM


location 22h

HERE SJMP HERE

OUTPUT:-
Microcontroller & embedded system

Before execution After execution


[22H]=FFH [22H]=

3. Write a program to invert the data on port 0 pins and write the data to port 1.

Address Hex code Label Mnemonic Comment


100 MOV A,P0
CPL A
MOV P1,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


P0=AAH P0=
P1=FFH P1=

4. Write a program to swap the nibbles of R0 & R1 so that the low nibble of R0 swaps with
the high nible of R1 & the high nibble of R0 swaps with the low nibble of R1.

R1
2 3

R0
5 8
Before execution

R1
8 5

R0
3 2

After execution
Microcontroller & embedded system

Address Hex code Label Mnemonic Comment


100 MOV A,R0
SWAP A
MOV R2,A
MOV A,R1
SWAP A
MOV R0,A
MOV A, R2
MOV R1,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


R0=58H R0=
R1=23H R1=

5. Write a program to complement the lower nibble of internal RAM location 2Ah.

Address Hex code Label Mnemonic Comment


100 MOV A,#0Fh
XRL 2Ah,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


A=00h A=
[2Ah]=FFh [2Ah]=

6. Write a program to move bit 6 of R0 to bit 3 of port 3.

Address Hex code Label Mnemonic Comment


100 MOV 20H,R0
MOV C,06H
MOV P3.3,C
HERE SJMP HERE

OUTPUT:-
Microcontroller & embedded system

Before execution After execution


R0=00H R0=
P3=FFH P3=

7. Write a program to move bit 4 of RAM location 30h to bit 2 of A.

Address Hex code Label Mnemonic Comment


100 MOV 20H,30H
MOV C,04H
MOV ACC.2,C
HERE SJMP HERE

OUTPUT:-

Before execution After execution


30H= 30H=
ACC.2= ACC.2=

8. Write a program to store the least significant nibble of A in both nibbles of RAM
address 3Ch; for example if A=36h,then [3Ch]=66h.

Address Hex code Label Mnemonic Comment


100 ANL A, #0FH
MOV 3CH, #00H
ORL A, 3CH
MOV 3CH,A
SWAP A
ORL A,3CH
MOV 3CH,A
HERE SJMP HERE

OUTPUT:-

Before execution After execution


A=36H A=
[3CH]=00 [3CH]=

9. Write a program to Set the carry flag to 1 if the number in A is even; set the carry flag
to 0 if the number in A is odd.

Address Hex code Label Mnemonic Comment


100 MOV R0,A
Microcontroller & embedded system

RRC A
MOV A,R0
HERE SJMP HERE

OUTPUT:-

Before execution After execution


A=36H A=
CARRY FLAG=0 CARRY FLAG=

10. Write a program to rotate the DPTR one place to the left; bit 15 becomes bit 0.

Address Hex code Label Mnemonic Comment


100 CLR C

MOV A,DPL

RLC A

MOV A,DPH

RLC A

MOV DPH,A

MOV A,DPL

RLC A

MOV DPL,A

HERE HERE:SJMP HERE

OUTPUT:-

Before execution After execution


DPTR=1234H DPTR=
Microcontroller & embedded system
Microcontroller & embedded system

Programs Based on Jump Instructions.

1. Write a program to increment the number stored in R3 until it equals E1h.


Microcontroller & embedded system

Address Hex code Label Mnemonic Comment


100 START CLR C
MOV A,#0E1H
SUBB A, R3
JZ HERE
INC R3
SJMP START
HERE SJMP HERE

OUTPUT:-

Before execution After execution


R3=20H R3=

2. Write a program to decrement the number stored in R3 until it equals E1h.

Address Hex code Label Mnemonic Comment


100 START CLR C
MOV A,#0E1H
SUBB A, R3
JZ HERE
DEC R3
SJMP START
HERE SJMP HERE

OUTPUT:-

Before execution After execution


R3=20H R3=

3. Write a program to decrement the numbers stored in internal RAM locations 20h(LSB)
& 21h(MSB) & decrement them as if they were a single 16-bit counter until they equal
numbers in R2(LSB) & R3(MSB).

Address Hex code Label Mnemonic Comment


100 START CLR C
MOV A,20H
SUBB A,R2
JNZ SKIP
CLR C
MOV A,21H
Microcontroller & embedded system

SUBB A,R3
JZ HERE
SKIP DEC 20H
CJNE 20H,#0FFH, ABC
DEC 21H
ABC SJMP START
HERE SJMP HERE

OUTPUT:-

Before execution After execution


R2=20H R2=
R3=45H R3=
[20H]=11H [20H]=
[21H]=22H [21H]=

4. Write a program to set the carry flag to 1 if the lower nibble of any number placed in A
is larger than the upper nibble.

Address Hex code Label Mnemonic Comment


100 MOV R0,A
ANL A,#0FH
MOV R1,A
MOV A,R0
ANL A,#F0H
SWAP A
CLR C
SUBB A,R1
HERE SJMP HERE

OUTPUT:-

Before execution After execution


A=35H A=
CARRY FLAG=0 CARRY FLAG=
Microcontroller & embedded system

5. Write a program to count the number of 1s in any number in register B & put the count
in R5

Address Hex code Label Mnemonic Comment


100 MOV R5,#00H
MOV R1,#08H
MOV A,B
AGAIN: RLC A
JNC SKIP
INC R5
SKIP: DJNZ R1,AGAIN
HERE: SJMP HERE

OUTPUT:-

Before execution After execution


R5=00H R5=
B=F9H B=
R1=08H R1=

6. Write a program to decrement the DPTR from any initialize value to 0033h as a 16 bit
register.

Address Hex code Label Mnemonic Comment


100 MOV R0,DPL
MOV R1,DPH
AGAIN: CJNE R1,#00H,SKIP
CJNE R0,#33H,SKIP
SJMP XYZ
SKIP: DEC R0
MOV A,R0
JNZ ABC
DEC R1
ABC: SJMP AGAIN
XYZ: MOV DPL,R0
MOV DPH,R1
HERE: SJMP HERE
Microcontroller & embedded system

OUTPUT:-

Before execution After execution


DPTR=0067H DPTR=
R0=00H R0=
R1=00H R1=

7. Write a program to get the contents of PC to the DPTR.

Address Hex code Label Mnemonic Comment


100 MOV SP,#10H
ACALL ABC
SJMP HERE
ABC: MOV DPL,11H
MOV DPH,12H
RET
HERE: SJMP HERE

OUTPUT:-

Before execution After execution


DPTR=0000H DPTR=

8. Write a program to put one random number in R2 and another in R5. Increment R2 &
decrement R5 until they are equal.

Address Hex code Label Mnemonic Comment


100 AGAIN: INC R2
DEC R5
MOV A,R2
MOV 20H,R5
CJNE A,20H,AGAIN
HERE: SJMP HERE

OUTPUT:-

Before execution After execution


R2=23H R2=
R5=77H R5=
Microcontroller & embedded system

9. Write a program to fill external RAM locations 100h to 200h with the number AAh.

Address Hex code Label Mnemonic Comment


100 MOV DPTR,#100H
MOV A,#0AAH
MOV R5,#0FFH
AGAIN: MOVX @DPTR,A
INC DPTR
DEC R5
CJNE R5,#0FEH,AGAIN
MOVX @DPTR,A
HERE: SJMP HERE

OUTPUT:-

Before execution After execution


R2=23H R2=
R5=77H R5=
Microcontroller & embedded system

Aim:To Interface LED display with 8051.

Appratus:-8051 trainer kit, 7-segment LED display interfacing board.

Theory:-

7 segment LED display is very popular and it can display digits from 0 to 9 and quite a few
characters like A, b, C, ., H, E, e, F, n, o,t,u,y, etc. Knowledge about how to interface a seven
segment display to a micro controller is very essential in designing embedded systems. A
seven segment display consists of seven LEDs arranged in the form of a squarish ’8′ slightly
inclined to the right and a single LED as the dot character. Different characters can be
displayed by selectively glowing the required LED segments. Seven segment displays are of
two types, common cathode and common anode. In common cathode type , the cathode of all
LEDs are tied together to a single terminal which is usually labeled as ‘com‘ and the anode of
all LEDs are left alone as individual pins labeled as a, b, c, d, e, f, g & h (or dot) . In common
anode type, the anode of all LEDs are tied together as a single terminal and cathodes are left
alone as individual pins. The pin out scheme and picture of a typical 7 segment LED display is
shown in the image below.

7 segment LED display


Microcontroller & embedded system

Digit drive pattern.


Digit drive pattern of a seven segment LED display is simply the different logic combinations
of its terminals ‘a’ to ‘h‘ in order to display different digits and characters. The common digit
drive patterns (0 to 9) of a seven segment display are shown in the table below.
Digit a b c d e f g
0 1 1 1 1 1 1 0
1 0 1 1 0 0 0 0
2 1 1 0 1 1 0 1
3 1 1 1 1 0 0 1
4 0 1 1 0 0 1 1
5 1 0 1 1 0 1 1
6 1 0 1 1 1 1 1
7 1 1 1 0 0 0 0
8 1 1 1 1 1 1 1
9 1 1 1 1 0 1 1
Microcontroller & embedded system

Interfacing seven segment display to 8051.

Interfacing 7 segment display to 8051

The circuit diagram shown above is of an AT89S51 microcontroller based 0 to 9 counter


which has a 7 segment LED display interfaced to it in order to display the count. This simple
circuit illustrates two things. How to setup simple 0 to 9 up counter using 8051 and more
importantly how to interface a seven segment LED display to 8051 in order to display a
particular result. The common cathode seven segment display D1 is connected to the Port 1 of
the microcontroller (AT89S51) as shown in the circuit diagram. R3 to R10 are current limiting
resistors. S3 is the reset switch and R2,C3 forms a debouncing circuitry. C1, C2 and X1 are
related to the clock circuit. The software part of the project has to do the following tasks.
● Form a 0 to 9 counter with a predetermined delay (around 1/2 second here).
● Convert the current count into digit drive pattern.
● Put the current digit drive pattern into a port for displayin
Microcontroller & embedded system

Program:-
ORG 100h
START: MOV A,#00001001B // initial value of accumulator
MOV B,A
MOV R0,#0AH //Register R0 initialized as counter which
counts from 10 to 0
LABEL: MOV A,B
INC A
MOV B,A
MOVC A,@A+PC // adds the byte in A to the
program counters

address
MOV P1,A
ACALL DELAY // calls the delay of the timer
DEC R0//Counter R0 decremented by 1
MOV A,R0 // R0 moved to accumulator to check if
it is zero in next instruction.
JZ START //Checks accumulator for zero and
jumps to START. Done to check if counting has been
finished.
SJMP LABEL
DB 3FH // digit drive pattern for 0
DB 06H // digit drive pattern for 1
DB 5BH // digit drive pattern for 2
DB 4FH // digit drive pattern for 3
DB 66H // digit drive pattern for 4
DB 6DH // digit drive pattern for 5
DB 7DH // digit drive pattern for 6
DB 07H // digit drive pattern for 7
DB 7FH // digit drive pattern for 8
DB 6FH // digit drive pattern for 9
DELAY: MOV R4,#05H // subroutine for delay
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET
END
Microcontroller & embedded system

Questions:-
1. Which segments should be on to display 5?
2. Explain Common cathode 7-segment display.
3. Explain Common anode 7-segment display.
4. Why series registers are connected in series with LED 7-segment display?

Conclusion:-
Microcontroller & embedded system

Aim:To Interface LCD display with 8051.

Appratus:-8051 trainer kit, LCD interfacing module.

Theory:
LCD display is an inevitable part in almost all embedded projects and this article is about
interfacing 16×2 LCD with 8051 microcontroller. Many guys find it hard to interface LCD
module with the 8051 but the fact is that if you learn it properly, its a very easy job and by
knowing it you can easily design embedded projects like digital voltmeter / ammeter, digital
clock, home automation displays, status indicator display, digital code locks, digital
speedometer/ odometer, display for music players etc etc. Thoroughly going through this
article will make you able to display any text (including the extended characters) on any part
of the 16×2 display screen. In order to understand the interfacing first you have to know about
the 16×2 LCD module.

16×2 LCD module:-


16×2 LCD module is a very common type of LCD module that is used in 8051 based
embedded projects. It consists of 16 rows and 2 columns of 5×7 or 5×8 LCD dot matrices. The
module were are talking about here is type number JHD162A which is a very popular one . It
is available in a 16 pin package with back light ,contrast adjustment function and each dot
matrix has 5×8 dot resolution. The pin numbers, their name and corresponding functions are
shown in the table below.
Pin No: Name Function
1 VSS This pin must be connected to the ground
2 VCC Positive supply voltage pin (5V DC)
3 VEE Contrast adjustment
4 RS Register selection
5 R/W Read or write
6 E Enable
7 DB0 Data
8 DB1 Data
9 DB2 Data
10 DB3 Data
11 DB4 Data
12 DB5 Data
Microcontroller & embedded system

13 DB6 Data
14 DB7 Data
15 LED+ Back light LED+
16 LED- Back light LED-

VEE pin is meant for adjusting the contrast of the LCD display and the contrast can be
adjusted by varying the voltage at this pin. This is done by connecting one end of a POT to the
Vcc (5V), other end to the Ground and connecting the center terminal (wiper) of of the POT to
the VEE pin. See the circuit diagram for better understanding.
The JHD162A has two built in registers namely data register and command register. Data
register is for placing the data to be displayed , and the command register is to place the
commands. The 16×2 LCD module has a set of commands each meant for doing a particular
job with the display. We will discuss in detail about the commands later. High logic at the RS
pin will select the data register and Low logic at the RS pin will select the command register.
If we make the RS pin high and the put a data in the 8 bit data line (DB0 to DB7) , the LCD
module will recognize it as a data to be displayed . If we make RS pin low and put a data on
the data line, the module will recognize it as a command.
R/W pin is meant for selecting between read and write modes. High level at this pin enables
read mode and low level at this pin enables write mode.
E pin is for enabling the module. A high to low transition at this pin will enable the module.
DB0 to DB7 are the data pins. The data to be displayed and the command instructions are
placed on these pins.
LED+ is the anode of the back light LED and this pin must be connected to Vcc through a
suitable series current limiting resistor. LED- is the cathode of the back light LED and this pin
must be connected to ground.

16×2 LCD module commands:-


16×2 LCD module has a set of preset command instructions. Each command will make the
module to do a particular task. The commonly used commands and their function are given in
the table below.
Command Function
0F LCD ON, Cursor ON, Cursor blinking
ON
01 Clear screen
2 Return home
4 Decrement cursor
06 Increment cursor
E Display ON ,Cursor ON
Microcontroller & embedded system

80 Force cursor to the beginning of 1st line


C0 Force cursor to the beginning of 2nd line
38 Use 2 lines and 5×7 matrix
83 Cursor line 1 position 3
3C Activate second line
0C3 Jump to second line, position3
OC1 Jump to second line, position1

LCD initialization:-
The steps that has to be done for initializing the LCD display is given below and these steps
are common for almost all applications.
● Send 38H to the 8 bit data line for initialization
● Send 0FH for making LCD ON, cursor ON and cursor blinking ON.
● Send 06H for incrementing cursor position.
● Send 01H for clearing the display and return the cursor.

Sending data to the LCD:-


The steps for sending data to the LCD module is given below. I have already said that the LCD
module has pins namely RS, R/W and E. It is the logic state of these pins that make the
module to determine whether a given data input is a command or data to be displayed.
● Make R/W low.
● Make RS=0 if data byte is a command and make RS=1 if the data byte is a data to be
displayed.
● Place data byte on the data register.
● Pulse E from high to low.
● Repeat above steps for sending another data.
Microcontroller & embedded system

Circuit diagram:-

Interfacing 16x2 LCD module to 8051:-


The circuit diagram given above shows how to interface a 16×2 LCD module with AT89S1
microcontroller. Capacitor C3, resistor R3 and push button switch S1 forms the reset circuitry.
Ceramic capacitors C1,C2 and crystal X1 is related to the clock circuitry which produces the
system clock frequency. P1.0 to P1.7 pins of the microcontroller is connected to the DB0 to
DB7 pins of the module respectively and through this route the data goes to the LCD module.
P3.3, P3.4 and P3.5 are connected to the E, R/W, RS pins of the microcontroller and through
this route the control signals are transffered to the LCD module. Resistor R1 limits the current
through the back light LED and so do the back light intensity. POT R2 is used for adjusting the
contrast of the display.
Microcontroller & embedded system

Program:-
Subroutine CMND sets the logic of the RS, R/W, E pins of the LCD module so that the
module recognizes the input data ( given to DB0 to DB7) as a command.
Subroutine DISP sets the logic of the RS, R/W, E pins of the module so that the module
recognizes the input data as a data to be displayed .

ORG 100h
MOV A,#38H // Use 2 lines and 5x7 matrix
ACALL CMND
MOV A,#0FH // LCD ON, cursor ON, cursor blinking ON
ACALL CMND
MOV A,#01H //Clear screen
ACALL CMND
MOV A,#06H //Increment cursor
ACALL CMND
MOV A,#82H //Cursor line one , position 2
ACALL CMND
MOV A,#3CH //Activate second line
ACALL CMND
MOV A,#49D
ACALL DISP
MOV A,#54D
ACALL DISP
MOV A,#88D
ACALL DISP
MOV A,#50D
ACALL DISP
MOV A,#32D
ACALL DISP
MOV A,#76D
ACALL DISP
MOV A,#67D
ACALL DISP
MOV A,#68D
ACALL DISP
MOV A,#0C1H //Jump to second line, position 1
ACALL CMND

MOV A,#67D
ACALL DISP
MOV A,#73D
Microcontroller & embedded system

ACALL DISP
MOV A,#82D
ACALL DISP
MOV A,#67D
ACALL DISP
MOV A,#85D
ACALL DISP
MOV A,#73D
ACALL DISP
MOV A,#84D
ACALL DISP
MOV A,#83D
ACALL DISP
MOV A,#84D
ACALL DISP
MOV A,#79D
ACALL DISP
MOV A,#68D
ACALL DISP
MOV A,#65D
ACALL DISP
MOV A,#89D
ACALL DISP

HERE: SJMP HERE

CMND: MOV P1,A


CLR P3.5
CLR P3.4
SETB P3.3
CLR P3.3
ACALL DELY
RET;

DISP:MOV P1,A
SETB P3.5
CLR P3.4
SETB P3.3
CLR P3.3
ACALL DELY
RET;
Microcontroller & embedded system

DELY: CLR P3.3


CLR P3.5
SETB P3.4
MOV P1,#0FFh
SETB P3.3
MOV A,P1
JB ACC.7,DELY

CLR P3.3
CLR P3.4
RET;

END

Questions:-

1. What is the function of RS pin of LCD display?

2. What is the function pin of R/W pin of LCD display?

3. What is the function of E pin of LCD display?

Conclusion:-

Aim: To Interface Stepper Motor with 8051.


Microcontroller & embedded system

Apparatus:-8051 trainer kit, stepper motor module.

Theory:-

BASICS OF STEPPER MOTOR:-

Of all motors, step motor is the easiest to control. It's handling simplicity is really hard to deny
- all there is to do is to bring the sequence of rectangle impulses to one input of step controller
and direction information to another input. Direction information is very simple and comes
down to "left" for logical one on that pin and "right" for logical zero. Motor control is also
very simple - every impulse makes the motor operating for one step and if there is no impulse
the motor won't start. Pause between impulses can be shorter or longer and it defines
revolution rate. This rate cannot be infinite because the motor won't be able to "catch up" with
all the impulses (documentation on specific motor should contain such information). The
picture below represents the scheme for connecting the step motor to microcontroller and
appropriate program code follows.

The key to driving a stepper is realizing how the motor is constructed. A diagram shows the
representation of a 4 coil motor, so named because 4 coils are used to cause the revolution of
the drive shaft. Each coil must be energized in the correct order for the motor to spin.

In Figure boxes are used to represent


switches; a control unit, not shown, is
responsible for providing the control
signals to open and close the switches
at the appropriate times in order to
spin the motors. The control unit is
commonly a computer or
programmable interface controller, with software directly generating the outputs needed to
control the switches.

As with drive circuitry for variable reluctance motors, we must deal with the inductive kick
produced when each of these switches is turned off. Again, we may shunt the inductive kick
using diodes, but now, 4 diodes are required.
Step angle
It is angle through which motor shaft rotates in one step. step angle is different for different
Microcontroller & embedded system

motor . selection of motor according to step angle depends on the application , simply if you
require small increments in rottion choose motor having smaller step angle.
No of steps require to rotate one complete rotation = 360 deg. / step angle in deg.

Steps/second
The relation between RPM and steps per sec. is given by ,
steps or impulses /sec. =(RPM X Steps /revolution ) /60
Pause between impulses can be shorter or longer and it defines revolution rate. This rate
cannot be infinite because the motor won't be able to "catch up" with all the impulses
(documentation on specific motor should contain such information). So referring to RPM
value in datasheet you can calculate steps/sec and from it delay or pause between impulses
Interfacing Circuit:-

Step Sequence:-

Q4 Q2 Q3 Q1 Step
Microcontroller & embedded system

1 0 1 0 1

0 1 1 0 2

0 1 0 1 3

1 0 0 1 4

➢ Connect stepper motor interfacing module to 8255-I of 8051 trainer kit through 26 pin FRC
cable.
➢ Be sure about the direction of the cable i.e. pin no-1 of module should be connected to pin no.1
of 8255 connector.
➢ Connect +5V, GND from the trainer kit .
➢ Connect motor supply to +12V from the trainer kit.
➢ 8255 port address:-
Port A- FF00h
Port B-FF01H
Port C-FF02H
Control Word- FF03H

Program:-
ORG 3000h
MOV DPTR, #0FF03H
MOV A, #80H
MOVX @DPTR,A
START: MOV DPTR, #0FF00H
MOV A, #0FAH
MOVX @DPTR, A
ACALL DELAY
MOV A, #0F6H
MOVX @DPTR, A
ACALL DELAY
Microcontroller & embedded system

MOV A, #0F5H
MOVX @DPTR, A
ACALL DELAY
MOV A, #0F9H
MOVX @DPTR, A
ACALL DELAY
SJMP START

ORG 3050H
DELAY: MOV R7, #03FH ; DECREASE THIS NUMBER TO INCREASE SPEED
DELAY1: MOV R6, #03FH ; DECREASE THIS NUMBER TO INCREASE SPEED
DELAY2: DJNZ R6, DELAY2
DJNZ R7, DELAY1
RET

Questions:-

1. Write down the applications of stepper motor.

2. Write the formula for relation between RPM and steps per sec for stepper motor.

Conclusion:-
Microcontroller & embedded system

Aim:To Interface Opto-coupler with 8051.

Apparatus:-8051 trainer kit, Opto-coupler module

Theory:-
Basics of Opto-Coupler:
An opto-isolator, also known as an optical coupler or optocoupler, is a semiconductor device
that allows signals to be transferred between circuits or systems, while keeping those circuits
or systems electrically isolated from each other. Optoisolators are used in a wide variety of
communications, control, and monitoring systems.

The opto-coupler consists of two parts: 1. The LED Side and 2. Photo-Transistor side. Both
sides are separated and are not electrically connected. Only light can travel between the
LED and the photo-transistor. When an electrical signal is applied to the input of the opto-
isolator, its LED lights. This light falls on the photo transistor and it then activates.
A typical usage of an opto-coupler is as follows:
Microcontroller & embedded system

In the above circuit, a forward biasing voltage is applied to the LED making it light up. The R1
resistor is a current limiting resistor - to provide sufficient voltage drop required by the LED.
The LED triggers the Q1 Photo-transistor inside the opto-coupler. This can be used to produce
an output in common emmitter configuration.

Interfacing an Opto-Coupler with a Microcontroller


An Opto-coupler is generally used to in conjunction with micro-controllers as Inputs and
Outputs that need to be electrically isolated from the driving circuit.

Interfacing an Opto-coupler for Input to Microcontroller


In this case, the opto-coupler's LED is driven by the external circuit that needs to give input to
the microcontroller. The opto-coupler's photo-transistor drives the microcontroller's digital
input pin. The LED 's driving must be designed keeping in mind the required voltage level
drop. See the opto-coupler's data sheet for information on how to bias the LED properly.
The opto-coupler's photo-transistor is opticaly connected to the microcontroller pin. It can be
connected in a common drain with pull up or common source with pull down configuration.
Drain Configuration with Pull-up resistor:

If the opto's LED is off, the photo-transistor is turned off. The Collector will be in High-
impedence, that is, in a disconnected state. Hence, the week pull-up resistor will increase the
Microcontroller & embedded system

voltage in the microcontroller's pin and make it logical high. The Microcontroller's internal
circuits will sense this as logical LOW.
If the LED is turned on, the photo-transistor will conduct current from the collector to emitter.
This will cause the microcontroller pin to 'drain' and reduce its voltage to zero. This is because
the resistance of the collector-emitter path is too low comapred to the pull-up resistor. The
pull-up being week, will not be able to raise the voltage level of the pin sufficiently. The
microcontroller's internal circuits will sense this as logical HIGH.
when the LED is turned off again, the collector will become hi-impedence (disconnected) and
the pull-up will increase the value of the voltage to logical high levels. The Microcontroller's
internal circuits will sense this as logical LOW. If the pull-up resistor is too large in value, it
will take more time to pull up the pin to high. If it is too low, it will pull-up the pin very fast
but it will consume more power when the LED is turned on due higher current being drained.

Aim:To Interface D-to-A converter with 8051.

Apparatus:-8051 trainer kit, DAC 0800H module.

Theory:-

DAC0800 introduction
The DAC0800 series are monolithic 8-bit high-speed current-output digital-to-analog
converters (DAC) featuring typical settling times of 100 ns. The DAC0800 series also features
high compliance complementary current outputs to allow differential output voltages of 20 Vp-
Microcontroller & embedded system

p with simple resistor loads as shown in Figure below

Features of DAC0800

• Fast settling output current: 100 ns


• Full scale error: ±1 LSB
• Nonlinearity over temperature: ±0.1%
• Full scale current drift: ±10 ppm/°C
• High output compliance: −10V to +18V
• Complementary current outputs
• Interface directly with TTL, CMOS, PMOS and others
• 2 quadrant wide range multiplying capability
• Wide power supply range: ±4.5V to ±18V
• Low power consumption: 33 mW at ±5V
• Low cost

analog voltage get amplified and isolated from the controller


circuit hence the Opamp circuit is used to provide the
compatibility with the alarming device. In our circuit we have used
a speaker as an alarming device which is operable on 5V.
We have used the DAC to convert the digital data coming from the
micro-controller to an analog alarming device, this is done by
using an opamp 741 at the output of DAC so that the
Microcontroller & embedded system

analog voltage get amplified and isolated from the controller circuit hence the Opamp circuit is
used to provide the compatibility with the alarming device. In our circuit we have used a
speaker as an alarming device which is operable on 5V.

The DAC0800 provides high speed digital to analog conversion. When very low conversion
rates can be used, another method of digital to analog conversion may suffice. Consider a
square wave which is input to a low pass filter, whose cutoff frequency is far below the
repetition rate of the square wave. From Fourier analysis, only the average value of the square
wave should pass through the filter. By varying the duty cycle for the square wave, the average
value o f the wave can be changed. Therefore, a low pass filter and the output compare
functions can be used together to form a simple D/A converter for slowly varying signals.
Write a program that uses the low pass filter in Figure 2 as a D/A converter. Accept a voltage,
between 0V and 5.0V, and use a 10KHz wave with variable duty cycle to produce the proper
output voltage. The output compare functions should be used to generate the square wave.
Measure Rref with an ohmmeter. Connect the circuit in Figure 1. Measure the voltage dropped
across Vref and calculate IFS. Run the program for several voltages and analyze the results.

Interfacing with 8051 kit:-


➢ Connect DAC-0800 interfacing module to 8255-I of 8051 trainer kit through 26-pin
FRC cable.
➢ Be sure about the direction of the cable i.e. pin no.1 of module should be connector to
pin no.1 of 8255 connector.
➢ Connect +12V, -12V & GND from the Trainer KIT.
Microcontroller & embedded system

➢ DAC is connected to port A & Address is FF00H.


➢ Control word address is FF03H.

Programs:-
(1) Program to generate sawtooth wave.

ORG 3000H
MOV DPTR, #0FF03H
MOV A, #80H
MOVX @DPTR, A
MOV A,#00H
AGAIN: MOV DPTR, #0FF00H
MOVX @DPTR,A
INC A
SJMP AGAIN
END
(2) Program to generate staircase waveform.

ORG 3000H
MOV DPTR, #0FF03H
MOV A, #80H
MOVX @DPTR, A
MOV A, #00H
Microcontroller & embedded system

MOV R1, #05H ; DECIDE NO. OF STEPS


MOV R2, #15H ; DECIDE HEIGHT OF STEPS
MOV DPTR, #0FF00H
AGAIN: MOVX @DPTR,A
ADD A,R2
LCALL DELAY
DJNZ R1,AGAIN

ORG 3050H
DELAY: MOV R0,#35H ;DECIDE WIDTH OF STEP
MOV R3, #FFH
ABC: DJNZ R3, ABC
XYZ: DJNZ R0,XYZ
RET
END
(3) Program to generate square wave.

ORG 3000H
MOV DPTR, #0FF03H
MOV A, #80H
MOVX @DPTR, A
AGAIN: MOV A, #00H
MOV DPTR, #0FF00H
MOVX @DPTR,A
LCALL DELAY
MOV A, #0FFH
MOV DPTR, #0FF00H
MOVX @DPTR, A
LCALL DELAY
SJMP AGAIN

ORG 3050H
DELAY: MOV R0,#35H
MOV R3, #FFH
ABC: DJNZ R3, ABC
XYZ: DJNZ R0,XYZ
RET
END
(4) Program to generate triangle wave.

ORG 3000H
MOV DPTR, #0FF03H
MOV A, #80H
Microcontroller & embedded system

MOVX @DPTR, A
MOV A, #00H
MOV DPTR, #0FF00H
AGAIN: MOVX @DPTR, A
INC A
CJNE A, #0FFH, AGAIN
REPEAT: DEC A
MOVX @DPTR, A
CJNE A, #00H, REPEAT
SJMP AGAIN
END

Questions:-
(1) Enlist the name of different types of D to A Converters.Draw circuits of any one.

Conclusion:-
Microcontroller & embedded system

Aim: To Interface A-to-D converter with 8051.

Apparatus:-8051 trainer kit, ADC 0809H module.

Theory:-

ADC 0809:-

The ADC0808 and ADC0809 are monolithic CMOS devices with an 8-channel multiplexer,
an 8-bit analog-to-digital (A/D) converter, and microprocessor-compatible control logic. The
8-channel multiplexer can be controlled by a microprocessor through a 3-bit address decoder
with address load to select any one of eight single-ended analog switches connected directly
to the comparator. The 8-bit A/D converter uses the successive-approximation conversion
technique featuring a high-impedance threshold detector, a switched-capacitor array, a sample
and-hold, and a successive-approximation register (SAR). Detailed information on interfacing
tomost popular microprocessors is readily available from the factory. The comparison and
converting methods used eliminate the possibility of missing codes, non-monotonicity, and
the need for zero or full-scale adjustment. Also featured are
latched 3-state outputs from the SAR and latched inputs to the
multiplexer address decoder. The single 5-V supply and low power
requirements make the ADC0808 and ADC0809 especially useful for a
wide variety of applications. Ratiometric conversion is made
possible by access to the reference voltage input terminals. The
ADC0808 and ADC0809 are characterized for operation from −40°C to
85°C.
Microcontroller & embedded system
Microcontroller & embedded system

Interfacing:-

➢ Connect ADC-0809 interfacing module to 8255-I of 8051 trainer kit through 26-pin
FRC cable.
➢ Be sure about the direction of the cable i.e. pin no.1 of module should be connected to
pin no. 1 of 8255 connector.
➢ Connect +5V, GND from the trainer kit( +5V & GND signals are available in the 25 &
26 pin of FRC 8255-I connector).
➢ D0-TO D7 PIN of ADC0809 is connected port A of 8255.
➢ OE pin (output enable) is connected to PC2, EOC(End of conversion) pin is connected
to PC4, START(start of conversion) pin is connected to PC1 & A0,A1,A2( Input line
selection)pin is connected to PB0, PB1 & PB2 pin respectively.
Program:-
Write a program to convert a DC voltage applied at IN0 of ADC0809 & store the digital value at
memory location 3050H.

ORG 3000H
MOV DPTR, #0FF03H
Microcontroller & embedded system

MOV A, #98H
MOVX @DPTR, A
START: MOV DPTR, #0FF01H
MOV A, #00H
MOVX @DPTR, A
MOV DPTR, #0FF02H
MOV A, #00H
MOVX @DPTR, A
MOV A, #03H
MOVX @DPTR, A
MOV A, #00H
MOVX @DPTR, A
DL1: MOVX A, @DPTR
ANL A, #10H
JZ DL1
MOV A, #04H
MOVX @DPTR, A
MOV DPTR, #0FF00H
MOVX A, @DPTR
MOV DPTR, #3050H
MOVX @DPTR, A
HERE: SJMP HERE

Questions:-
(1) What is the function WR/ SOC pin in A-to D converter?
(2) What is the function of RD/OE pin in A-to-D converter?
(3) What is the function of INTR pin in A-to-D converter?
Conclusion:-
Microcontroller & embedded system

You might also like