8051 MICROCONTROLLER
PROGRAMMING IN KEIL
1. ASSEMBLY LANGUAGE PROGRAMMING
ADDITION OF TWO NUMBERS
org 00h
mov a,# 05h
mov b, a
mov a, #00h
mov a, #03h
accumulator
add a,b
end
// entering accumulator value
// moving value to register b
// clearing the accumulator
// entering second value to
// adding the two values
Steps for simulating the program in Keil.
Start Keil programming software, open new project
Create the project
Select your microcontroller to work with
For example Atmel -AT89C52
8051-based Fully Static 24MHz CMOS controller with
32 I/O Lines,3 Timers/Counters, 8 Interrupts/2
Priority Levels, UART,
Three-Level Program Memory Lock, 8K Bytes Flash
Memory,
128 Bytes On-chip.
Create an empty document
Type the program
Save the file with .asm as extension
Open target target 1 by right clicking on target
folder on project window (if window is disabled enable it using,
view project window).
Click output tab- Enable hex file option and then click
ok
Add the files to source group- right click on source
group folder in project window and add existing files.
Select the saved add.asm file from the folder.
Rebuild the target files- Rebuilding will gives you the
errors and warnings in the program. You can proceed
with debug when having no error message.
Debug the program
Use step over function to execute program step by
step, you can see the register value changes with
each step. From this step you can make sure the
correctness of the program.
Return to curser line is the function used to execute
the program all in once
ASSEMBLY LANGUAGE PROGRAM TO FIND THE SUBSTRACTION
OF TWO NUMBERS
org 00h
mov a,# 03h
// entering accumulator value
mov b, a
// moving value to register b
mov a, #00h
// clearing the accumulator
mov a, #05h
// entering second value to accumulator
subb a,b
// substracting the two values
end
LED BLINKING USING ASEMBLY LANGUAGE PROGRAM
ORG 00H
CLR P3.0
CLR P2.0
MOV A, #0FFH
MOV P0, #01H
MOV A, P0
JZ LAST
NOW :
SETB P2.0
ACALL DELAY
CLR P2.0
ACALL DELAY
SETB P3.0
ACALL DELAY
CLR P3.0
SETB P2.0
CLR P2.0
MOV R2,#02H
DJNZ R2, NOW
DELAY : MOV R0,#05H
GO :MOV R1,#04H
HERE : DJNZ R1,HERE
DJNZ R0,GO
LAST:
RET
END