Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help for 8051 Time delay/Timer routine

Status
Not open for further replies.

Ogu Reginald

Full Member level 6
Joined
Oct 7, 2011
Messages
369
Helped
47
Reputation
94
Reaction score
46
Trophy points
1,308
Location
Nigeria
Activity points
3,391
Can someone help me with an assembly code or c programme source code for 30seconds delay. The microcontroller I am using is at89s52.
 

Re: Source code for at89s52

It is not such difficulty, use 8051 timers

Here link for "8051 Time delay/Timer routine calculator "

8051 Time delay/Timer routine calculator / 8051 software / Downloads : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes

---------- Post added at 20:09 ---------- Previous post was at 19:58 ----------

You may need software loop as well

---------- Post added at 20:09 ---------- Previous post was at 20:09 ----------

You may need software loop as well
 

i think u can calculate ur time delay from the following details and make program for delay...



In timers... there are few things to take care of.. first.. amount of time you want delay for, second which timer mode is suitable for that delay.

Timer increment a count every single machine cycle. so if you are using a clock of say.. 12Mhz then.. no. of times timer count is incremented is:

12000000/12 = 1000000

i.e. timer will be incremented 1,000,000 times in a sec.

Lets say you want a delay of 10mS (0.01S) and you have to calculate the count which is to be loaded in Timer registers (THx and TLx) to find the count to be loaded.. simply multiply the required delay with the count per sec..

i.e. 0.01 x 1,000,000 = 10,000

so we need to count from 0 to 10,000. Maximum count for 16 bit timer is 65536.
So if we load 65536-10000 = 55536 in timer registers it till automatically count 10000 times..
So final value is 55536 (DF80H)
so THx = DFH and TLx = 80H
this will give you the required delay...

in case of registers.. you need to add all the time delay required for an instruction to execute and then multiply it by the loop count.. that will give you the time delay..
e.g. the commonly used instructions in register delay are.. djnz Rx,label (2 machine cycles)
loading value using MOV instruction also need 2 machine cycles. RET instuction and Acall instuction both need 2 machine cycles.
Lets say you want a delay of 100uS then.. you are running a clock of 12Mhz, so 1 machine cycle will be of 1uS. you can divide this according to the instructions as...
100 - 2(RET) - 2(lcall) - 2 (load) = 94uS left
94/2 (for DJNZ) = 47 (the count)

so required loop for 100uS delay is..

CODE:
delay100uS:
mov R7,#47
wait:
djnz r7,wait
ret
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top