Professional Documents
Culture Documents
8085 Microprocessor Programs: Microprocessor & Microcontroller Lab Manual
8085 Microprocessor Programs: Microprocessor & Microcontroller Lab Manual
8085 MICROPROCESSOR
PROGRAMS
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
1
PROGRAM:
MVI
LDA
MOV
LDA
ADD
JNC
INR
LOOP: STA
MOV
STA
HLT
C, 00
Initialize C register to 00
4150
Load the value to Accumulator.
B, A
Move the content of Accumulator to B register.
4151
Load the value to Accumulator.
B
Add the value of register B to A
LOOP Jump on no carry.
C
Increment value of register C
4152
Store the value of Accumulator (SUM).
A, C
Move content of register C to Acc.
4153
Store the value of Accumulator (CARRY)
Halt the program.
OBSERVATION:
Input:
Output:
80 (4150)
80 (4251)
00 (4152)
01 (4153)
RESULT:
Thus the program to add two 8-bit numbers was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
2
ALGORITHM:
1.
2.
3.
4.
5.
6.
7.
8.
9.
PROGRAM:
MVI
LDA
MOV
LDA
SUB
JNC
CMA
INR
INR
LOOP: STA
MOV
STA
HLT
C, 00
4150
B, A
4151
B
LOOP
A
C
4152
A, C
4153
Initialize C to 00
Load the value to Acc.
Move the content of Acc to B register.
Load the value to Acc.
Jump on no carry.
Complement Accumulator contents.
Increment value in Accumulator.
Increment value in register C
Store the value of A-reg to memory address.
Move contents of register C to Accumulator.
Store the value of Accumulator memory address.
Terminate the program.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
3
RESULT:
Thus the program to subtract two 8-bit numbers was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
4
Start the program by loading HL register pair with address of memory location.
Move the data to a register (B register).
Get the second data and load into Accumulator.
Add the two register contents.
Check for carry.
Increment the value of carry.
Check whether repeated addition is over and store the value of product and carry
in memory location.
8) Terminate the program.
PROGRAM:
LOOP:
NEXT:
MVI
MVI
LXI
MOV
INX
MOV
ADD
JNC
INR
DCR
JNZ
STA
MOV
STA
HLT
D, 00
A, 00
H, 4150
B, M
H
C, M
B
NEXT
D
C
LOOP
4152
A, D
4153
Initialize register D to 00
Initialize Accumulator content to 00
Get the first number in B - reg
Get the second number in C- reg.
Add content of A - reg to register B.
Jump on no carry to NEXT.
Increment content of register D
Decrement content of register C.
Jump on no zero to address
Store the result in Memory
Store the MSB of result in Memory
Terminate the program.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
5
OBSERVATION:
Input:
Output:
FF (4150)
FF (4151)
01 (4152)
FE (4153)
RESULT:
Thus the program to multiply two 8-bit numbers was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
6
ALGORITHM:
1)
2)
3)
4)
5)
6)
7)
Start the program by loading HL register pair with address of memory location.
Move the data to a register(B register).
Get the second data and load into Accumulator.
Compare the two numbers to check for carry.
Subtract the two numbers.
Increment the value of carry .
Check whether repeated subtraction is over and store the value of product and
carry in memory location.
8) Terminate the program.
PROGRAM:
NEXT:
LOOP:
LXI
MOV
MVI
INX
MOV
CMP
JC
SUB
INR
JMP
STA
MOV
STA
HLT
H, 4150
B, M
C, 00
H
A, M
B
LOOP
B
C
NEXT
4152
A, C
4153
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
7
OBSERVATION:
Input:
FF (4150)
FF (4251)
Output:
RESULT:
Thus the program to divide two 8-bit numbers was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
8
PROGRAM:
LOOP:
AHEAD:
LXI
MOV
INX
MOV
DCR
INX
CMP
JNC
MOV
DCR
JNZ
STA
HLT
H,4200
B,M
H
A,M
B
H
M
AHEAD
A,M
B
LOOP
4300
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
9
OBSERVATION:
Input:
Output:
FE (4300)
RESULT:
Thus the program to find the largest number in an array of data was executed
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
10
ALGORITHM:
1) Load the address of the first element of the array in HL pair
2) Move the count to B reg.
3) Increment the pointer
4) Get the first data in A reg.
5) Decrement the count.
6) Increment the pointer
7) Compare the content of memory addressed by HL pair with that of A - reg.
8) If carry = 1, go to step 10 or if Carry = 0 go to step 9
9) Move the content of memory addressed by HL to A reg.
10) Decrement the count
11) Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next step.
12) Store the smallest data in memory.
13) Terminate the program.
PROGRAM:
LOOP:
AHEAD:
LXI
MOV
INX
MOV
DCR
INX
CMP
JC
MOV
DCR
JNZ
STA
HLT
H,4200
B,M
H
A,M
B
H
M
AHEAD
A,M
B
LOOP
4300
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
11
OBSERVATION:
Input:
Output:
0A (4300)
RESULT:
Thus the program to find the smallest number in an array of data was executed
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
12
PROGRAM:
REPEAT:
LOOP:
SKIP:
LXI
MOV
DCR
MOV
LXI
MOV
INX
CMP
JC
MOV
MOV
DCX
MOV
INX
DCR
JNZ
DCR
JNZ
HLT
H,4200
C,M
C
D,C
H,4201
A,M
H
M
SKIP
B,M
M,A
H
M,B
H
D
LOOP
C
REPEAT
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
13
OBSERVATION:
Input:
4200
4201
4202
4203
4204
4205
05 (Array Size)
05
04
03
02
01
Output:
4200
4201
4202
4203
4204
4205
05(Array Size)
01
02
03
04
05
RESULT:
Thus the given array of data was arranged in ascending order.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
14
PROGRAM:
REPEAT:
LOOP:
SKIP:
LXI
MOV
DCR
MOV
LXI
MOV
INX
CMP
JNC
MOV
MOV
DCX
MOV
INX
DCR
JNZ
DCR
JNZ
HLT
H,4200
C,M
C
D,C
H,4201
A,M
H
M
SKIP
B,M
M,A
H
M,B
H
D
LOOP
C
REPEAT
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
15
OBSERVATION:
Input:
4200
4201
4202
4203
4204
4205
05 (Array Size)
01
02
03
04
05
Output:
4200
4201
4202
4203
4204
4205
05(Array Size)
05
04
03
02
01
RESULT:
Thus the given array of data was arranged in descending order.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
16
PROGRAM:
LXI
MOV
ADD
MOV
ADD
ADD
ADD
INX
ADD
INX
MOV
HLT
H,4150
A,M
A
B,A
A
A
B
H
M
H
M,A
OBSERVATION:
Input:
4150 : 02 (MSD)
4151 : 09 (LSD)
Output:
4152 : 1D H
RESULT:
Thus the program to convert BCD data to HEX data was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
17
PROGRAM:
LOOP2:
LOOP1:
LXI
MVI
XRA
MOV
ADI
DAA
JNC
INR
DCR
JNZ
STA
MOV
STA
HLT
H,4150
D,00
A
C,M
01
LOOP1
D
C
LOOP2
4151
A,D
4152
OBSERVATION:
Input:
4150 : FF
Output:
4151 : 55 (LSB)
4152 : 02 (MSB)
RESULT:
Thus the program to convert HEX data to BCD data was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
18
PROGRAM:
SUB1:
SKIP:
LDA
MOV
ANI
CALL
STA
MOV
ANI
RLC
RLC
RLC
RLC
CALL
STA
HLT
4200
B,A
0F
SUB1
4201
A,B
F0
CPI
JC
ADI
ADI
RET
0A
SKIP
07
30
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
19
OBSERVATION:
Input:
4200
E4(Hexa data)
Output:
4201
4202
RESULT:
Thus the given Hexa decimal number was converted into its equivalent ASCII Code.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
20
PROGRAM:
LDA
SUI
CPI
JC
SUI
STA
HLT
SKIP:
4500
30
0A
SKIP
07
4501
OBSERVATION:
Input:
4500
31
Output:
4501
0B
RESULT:
Thus the given ASCII character was converted into its equivalent Hexa Value.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
21
PROGRAM:
AFTER:
LXI
LDA
CPI
JC
MVI
STA
HLT
MOV
MVI
DAD
MOV
STA
HLT
H,4125
4150
0A
AFTER
A,FF
4151
C,A
B,00
B
A,M
4151
LOOKUP TABLE:
4125
4126
4127
4128
4129
4130
4131
4132
4133
01
04
09
16
25
36
49
64
81
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
22
OBSERVATION:
Input:
4150: 05
Output:
4151
Input :
4150: 11
Output:
25 (Square)
RESULT:
Thus the program to find the square of the number from 0 to 9 using a Look up table
was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
23
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
24
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
25
S2
S1
EP
PEN
L2
L1
B2
B1
BAUD RATE FACTOR
0
1
0
0
0
1
SYNC MODE (1X)
(16X)
5 BITS
CHARACTR LENGTH
0
1
0
0
0
1
6
7
BITS
BITS
1
1
(64X)
1
1
8 BITS
PARITY ENABLE
1= ENABLE 0 = DISABLE
EVEN PARITY GEN/CHECK
0 =ODD 1 = EVEN
INVALID
1
1
2 BIT
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
26
S2
S1
EP
PEN
L2
L1
B2
B1
CHARACTER LENGTH
0
1
0
1
0
0
1
1
5 BITS
6 BITS 7 BITS 8 BITS
PARITY ENABLE
1= ENABLE 0 = DISABLE
EVEN PARITY GEN/CHECK
0 =ODD 1 = EVEN
EXTERNAL SYNC DETECTS
1 = SYSDET IS AN INPUT
0 = SYSDET IS AN IOUTPUT
SINGLE CHARACTER SYNC
1 = SINGLE SYNC CHARACTER
0 = DOUBLE SYNC CHARACTER
EH
IR
RTS
ER
SBRK
RXE
DTR
TXEN
TRANSMIT ENABLE
1=Enable 0 = Disable
DATA TERMINAL READY
HIGH will force DTR
Output to Zero
RECEIVE ENABLE
1=Enable 0 = Disable
SEND BREAK CHARACTER
1 = Forces TXD LOW
0 = Normal Operation
ERROR RESET
1=Reset Error Flags
PE,OE,FE
REQUEST TO SEND
HIGH will force RTS
Output to Zero
INTERNAL RESET
HIGH Returns 8251 to
Mode Instruction Format
ENTER HUNT MODE
1= Enable a Search for
Sync Characters( Has
No Effect in Async mode)
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
28
PROGRAM:
MVI
OUT
MVI
OUT
MVI
OUT
LXI
MVI
OUT
MVI
OUT
MVI
OUT
RST
A,36H
CEH
A,0AH
C8H
A,00
C8H
H,4200
A,4E
C2
A,37
C2
A,41
C0
1
ORG
IN
STA
RST
4200
C0
4500
1
4500
41
OBSERVATION:
Output:
RESULT:
Thus the 8251 was initiated and the transmission and reception of character was
done successfully.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
29
LOOP:
MVI
OUT
MVI
OUT
MVI
OUT
XRA
XRA
XRA
MVI
OUT
IN
ANI
CPI
JNZ
IN
STA
HLT
A,10
C8
A,18
C8
A,10
D0
A
A
A
A,00
D0
D8
01
01
LOOP
C0
4150
OBSERVATION:
Compare the data displayed at the LEDs with that stored at location 4150
RESULT:
Thus the ADC was initiated and the digital data was stored at desired location
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
30
THEORY:
DAC 0800 is an 8 bit DAC and the output voltage variation is between 5V and +
5V.The output voltage varies in steps of 10/256 = 0.04 (appx.). The digital data input and
the corresponding output voltages are presented in the Table1.
Input
Data in
HEX
00
01
02
7F
FD
FE
FF
Output
Voltage
- 5.00
- 4.96
- 4.92
0.00
4.92
4.96
5.00
Referring to Table1, with 00 H as input to DAC, the analog output is 5V. Similarly,
with FF H as input, the output is +5V. Outputting digital data 00 and FF at regular intervals,
to DAC, results in different wave forms namely square, triangular, etc,. The port address of
DAC is 08 H.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
31
ALGORITHM:
(a) Square Wave Generation
1.
2.
3.
4.
5.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
32
PROGRAM:
START:
MVI
OUT
CALL
MVI
OUT
CALL
JMP
A,00
Port address of DAC
DELAY
A,FF
Port address of DAC
DELAY
START
DELAY:
L1:
L2:
MVI
MVI
DCR
JNZ
DCR
JNZ
RET
B,05
C,FF
C
L2
B
L1
START:
L1:
MVI
OUT
INR
JNZ
JMP
A,00
Port address of DAC
A
L1
START
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
33
L2:
MVI
MOV
OUT
INR
JNZ
MVI
MOV
OUT
DCR
JNZ
JMP
L,00
A,L
Port address of DAC
L
L1
L,FF
A,L
Port address of DAC
L
L2
START
RESULT:
Thus the square, triangular and saw tooth wave form were generated by interfacing
DAC with 8085 trainer kit.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
34
the operation
APPARATUS REQUIRED:
1)
2)
3)
4)
5)
MODE 0-Interrupt On Terminal Count:The output will be initially low after mode set operation. After loading the counter, the
output will remain low while counting and on terminal count, the output will become high
until reloaded again.
Let us see the channel in mode0. Connect the CLK 0 to the debounce circuit and
execute the following program.
PROGRAM:
MVI A, 30H
OUT CEH
MVI A, 05H
OUT C8H
MVI A, 00H
OUT C8H
HLT
;Channel 0 in mode 0.
;LSB of count.
;MSB of count.
It is observed in CRO that the output of channel 0 is initially low. After giving x clock
pulses, we may notice that the output goes high.
MODE 1-Programmable One Shot:After loading the count, the output will remain low following the rising edge of the
gate input. The output will go high on the terminal count. It is retriggerable; hence the
output will remain low for the full count after any rising edge of the gate input.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
35
The following program initializes channel 0 of 8253 in Mode 1 and also initializes triggering
of gate. OUT 0 goes low as clock pulses and after triggering It goes back to high level after
five clock pulses. Execute the program and give clock pulses through the debounce logic and
verify using CRO.
PROGRAM:
MVI A, 32H
OUT CEH
MVI A, 05H
OUT C8H
MVI A, 00H
OUT C8H
OUT DOH
HLT
;Channel 0 in mode 1.
;
;LSB of count.
;MSB of count.
;Trigger Gate 0.
;Channel 0 in mode 3.
;
;LSB of count.
;MSB of count.
We utilize mode 3 to generate a square wave of frequency 150 kHz at Channel 0.Set the
jumper so that the clock of 8253 is given a square wave of Frequency 1.5 MHz. This
program divides the program clock by 10 and thus the Output at channel 0 is 150 KHz.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
36
RESULT:
Thus the 8253 PIT was interfaced to 8085 and the operations for mode 0, Mode 1
and mode 3 was verified.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
37
PROGRAM:
START:
LOOP:
DELAY:
LOOP2:
LOOP1:
LXI
MVI
MVI
OUT
MVI
OUT
MVI
OUT
MOV
OUT
CALL
INX
DCR
JNZ
JMP
H,4130H
D,0FH ;Initialize counter.
A,10H
C2H ;Set Mode and Display.
A,CCH ;Clear display.
C2H
A,90H ;Write Display
C2H
A,M
C0H
DELAY
H
D
LOOP
START
MVI
MVI
DCR
JNZ
DCR
JNZ
RET
B, A0H
C, FFH
C
LOOP1
B
LOOP2
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
38
- FF
FF
FF
FF
FF
FF
FF
FF
98
68
-7C
-C8
-1C
-29
-FF
-FF
RESULT:
Thus 8279 controller was interfaced with 8085 and program for rolling display was
executed successfully.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
39
8051 MICROCONTROLLER
PROGRAMS
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
40
AIM:
To perform addition of two 8 bit numbers using 8051 instruction set.
ALGORITHM:
1.
2.
3.
4.
PROGRAM:
ORG
CLR
MOV
ADD
MOV
MOVX
SJMP
HERE:
4100
C
A,#data1
A,#data2
DPTR,#4500
@DPTR,A
HERE
OBSERVATION:
Input:
66
23
Output:
89 (4500)
RESULT:
Thus the program to perform addition of two 8 bit numbers using 8051 instruction set
was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
41
AIM:
To perform Subtraction of two 8 bit numbers using 8051 instruction set.
ALGORITHM:
1.
2.
3.
4.
PROGRAM:
ORG
CLR
MOV
SUBB
MOV
MOVX
SJMP
HERE:
4100
C
A,#data1
A,#data2
DPTR,#4500
@DPTR,A
HERE
OBSERVATION:
Input:
66
23
Output:
43 (4500)
RESULT:
Thus the program to perform subtraction of two 8 bit numbers using 8051 instruction
set was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
42
AIM:
To perform multiplication of two 8 bit numbers using 8051 instruction set.
ALGORITHM:
1.
2.
3.
4.
5.
6.
PROGRAM:
HERE:
ORG
CLR
MOV
MOV
MUL
MOV
MOVX
INC
MOV
MOVX
SJMP
4100
C
A,#data1
B,#data2
AB
DPTR,#4500
@DPTR,A
DPTR
A,B
@DPTR,A
HERE
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
43
OBSERVATION:
Input:
80
80
Output:
00 (4500)
19 (4501)
RESULT:
Thus the program to perform multiplication of two 8 bit numbers using 8051
instruction set was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
44
AIM:
To perform division of two 8 bit numbers using 8051 instruction set.
ALGORITHM:
1.
2.
3.
4.
5.
6.
PROGRAM:
HERE:
ORG
CLR
MOV
MOV
DIV
MOV
MOVX
INC
MOV
MOVX
SJMP
4100
C
A,#data1
B,#data2
AB
DPTR,#4500
@DPTR,A
DPTR
A,B
@DPTR,A
HERE
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
45
OBSERVATION:
Input:
05
03
Output:
01 (4500)
02 (4501)
RESULT:
Thus the program to perform multiplication of two 8 bit numbers using 8051
instruction set was executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
46
RAM ADDRESSING
AIM:
To exhibit the RAM direct addressing and bit addressing schemes of 8051
microcontroller.
ALGORITHM:
1.
2.
3.
4.
5.
For Bit addressing, Select Bank 1 of RAM by setting 3rd bit of PSW
Using Register 0 of Bank 1 and accumulator perform addition
For direct addressing provide the address directly (30 in this case)
Use the address and Accumulator to perform addition
Verify the results
PROGRAM:
Bit Addressing:
HERE:
SETB
MOV
MOV
ADD
MOV
MOVX
SJMP
PSW.3
R0,#data1
A,#data2
A,R0
DPTR,#4500
@DPTR,A
HERE
MOV
MOV
ADD
MOV
MOVX
SJMP
30,#data1
A,#data2
A,30
DPTR,#4500
@DPTR,A
HERE
Direct Addressing:
HERE:
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
47
OBSERVATION:
Bit addressing:
Input:
54
25
Output:
79 (4500)
Direct addressing:
Input:
54
25
Output:
79 (4500)
RESULT:
Thus the program to exhibit the different RAM addressing schemes of 8051 was
executed.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
48
THEORY:
A motor in which the rotor is able to assume only discrete stationary angular position is a
stepper motor. The rotor motion occurs in a stepwise manner from one equilibrium
position to next.
The motor under our consideration uses 2 phase scheme of operation. In this scheme,
any two adjacent stator windings are energized. The switching condition for the above said
scheme is shown in Table.
A1
1
0
0
1
Clockwise
B1
A2
0
0
1
0
1
0
0
1
B2
1
0
1
0
A1
1
0
0
1
Anti - Clockwise
B1
A2
0
1
1
0
1
0
0
0
B2
0
1
0
1
In order to vary the speed of the motor, the values stored in the registers R1, R2, R3 can
be changed appropriately.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
49
ALGORITHM:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
PROGRAM:
START:
AGAIN:
DLY1:
DLY:
ORG
MOV
MOV
MOVX
PUSH
PUSH
MOV
MOV
MOV
MOV
DJNZ
DJNZ
DJNZ
MOVX
POP
POP
INC
DJNZ
SJMP
4100
DPTR,#4500H
R0,#04
A,@DPTR
DPH
PDL
DPTR,#FFC0H
R2, 04H
R1,#FFH
R3, #FFH
R3,DLY
R1,DLY1
R2,DLY1
@DPTR,A
DPL
DPH
DPTR
R0,AGAIN
START
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
50
DATA:
4500: 09, 05, 06, 0A
RESULT:
Thus the speed and direction of motor were controlled using 8051 trainer kit.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
51
THEORY:
DAC 0800 is an 8 bit DAC and the output voltage variation is between 5V and +
5V.The output voltage varies in steps of 10/256 = 0.04 (appx.). The digital data input and
the corresponding output voltages are presented in the Table below
.
Input Data in HEX
00
01
02
7F
FD
FE
FF
Output Voltage
- 5.00
- 4.96
- 4.92
0.00
4.92
4.96
5.00
Referring to Table1, with 00 H as input to DAC, the analog output is 5V. Similarly,
with FF H as input, the output is +5V. Outputting digital data 00 and FF at regular intervals,
to DAC, results in different wave forms namely square, triangular, etc,.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
52
ALGORITHM:
(a)
1.
2.
3.
4.
5.
6.
(b)
1.
2.
3.
4.
5.
(c)
1.
2.
3.
4.
5.
6.
7.
8.
9.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
53
START:
DELAY:
LOOP:
HERE:
ORG
MOV
MOV
MOVX
LCALL
MOV
MOVX
LCALL
LJUMP
4100
DPTR,PORT ADDRESS OF DAC
A,#00
@DPTR,A
DELAY
A,#FF
@DPTR,A
DELAY
START
MOV
MOV
DJNZ
DJNZ
RET
SJMP
R1,#05
R2,#FF
R2,HERE
R1,LOOP
START
LOOP:
ORG
MOV
MOV
MOVX
INC
SJMP
4100
DPTR,PORT ADDRESS OF DAC
A,#00
@DPTR,A
A
LOOP
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
54
START:
LOOP1:
LOOP2:
ORG
MOV
MOV
MOVX
INC
JNZ
MOV
MOVX
DEC
JNZ
LJMP
4100
DPTR,PORT ADDRESS OF DAC
A,#00
@DPTR,A
A
LOOP1
A,#FF
@DPTR,A
A
LOOP2
START
RESULT:
Thus the square, triangular and saw tooth wave form were generated by interfacing
DAC with 8051 trainer kit.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
55
AIM:
To perform arithmetic operations in 8051 using keil software.
PROCEDURE:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
PROGRAM:
ORG
CLR
MOV
MOV
DIV
4100
C
A,#05H
B,#02H
AB
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
56
RESULT:
Thus the arithmetic operation for 8051 was done using Keil Software.
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
57
AIM:
To Design a microcontroller based system for simple applications like security
systems combination lock etc.
PROCEDURE:
1. Read number of bytes in the password
2. Initialize the password
3. Initialize the Keyboard Display IC (8279) to get key and Display
4. Blank the display
5. Read the key from user
6. Compare with the initialized password
7. If it is not equal, Display E to indicate Error.
8. Repeat the steps 6 and 7 to read next key
9. If entered password equal to initialized password, Display O to indicate open.
PROGRAM:
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
51H,#
52H,#
53H,#
54H,#
R1,#51
R0,#50
R3,#04
R2,#08
DPTR,#FFC2
A,#00
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
58
LOOP:
AGAIN:
WAIT:
XX:
NEQ:
YY:
MOVX
MOV
MOVX
MOV
MOVX
MOV
MOV
MOVX
DJNZ
MOV
MOVX
ANL
JZ
MOV
MOVX
MOV
MOVX
MOV
MOV
CJNE
INC
DJNZ
MOV
MOV
MOVX
SJMP
@DPTR,A
A,#CC
@DPTR,A
A,#90
@DPTR,A
A,#FF
DPTR,#FFCO
@DPTR,A
R2,LOOP
DPTR,#FFC2
A,@DPTR
A,#07
WAIT
A,#40
@DPTR,A
DPTR,#FFCO
A,@DPTR
@R0,A
A,@R1
A,50H,NEQ
R1
R3,AGAIN
DPTR,#FFCO
A,#OC
@DPTR,A
XX
MOV
MOV
MOVX
SJMP
DPTR,#FFCO
A,#68
@DPTR,A
YY
RESULT:
Thus the program for security lock system was executed
C.SARAVANAKUMAR. M.E.,
LECTURER, DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
59