Basic Tutorial For Keil Software: Written by
Basic Tutorial For Keil Software: Written by
Written by
www.MicroDigitalEd.com
Introduction
This tutorial will assist you in writing your first 8051 Assembly language program using the popular Keil
Compiler. Keil offers an evaluation package that will allow the assembly and debugging of files 2K or less. This
package is freely available at their web site. Keil’s website address is www.keil.com.
The sample program included in the tutorial toggles Ports 1 and 2 on the 8051. The compiled program
has been tested using the 8051 board from MicroDigitalEd.com. The program also works with other systems that
have Port 1 and 2 available.
Copyright 2002
MicroDigitalEd.com
Page 2 of 16
9/21/2003
Basic Keil Tutorial
Page 3 of 16
9/21/2003
Starting a new Assembler Project
Page 4 of 16
9/21/2003
4. The device window will be displayed.
5. Select the part you will be using to test
with. For now we will use the Dallas
Semiconductor part DS89C420.
6. Double Click on the Dallas Semiconductor.
Page 5 of 16
9/21/2003
Creating Source File
Page 6 of 16
9/21/2003
3. Copy the example to the Right into the new window. This file will ORG 0H
toggle Ports 1 and 2 with a delay. MOV A, #55H
AGAIN:
MOV P1, A
MOV P2, A
ACALL DELAY
CPL A
SJMP AGAIN
DELAY:
MOV R3, #200
OUTER: MOV R2, #0255
INNER: DJNZ R2, INNER
DJNZ R3, OUTER
RET
END
Page 7 of 16
9/21/2003
5. Name the file Toggle.a51
6. Click the Save Button
Page 8 of 16
9/21/2003
Adding File to the Project
Page 9 of 16
9/21/2003
3. Click on Groups/Add Files tab
4. Under Available Groups select Source Group 1
5. Click Add Files to Group… button
Page 10 of 16
9/21/2003
11. Expand the Source Group 1 in the
Tree menu to ensure that the file
was added to the project
Page 11 of 16
9/21/2003
Creating HEX for the Part
Page 12 of 16
9/21/2003
5. Select Output Tab
6. Click on Create Hex File check box
7. Click OK Button
Page 13 of 16
9/21/2003
Testing Program in Debugger
Page 14 of 16
9/21/2003
Running the Keil Debugger
2. Click on Peripherals.
Select I/O Ports, Select
Port 1
Page 15 of 16
9/21/2003
3. A new window should port will pop up. This represent the Port and
Pins
5. To exit out, Click on Debug Menu and Select Start/Stop Debug Session
Page 16 of 16
9/21/2003