Vivekananda Samantra CP15 05 01-Embedded Systems
Vivekananda Samantra CP15 05 01-Embedded Systems
Vivekananda Samantra CP15 05 01-Embedded Systems
Microprocessor Microcontroller
• CPU is stand-alone, RAM, • CPU, RAM, ROM, I/O and
ROM, I/O, timer are separate timer are all on a single chip
• designer can decide on the • fix amount of on-chip ROM,
amount of ROM, RAM and RAM, I/O ports
I/O ports. • for applications in which cost,
• expansive power and space are critical
• versatility • single-purpose
• general-purpose
CPU
Bus Serial
4 I/O Ports
OSC Control Port
P0 P1 P2 P3 TxD RxD
Address/Data
• Vcc ( pin 40 ):
– Vcc provides supply voltage to the chip.
– The voltage source is +5V.
• GND ( pin 20 ): ground
• XTAL1 and XTAL2 ( pins 19,18 ):
– These 2 pins provide external clock.
– Way 1 : using a quartz crystal oscillator
– Way 2 : using a TTL oscillator
– Example 4-1 shows the relationship between XTAL and the
machine cycle.
Solution:
Solution:
C2
XTAL2
30pF
C1
XTAL1
30pF
GND
R0
DPTR DPH DPL
R1
R2 PC PC
R3
R5
R6
R7
4k 8k 32k
0000H 0000H 0000H
0FFFH
DS5000-32
1FFFH
8751
AT89C51
8752
AT89C52 7FFFH
7FH
30H
2FH
Bit-Addressable RAM
20H
1FH Register Bank 3
18H
17H
Register Bank 2
10H
0FH Register Bank 1 )Stack(
08H
07H
Register Bank 0
00H
0 0 0 00H-07H
0 1 1 08H-0FH
1 0 2 10H-17H
1 1 3 18H-1FH
Note: X can be 0 or 1
Myfile.asm
ASSEMBLER
PROGRAM
Myfile.lst
Other obj file
Myfile.obj
LINKER
PROGRAM
Myfile.abs
OH
PROGRAM
Myfile.hex
Example :
Num EQU 30
…
MOV R0,Num
MOV DPTR,#data1
…
ORG 100H
data1: db “IRAN”
MOV DPTR, A
MOV Rn, Rn
In other word, the content of register R0 or R1 is sources or target in MOV, ADD and SUBB
insructions.
Example:
Write a program to copy a block of 10 bytes from RAM location starting at 37h to RAM
location starting at 59h.
Solution:
MOV R0,37h ; source pointer
MOV R1,59h ; dest pointer
MOV R2,10 ; counter
L1: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2,L1
MOVC A,@A+DPTR
A= content of address A +DPTR from ROM
Note:
Because the data elements are stored in the program
(code ) space ROM of the 8051, it uses the instruction
MOVC instead of MOV. The “C” means code.
Vivekananda Samantra CP15 05 01- Embedded Systems
8051 instruction set
• MOV – copy the data from data memory
• MOV addr(8),@Rp
• MOV @Rp, #data
• MOV @Rp, A
• MOV @Rp,addr(8)
• ADDC A,#data(8)
A + data(8)+ CY A
• ADDC A,Rn
A + Rn+CY A
• ADDC A,add(8)
A + addr(8)+CY A
• SUBB A, add(8)
A – add(8) - CY A
• SUBB A, Rn
A- Rn- CY A
• Instructions
• ORL addr(8), A
• ORL addr(8), #data
• ORL A, #data
• ORL A, addr(8)
• ORL A,@R0
• ORL C, bit
EXAMPLE:
RR A
RR:
RRC: C
RL:
RLC: C
Vivekananda Samantra CP15 05 01- Embedded Systems
ROTATE LEFT
• Operation: RL
• Function: Rotate Accumulator Left
• Syntax: RL A
• Description: Shifts the bits of the Accumulator to the left.
The left-most bit -bit 7 of the Accumulator is loaded into
bit0.
• Operation: RLC
• Function: Rotate Accumulator Left Through Carry
• Syntax: RLC A
• Description: Shifts the bits of the Accumulator to the left.
The left-most bit (bit 7) of the Accumulator is loaded into
the Carry Flag, and the original Carry Flag is loaded into
bit 0 of the Accumulator. This function can be used to
quickly multiply a byte by 2.
Vivekananda Samantra CP15 05 01- Embedded Systems
ROTATE RIGHT
• Operation: RR
• Function: Rotate Accumulator Right
• Syntax: RR A
• Description: Shifts the bits of the Accumulator to the
right. The right-most bit -bit 0 of the Accumulator is
loaded into bit7.
• Operation: RRC
• Function: Rotate Accumulator Right Through Carry
• Syntax: RRC A
• Description: Shifts the bits of the Accumulator to the
right. The right-most bit (bit 0) of the Accumulator is
loaded into the Carry Flag, and the original Carry Flag is
loaded into bit 7. This function can be used to quickly
divide a byte by 2.
Vivekananda Samantra CP15 05 01- Embedded Systems
LOOP and JUMP Instructions
Conditional Jumps :
JZ Jump if A=0
JB Jump if bit=1
AJMP(absolute jump)
In this 2-byte instruction, It allows a jump to any memory
location within the 2k block of program memory.
SJMP(short jump)
In this 2-byte instruction. The relative address range of 00-
FFH is divided into forward and backward jumps, that is ,
within -128 to +127 bytes of memory relative to the address of
the current PC.