8051 Lec2-Fd
8051 Lec2-Fd
LECTURE 2
1
Microcontroller Burning procedures
Software
Burner Assembly
4 Assembler
code
Filename.asm
5
Filename.HEX 3 1 2
Filename.C
Firmware
C or MikroC
Compiler
To code Filename.h
HW
Simulator “as Proteus”
USB
6 Training-KIT
AT89c51 To Embedded system
2
Is assembly and assembler the same?
3
• Emulator: another way to run the program is
using emulator.
• It is a mixture of hardware and software.
• •It is used to teat and debug external systems.
4
5
• Debugger: if your program does not require
external hardware or requires only hardware
accessible directly from your microcomputer
then you can use a debugger to run and debug
your program.
•It allows you to load your object code program
and troubleshoot it.
6
• LINKER: it is a program used to join several object
files into one object file.
•The linker produces link file which contains the
binary codes for all combined modules.
•The linker also produces a link map file which
contains the address information about the linked
files.
•The produced link files have the extension .EXE
and .MAP
7
difference between assembly and instruction set?
8
Directive and instructions
• Assembler instruction generates machine
code, thus contributes towards the size of the
program .
• Assembler directive does not create any
machine code, thus does not contribute to
program size. It directs the assembler to
perform certain actions during assembly
phase
9
10
DW: Define Word.
• The DW directive serves the same purposes as
the DB directive, but it now makes the
assembler reserve the number of memory
words (16-bit) instead of bytes.
• EXample: WORDS DW 1234H
11
ORG
Directive used by assembler to define
the start address of the current machine
Internal Rate of the
code at the program memory Internal clock
clock divider
by12 pulses
Such as
0000h Machine code (INC A)
ORG 0
INC A
DEC A
Program M 12
END
• Directive used by assembler to stop compiling.
• Any instruction after “End” consider as comment.
Internal Rate of the
clock divider Internal clock
by12 pulses
END
Program M 13
14
instruction set architecture ISA
15
16
17
The internal clock pulse
Uses by CPU to synchronize all processes in
the microcontrollers
/12
𝑭 =𝒇 𝒄𝒓𝒚𝒔𝒕𝒂𝒍
𝒇 𝒄𝒓𝒚𝒔𝒕𝒂𝒍 18
The machine cycle (MC)
19
The rate of machine cycles
(The internal clock pulses)
Internal Rate of the
Crystal Oscillator Internal clock
clock divider
(Up to 24 MHz) pulses
by12
Crystal frequency
R ate of 𝑀𝑎𝑐h𝑖𝑛𝑒𝑐𝑦𝑐𝑙𝑒= [ 𝑀𝐻𝑧 ]
12
20
EXAMPLE
Calculate the rate of the internal clock pulse
of AT89C55, if the external crystal has
frequency 3 MHz
The answer
21
The Execution time
Is time taken by CPU to carry out one instruction
22
EXAMPLE
Calculate the total run-time (total delay time) for
AT89C51 during execution of 3 instructions that
need 1, 2 and 4 machine cycles respectively,
the connected crystal has frequency equal 6
MHz.
The answer
23
Note that:
• Port 1,2,3 have internal pull-up resistors
• Port 0 has not internal pull-up resistors
24
The internal memories of 8051
25
The internal RAM
26
The special function
27
registers
The Program-Status-Word Register (PSW)
28
Selection of operational bank
29
The Carry and Auxiliary carry flags
D7 D6 D5 D4 D3 D2 D1 D0
Accumulator
30
The parity flag (P)
𝐛𝐢𝐭 𝟕
𝐏 = ∑ 𝐨𝐧𝐞𝐬 𝐢𝐧 𝐀𝐜𝐜𝐮𝐦𝐮𝐥𝐚𝐭𝐨𝐫
𝐛 𝐢𝐭 𝟎
31
EXAMPLE
Find the status of the flags CY, AC and P
after the addition of the two digital values
ABh and 38h in AT89C51.
The answer
CY = 0 because there isn't carry-up from 8th bit of the final result.
AC = 1 because there is carry-up from 4th 5th bit of the final result.
P = 1 because the Accumulator has odd number of ones (5 ones).
32
The Over Flow flags (OV = 1) in three
cases
1) When the divisor has value zero during the division
operation.
2) When the multiplication product is greater than the value
"FFh". (the result outside the stored data in accumulator)
3) When an error occurs during the addition and subtraction
operations for the singed numbers (the result outside the
signed 8-bit range "-128" to "127").
33
EXAMPLE
Find the status of the flags CY and OV after
the addition of the two digital values F4h and
80h in the AT89C51.
The answer
-ve
-ve
+ve
34
The Internal Program memory
35