Basic Micro Controller Programs
Basic Micro Controller Programs
• Separate memory is allocated for program and data storage. (MD 9000
refers to data memory address and MP 9000 refers to program memory
address.)
PROGRAM 9.A
AIM: Write an Assembly Language Program to add, subtract, multiply and divide the
bytes available in internal RAM locations 30H & 31H. Verify the results in register R3 for
addition and register R4 for subtraction.
EQUIPMENT REQUIRED:
8051 Microcontroller trainer kit
Power supply and Keyboard
PROGRAM:
ADDRESS HEXCODE MNEMONIC
8000 MOV A, 30
MOV R1, A
MOV R2, 31
ADD A, R2
MOV R3, A
MOV A, R1
SUBB A, R2
MOV R4, A
LJMP 3
THEORETICAL RESULT:
79 H + 5C H = 0D5 H
79 H – 5C H = 1D H
PRACTICAL RESULT:
To enter inputs in internal RAM use the command
MI 30
30 00 79
31 00 5C
R register name
R R3
R3 D5
R R4
R4 1D
PROGRAM 9.B
8-BIT MULTIPLICATION
AIM: Write an Assembly Language Program to multiply two data bytes (13H and 49H).
Store the result from 6000 onwards.
EQUIPMENT REQUIRED:
8051 Microcontroller trainer kit
Power supply
Keyboard
PROGRAM:
13 H X 49 H = 056B H
PRACTICAL RESULT:
MD RAM address
MD 6000
PROGRAM 9.C
8-BIT DIVISON
AIM: Write an Assembly Language Program to divide data stores at external RAM
locations 2000H and 2001H and verify the result from registers.
EQUIPMENT REQUIRED:
8051 Microcontroller trainer kit
Power supply
Keyboard
PROGRAM:
THEORETICAL RESULT:
PRACTICAL RESULT:
Load data inputs (0ABH and 12H) at external RAM addresses 2000H and
2001H.
MD RAM address
MD 2000
2000 0AD
2001 12
Verify the outputs from registers A and B, use the command R. A holds
quotient and B with reminder.
PROGRAM 10
AIM: Write an assembly language program to set timer 0 to provide 5 Seconds time
delay while displaying decimal numbers 0 to 10 on LCD Screen.
EQUIPMENT REQUIRED:
If timer 0 is used in mode 1 it will work as a 16-bit timer and count 65536
internal clock pulses by incrementing TH0 & TL0 register values from 0000H to FFFFH
to get 5 Seconds time delay the timer has to run for 70 times.
TH0 8C 00 TL08A 00
TCON 88 10H TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
0 0 0 1 0 0 0 0
03B1H is the address of a subroutine that clears LCD monitor
139EH is the starting address of subroutine that displays a number on the LCD.
The number should be loaded in RAM location 71H
9600H is the starting address of delay subroutine
PROGRAM:
PRACTICAL RESULT:
• Perform the following operation using bit addressable instructions: start Timer1
PROGRAM 11
AIM: Write an assembly language program to transfer data bytes from register to
memory in a continuous manner. Program timer1 interrupt to stop the controller from
data transfer after 100 uSec time delay. Find how many data bytes transferred from
register to memory with in 100 uSec.
EQUIPMENT REQUIRED:
To count 92 clocks TH1 & TL1 should be loaded with TH1 :TL1 = FFFF – 52H= FFADH
TH1 8D FF TL18B AD
TCON 88 40H TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
0 1 0 0 0 0 0 0
At 001B address, binary code for LJMP FFF6 is already loaded by manufacturer.
PROGRAM:
FFF6 LJMP 3
FFF9 RET I
THEORETICAL RESULT:
To get 100 sec time delay count n should be n= 100 sec / 1.085 sec =92
INC A 1 MC
INC DPTR - 2 MC
SJMP BACK – 2 MC
Microcontroller consume 92 T- STATES (Clock cycles) during 100 sec time delay
in the form of incrementing from 0 to B to repeat the loop for 12 times
[12 (2+1+2+2)+3]+ 4 = 87 + 4 =91.
PRACTICAL RESULT:
To verify the outputs from external RAM use the command MD RAM Address
MD 9000
9000 00
9001 01
9002 02
9003 03
9004 04
9005 05
9006 06
9007 07
9008 08
9009 09
900A 0A
900B 0B
• R A
A-0B
• R DPTR
DPTR- 900B
VIVA QUESTIONS FOR PROGRAM 11
•
PROGRAM 12
PROGRAM 12.A
PRACTICAL RESULT:
MD RAM address
MD 8000
8500 37
8501 35
PROGRAM 12.B
SWAPPING
AIM: Write an Assembly Language Program to swap the nibbles of R0 & Accumulator so
that the Lower nibble of R0 swaps with Upper nibble of Accumulator and vice - versa.
Store the results from 6000H onwards.
EQUIPMENT REQUIRED:
IBM PC with X-8051 software
8051 Microcontroller trainer kit
Power supply
PROGRAM:
MOV A, #26
SWAP A
XCHD A,@ R0
MI 49
49 00 49
THEORETICAL RESULT:
The given inputs 49H & 26H are swapped to 42H & 96H
PRACTICAL RESULT:
Inputs are entered immediately in the main program.
5600 42
5601 96
PROGRAM 12.C
PRACTICAL RESULT: