DEPARTMENT OF
MECHANICAL ENGINEERING
FACULTY OF ENGINEERING
BTME 4533
Digital Electronics and Microprocessors
Content
1
Experiment 1:
Introduction to the FX8031 IDE Software and Programming Fundamentals
Objectives:
To demonstrate program development procedures using the FX8031 Integrated
Development Environment (IDE) interface.
To learn and understand programming fundamentals of 8051 microcontroller.
2
Experiment 1A: FX8031 Development Kit Start Up
This experiment is to let you know how to start writing your own program or assembly
code. Among the processes involved are writing, assembling, compiling and debugging an
Intel 8051 assembly code. Now, lets start our experiment by following the step-by-
step guidance given as follows.
6. Click FILE > SAVE AS and save your file name as exp1a.asm.
7. Under the Project tab, add your exp1a.asm file by right clicking and ADD FILE.
8. Also add the include file, at89c51.inc using the same way as exp1a.asm.
at89c51.inc can be located at C:\program files\FX8031\include\.
9. You can now compile your program by selecting BUILD from PROJECT menu.
10. If there is no error, a successful message will show on the output window and
3
the HEX file will be generated.
11. Correct your program if error message appear.
12. Every single time your codes are changed, you must SAVE it again before
compiling and running it.
13. To run the software simulate, click START from the VIRTUAL MACHINE
(CTRL + D)
14. Simulate your program by pressing F7 button for single stepping. (Single step
means that you run the program line by line).
Question:
4. What are the status of CY, AC and P at the end of the program execution?
__________________________________________________________________
__________________________________________________________________
Answer:
Instruction Result
MOV A, #17H Content of A =
ADD A, R2 Content of A =
5
Experiment 2:
Data Transfer and Addressing Mode
Objective: To learn different modes of data transfer by using various addressing modes
A computer typically spends more time moving data from one location to another
than it spends on any other operation.
Data is stored at a source address and moved to a destination address.
The ways by which these addresses are specified are called the addressing modes.
8051 memory is divided into the following four distinct physical parts:
Internal RAM
Internal special-function registers
External RAM
Internal and External ROM
The following four addressing modes are commonly used to access data:
Immediate addressing mode
Register addressing mode
Direct addressing mode
Indirect addressing mode
6
Experiment 2A: Programming Exercise - Put the number 8DH in RAM locations
03H to 07H.
7
Address Code (Hex) Instruction Byte Cycle
0000H 75 03 8D MOV 03H,#8DH 3 2
Total
Table 1: Method 1
Total
Table 2: Method 2
Total
Table 3: Method 3
Total
Table 4: Method 4
8
Experiment 3: Logical Operation
Objective: To learn the use of logical operation that concerns Boolean algebras.
Compile the following program and record the result after every instruction has been
executed in the table below.
MOV A, #0FFH
MOV R0, #77H
ANL A, R0
MOV 15H, A
CPL A
ORL 15H, #80H
XRL A, 15H
Instruction Result
MOV A, #0FFH Content of A =
ANL A, R0 Content of A =
CPL A Content of A =
Table 3.1
9
Experiment 3.2 Rotate and Swap Operations
.
Compile the following programs:
Program 3.2
MOV A, #0A5H
CLR C
RRC A
RL A
SWAP A
RLC A
SWAP A
10
Instruction Result of destination operand CY Content of A in binary P
MOV A, #0A5H
CLR C
RRC A
RL A
SWAP A
RLC A
SWAP A
Table 3.2
11
Experiment 4: Arithmetic Operation
Objective: To learn methods of manipulating data using the arithmetic operation and the
flags which are affected by the operation.
MOV A, #7BH
MOV 0F0H, #02H
MUL AB
MOV R0, B
MOV B, #0FEH
MUL AB
MOV R0, B
Table 4.1
12
Experiment 4.2 Division
MOV A, #0FFH
MOV 0F0H, #2CH
DIV AB
MOV R0, B
Table 4.2
Results: Quotient = H, Remainder = H
Values in decimal =
CLR C
MOV A, #64H
SUBB A, #0FH
Table 4.3
Experiment 4.4 Addition
Type and compile the following program. Fill in the table 4.4
MOV A, #5FH
ADD A, #0BDH
Table 4.4
13
Experiment 5: Program Interrupt and Timer Instructions
Use when an important external event occurrence need the attention of the CPU
while the CPU is attending another task
Once interrupt conditions is detected, CPU will push the current PC value to the
Stack Memory and load the PC with the Interrupt vectors.
However, the above will happen if and only if the Global Interrupt Enable bit
(EA) and the Interrupt masking bits are enabled. i.e EX0 (INT0) and EX1
(INT1).
INT0 & INT1 Interrupt Vectors locations
cseg
org RESET_VECTOR
sjmp START
ends
cseg
org EX0_VECTOR
14
EX0_ISR:
jb LED1,EX0_ISR1
setb LED1
reti
EX0_ISR1:
clr LED1
reti
ends
cseg
org EX1_VECTOR
EX1_ISR:
jb LED2,EX1_ISR1
setb LED2
reti
EX1_ISR1:
clr LED2
reti
ends
cseg
START:
mov SP,#80h
clr P1 ; Light up all LEDs
setb IT0 ; Set EX0 as falling edge trigger
15
16
APPENDIX B: Intel 8051 Instruction Set Summary
17
APPENDIX B: Intel 8051 Instruction Set Summary
18
APPENDIX B: Intel 8051 Instruction Set Summary
19
APPENDIX C: ASCII Printable Characters
20
APPENDIX D: Summary of the 8051 on-chip data memory
21
APPENDIX E: Jump Instruction Ranges
22
APPENDIX F: PSW register
The Program Status Word (PSW) contains status bits that reflect the current MPU state.
23