All About Circuits Forum  

Go Back   All About Circuits Forum > Software, Microcomputing, and Communications Forums > Programmer's Corner

Notices

Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 08-16-2008, 10:54 PM
MLCC MLCC is offline
New Member
 
Join Date: Aug 2008
Posts: 8
Question How to program a delay in assembly?

Hello,
I am programming 8051 microcotroller in assembly and I'm trying to stop the program for 10 seconds and then continue with the rest of the program. Any ideas on how to do this?

-MLCC
Reply With Quote
  #2  
Old 08-17-2008, 01:23 PM
beenthere's Avatar
beenthere beenthere is offline
Senior Member
 
Join Date: Apr 2004
Location: Missouri, USA (GMT -6)
Posts: 15,815
Blog Entries: 10
Default

One classic way to make a delay is to use nested decrement loops. Every time the inner loop counts down to 0, then the next decrements, and so on.

It's a bit tedious to adjust the timing, and interrupts will mess with the process, but it works.
__________________
First comes the hardware, then the software.
Reply With Quote
  #3  
Old 08-17-2008, 02:50 PM
Ratch Ratch is offline
Banned
 
Join Date: Mar 2007
Posts: 1,068
Default

MLCC,

Quote:
I am programming 8051 microcotroller in assembly and I'm trying to stop the program for 10 seconds and then continue with the rest of the program. Any ideas on how to do this?
The 8051 has two internal timer/counters. Each timer/counter has two special function registers (SFRs) dedicated to it. That should make a delay a snap to code once you are familiar with the instructions and hardware.

Ratch
Reply With Quote
  #4  
Old 08-17-2008, 05:42 PM
MLCC MLCC is offline
New Member
 
Join Date: Aug 2008
Posts: 8
Post

The Loop is what seems to do the trick, although, is their a more efficient way to do this? (I need a example with it too, I'm very new to programming microcontrollers)
Reply With Quote
  #5  
Old 08-18-2008, 05:39 AM
dbogusone's Avatar
dbogusone dbogusone is offline
New Member
 
Join Date: Jul 2008
Posts: 1
Default

Quote:
Originally Posted by MLCC View Post
The Loop is what seems to do the trick, although, is their a more efficient way to do this? (I need a example with it too, I'm very new to programming microcontrollers)
There are only two ways to do it and both will make use of a loop.
1. A loop making use of counters, as mentioned by beenthere.
- To get the exact timing, you have to know your instruction speed with respect to the clock that you are using.
2. A loop that waits for a pre-set timer interrupt. Normally most microcontrollers have this feature.
Reply With Quote
  #6  
Old 08-19-2008, 07:07 AM
Arm_n_Legs Arm_n_Legs is offline
Senior Member
 
Join Date: Mar 2007
Posts: 170
Default

MAIN:
MOV TMOD,#10H ; Init timer 1
.......
.......
SETB TR1 ; Start timer 1
LCALL DELAY ;

DELAY:
MOV R1,#200D ; 200 x 50 ms = 10 sec
D1:
MOV TH1,#3CH
MOV TL1,#B0H
D2:
JNB TF1,D2 ; timer overflow in 50 ms
CLR TF1
DJNZ R1,D1 ; loop 200 times
RET
Reply With Quote
  #7  
Old 08-27-2008, 06:40 AM
amolhshah amolhshah is offline
Junior Member
 
Join Date: Aug 2008
Location: Nasik/Mumbai, India
Posts: 12
Thumbs up

here is a link explaining different types of delay subrouines:
http://www.dnatechindia.com/index.ph...ontroller.html

here is a link for few working codes that u may find useful
http://www.dnatechindia.com/index.php/Code-Library/
__________________
Amol Shah
For 8051 Tutorials
www.dnatechindia.com
Reply With Quote
  #8  
Old 09-02-2008, 06:39 AM
Developer_Dan() Developer_Dan() is offline
Junior Member
 
Join Date: Oct 2007
Location: Melbourne, Australia
Posts: 17
Send a message via MSN to Developer_Dan()
Default

Assembly and C/C++ are just the most awesome, greatest languages EVER in programming history...
I'm not sure if 8051 chip has these type of instructions, but what about a couple of

NOP ; No Operation instruction

I supose this might not be enough delay/wait for you anyhow?
__________________
Developer_Dan()

Programmer and Software Developer
Reply With Quote
  #9  
Old 09-02-2008, 06:02 PM
Mark44 Mark44 is offline
Senior Member
 
Join Date: Nov 2007
Location: Snohomish County, USA
Posts: 626
Blog Entries: 2
Default

It would take more than a couple of NOP instructions to wait 10 seconds, and the number needed would depend on the clock speed of the 8051 microcontroller, and how long it takes to process a NOP.
__________________
"The floggings will continue until morale improves!"
Reply With Quote
Reply   Post New Thread

Tags
, ,


Similar Threads
Thread Thread Starter Forum Replies Last Post
55 Sec Time Delay in Assembly Language pauliewalnuts Embedded Systems and Microcontrollers 8 06-17-2008 06:20 AM
Assembly Program (digit conversion) frogacult Programmer's Corner 4 05-11-2008 05:15 PM
Assembly Program frogacult Programmer's Corner 5 05-08-2008 03:41 PM
Assembly Program For Transmitting And Receiving A Message Using Ms-dos Debug Diana Programmer's Corner 5 06-22-2007 04:09 AM
Assembly Language program Thinker Programmer's Corner 18 05-23-2007 03:01 PM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:16 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.