8051 Microcontroller:
Machine Cycle
Machine Cycles
Machine Cycles
Four Steps of Instruction Cycle:
1. Fetch: Retrieve an instruction from the memory.
2. Decode: Translate the retrieved instruction into a series of
computer commands.
3. Execute: Execute the computer commands.
4. Store: Send and write the results back in memory.
Machine Cycles
❑ Instruction cycle:
▪ The amount of time the microprocessor takes to fetch, decode and
execute one Instruction.
▪ One Instruction cycle consists of several machine cycle.
❑ Machine cycle:
▪ The amount of time the microprocessor takes to perform a
memory or I/O access.
▪ One machine cycle consists of several clock cycle.
Machine Cycles
❑ CPU executing an instruction takes a certain number of clock cycle.
❑ Instruction Cycle:
▪ Time taken by the microcontroller to execute the complete instruction is
called the instruction cycle.
▪ It consist of many machine cycles as execution of instruction required
many steps.
Machine Cycles
❑ Machine Cycle:
▪ The length of machine cycle depends on the frequency of the crystal oscillator
connected to 8051.
▪ In original 8051, one machine cycle lasts 12 oscillator periods.
▪ In 8051 one instruction cycle consists of 6 states or 12 clock cycles, instruction
cycle is also referred as Machine cycle.
▪ Each States last for two oscillator clock period.
Machine Cycles
❑ Power Supply:
▪ 8051 has VCC = +5V and Vss = Reference
(Ground)
❑ XTAL1 and XTAL2:
▪ Crystal is connected in between these two pins 12
MHz of crystal clock is provided.
▪ 8051 is designed to operate between 1MHz to
16MHz and generally operates with a crystal
frequency 11.04962 MHz.
▪ In serial communication, operating frequency is
chosen to be 11.0592 MHz, in order to get standard
universal baud rates.
Baud rate is the measure of the number of changes to the signal
(per second) that propagate through a transmission medium.
Machine Cycles
Question: Find the Period of the machine cycle for 11.0592 MHz
Crystal frequency.
Solution:
Machine Cycles
Question: The following shows crystal frequency for three different 8051-
based systems. Find the period of the machine cycle in each case.
(a)11.0592 MHz (b) 16 MHz (C) 20 MHz
Solution:
(a)11.0592/12 = 921.6 KHz
Machine cycle is 1/921.6 KHz = 1.085 μs
(b) Oscillator period = 1/16 MHz = 0.625 μs
Machine cycle (MC) = 0.625 μs ×12 = 0.75 μs
(c) 20 MHz/12 = 1.66 MHz and
Machine cycle = 1/1.66 MHz = 0.60 μs
Machine Cycles
Question:
Machine Cycles
Questions: Find the size of the delay in following program, if the crystal
frequency is 11.0592 MHz
Machine Cycles
Questions : Find the size of the delay in following program, if the crystal
frequency is 11.0592 MHz.
Machine Cycles
Machine Cycles
Questions : Find the size of the delay in following program, if the crystal
frequency is 11.0592 MHz.
Solution:
The HERE loop & the two instructions outside the loop:
{[250 (1+1+1+1+2)]+3}×1.085 μs = (1500+3) × 1.085 μs=1630.755 μs.
8051 Microcontroller:
Programming Example
Addressing Mode
Identify the addressing mode in each instruction and describe the
operation performed by each instruction
1. MOV A, #15H 9. MOV A, @ R1
2. MOV DPTR, #1000H 10. MOV @R2,A
3. MOV A, R2 11. MOVX A, @DPTR
4. MOV R2, A 12. MOVX@DPTR, A
5. MOV R1, R2 13. MOVX A, @R1
6. MOV A, 35H 14. MOVX @R0,A
7. MOV A, 80H 15. MOVC A,@A+DPTR
8. MOV 30H, 35H 16. MOVC A, @A+PC
Pro1
Addressing Mode
Org 0000h
Mov a, #5h Pro4 Pro5
end Org 0000h Org 0000h
Back: Mov r0, #30h Back:Mov dptr, #40h
Pro2 MOV A, @ro MOV A, @A+dptr
Org 0000h Inc ro Inc dptr
Mov r0, #5h SJMP back Mov a, #0h
Pro3 SJMP back
Mov A, ro End
Org 0000h Org 0040h
end Hint : D:30h
Mov A, 30h Mydata: db 1,2,3,4,5,6,7
End End
Hint : D:30h
Register Bank with Address
Stack Operation (PUSH)
Stack Operation (POP)
Solution:
Example
❑ Show the code to push R5 and A onto the stack and then pop them
back into R2 and B, where B = A and R2 = R5.
Solution:
Note: Only direct addressing mode is allowed for pushing or popping the stack.
Such as PUSH A is invalid.
Pushing the accumulator onto the stack must be coded as PUSH 0E0H
Example
Solution
Write a program to
toggle all the bits of
port1 by sending to it
the value 55H and
AAH continuously.
Put a time delay in
between each issuing
of data to port 1.
Example
❑ Write a program to clear 16H RAM locations starting at RAM
address 60H.
❑ Write a program to copy a block of 10 bytes of data from 35H to
60H.