microprocessor: delay technique

15
Delay Technique MCS-51 Microcontroller

Upload: arkhom-jodtang

Post on 21-Jul-2015

19 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Microprocessor: Delay technique

Delay Technique

MCS-51 Microcontroller

Page 2: Microprocessor: Delay technique

Why Delay?

• CPU run with 11.059MHz clock frequency

• 1 Machine cycle (about 1 Second)

• Human eyes able to see only 14 frame / Second

Page 3: Microprocessor: Delay technique

How to Delay ?

• Create loop (Each loop take time to complete)

• Create Nested loop to make more delay

• Use DJNZ as a tools for loop

• Write the code as Sub routine for easy to use them.

Page 4: Microprocessor: Delay technique

Create loop

MOV R7, #XXH

Loop_inner:

NOP

NOP

DJNZ R7, Loop_inner

R7 = #XXH

Process

Loop_inner:

DJNZ R7, Loop_Inner

Page 5: Microprocessor: Delay technique

Create Nested loop

MOV R6, #XXH

Loop_Outter:

MOV R7, #XXH

Loop_inner:

NOP

NOP

DJNZ R7, Loop_inner

DJNZ R6, Loop_Outter

R7 = #XXH

Process

Loop_inner:

DJNZ R7, Loop_Inner

R6 = #XXH

Loop_Outter:

DJNZ R6, Loop_Outter

Process

Page 6: Microprocessor: Delay technique

Create Nested of Nested loop

MOV R5, #XXH

SuperLoop:

MOV R6, #XXH

Loop_Outter:MOV R7, #XXH

Loop_inner:

NOP

NOP

DJNZ R7, Loop_inner

DJNZ R6, Loop_Outter

DJNZ R5, SuperLoop

R6 = #XXH

Loop_Outer:

DJNZ R6

R5 = #XXH

SuperLoop:

DJNZ R5

Process

goto SuperLoop

goto Loop_Outer

Delay

Page 7: Microprocessor: Delay technique

Sample Delay Code

DELAY_100ms: MOV R7, #64H

DELAY_1ms_1:MOV R6, #0E6H

DELAY_1ms_2:NOPNOPDJNZ R6, DELAY_1ms_2DJNZ R7, DELAY_1ms_1

Page 8: Microprocessor: Delay technique

Write as Subroutine

Delay100ms:

MOV R6, #0FFH

Loop_Outter:MOV R7, #0FFH

Loop_inner:

NOP

NOP

DJNZ R7, Loop_inner

DJNZ R6, Loop_Outter

RET

Page 9: Microprocessor: Delay technique

Question ?

• How to make more delay?

– Add the NOP Instruction

– Increase initial value

– Create more nested loop

Page 10: Microprocessor: Delay technique

DC Motor

• Small size

Page 11: Microprocessor: Delay technique

Transistor

Page 12: Microprocessor: Delay technique

Relay

Page 13: Microprocessor: Delay technique

Stepping Motor

• Program to

– Fill value #F0 to #FFH to memory address 20h to 2Fh

– Fill value #00 to #0FH to memory address 30h to 3Fh

– Make Left shift for every number that is just filled.

Refer to the display of the Emulator 8051 Software

– Complete the Additional operation (Don’t care carry flag) of Top and bottom, store the result on the 40h to 4Fh. Such as

• 20h + 30h store in 40h

• 21h + 31h store in 41h and so on.

Page 14: Microprocessor: Delay technique

Speaker

Page 15: Microprocessor: Delay technique

Sample Question (Design)

• Write