Discussion in "8051 Discussion Forum" started by    Khadka_Bishal    Mar 16, 2018.
Fri Mar 16 2018, 11:34 AM
#1
I want to have a delay of 15 microsecond in 8051 using a crystal oscillator of 11.0592 MHz. .

To test the delay, i toggle port pin 1.0 for every execution of delay.
The code and its calculations are shown in code's comment section below

====================================================================
ORG 00h
MOV TMOD,#01 ;TIMER0 -> MODE1
;No. of machine cycle = 480uS/1.0850693us = 14
; 2^16 - 14 = 65522
; ( 65522 ) dec = ( FFF2 )hex
; The required value to generate 15us is (FFF2)16
; BUT, there is extra delay of 17 us due to execution of
;other codes except the delay loop
; To Compensate this,
; i add (17)dec =(11)hex to FFF2 = 1 0003 which exceed
; the max value FFFF.
; but i loaded the maximum value i.e. FFFF to timer reg
; and still i got a delay of 17 uS

LOOP:
CPL P1.0
ACALL DELAY15
SJMP LOOP


DELAY15:
MOV TH0,#0FFH
MOV TL0,#0FFH
SETB TR0
HERE: JNB TF0,HERE
CLR TR0
CLR TF0
RET
END
===================================================================

Even assigning the timer register its maximum value i am not getting delay of 15 uS (microsecond) . I have checked for the code optimization as well but i didn't see ta single step that could be either eliminated or optimized.

Please help on it !
Sat Mar 17 2018, 09:26 PM
#2
CPL P1.0 3
ACALL DELAY15 6
SJMP LOOP 3

DELAY15:
MOV TH0,#0FFH 2
MOV TL0,#0FFH 2
SETB TR0 3
HERE: JNB TF0,HERE 4
CLR TR0 3
CLR TF0 3
RET 4

total 33 = 17.9 uS

Instructions need different numbers of machine cycles.
I have noted the number needed for each instruction in your loop.
I get a total of 33.
You must be using a version of the 8051 that has
6 clock cycles per machine cycle.
Older types use 12 clock cycles per machine cycle.
33 machine cycles take around 17 uS as you found.

One obvious way to speed up the loop is to
not use a subroutine.
Put the delay "inline".
This saves the ACALL and RET.
You don't need Timer0 at all, you could just
just use a software loop.

LOOP:
CPL P1.0 3
// DELAY15:
MOV TH0,#0FFH 2
MOV TL0,#0FFH 2
SETB TR0 3
HERE: JNB TF0,HERE 4
CLR TR0 3
CLR TF0 3
SJMP LOOP 3

total 23 = 12.4 uS

Get Social

Information

Powered by e107 Forum System

Conversation

Mon Nov 12 2018, 05:58 AM
Pavan_user
i have seen your replica of I2C programming using AT89C51 but i am unable to understand the "ack_bit" variable usage ...looks like it is always 1...can you elaborate how acknowledgment is working....
bgk3678
Tue Nov 06 2018, 02:36 PM
kindly any one give solution for my problem
ExperimenterUK
Mon Nov 05 2018, 09:48 PM
Pins high is the normal state. You need a program to set them low
mayengbam
Sun Nov 04 2018, 05:41 PM
hello, i am niranjoy, alll the port of my 8051 is always high, even i erase all the program. why is it so happen and what is the problem. any one please help me!
Sun Nov 04 2018, 02:16 PM
BASAVARAJ g kudamble
hi I am interfacing GSM 300 to 8051 microcontroller to receive message from mobile
ExperimenterUK
Sat Sep 29 2018, 06:28 PM
Please post questions in the forum.
Sat Sep 29 2018, 11:26 AM
Ashfaq Ch
hi i have some AT89C51RC microcontrollers already programed. some one help us to how to download from AT89C51RC and after study and edit all corractions reload to AT89C51RC controller
shshistiem
Wed Sep 12 2018, 10:58 PM
hii!! some1 please let me know how i ll get rfid code to 8051 by WEIGAND mode
DrNossberg
Tue Sep 11 2018, 08:09 PM
is there anyone here?
Mon Aug 27 2018, 07:30 AM
bun
Hello everyone´╝ü

Downloads

Comments

atalnet
Fri Nov 16 2018, 07:44 AM
genius784
Wed Nov 14 2018, 09:25 AM
katherineamt
Mon Nov 12 2018, 03:14 PM
wimac
Sun Nov 11 2018, 03:36 PM
suryanspn
Sat Nov 10 2018, 02:52 AM
RubenMarques
Tue Nov 06 2018, 06:35 PM
mayengbam
Sun Nov 04 2018, 05:36 PM
bgk3678
Sun Nov 04 2018, 02:27 PM

Online

Guests: 47, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38021
Newest member: atalnet
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 19 2018, 01:11 AM
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Nov 15 2018, 06:48 PM
Unfortunately I have no experience of LabView,but ...
katherineamt Avatar
Posted By katherineamt
Mon Nov 12 2018, 03:22 PM
I have never used LabView and I have to implement ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 12 2018, 01:21 AM
wimac Avatar
Posted By wimac
Sun Nov 11 2018, 04:03 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 11 2018, 07:25 AM
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 06 2018, 06:10 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 04 2018, 02:52 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 04 2018, 02:48 PM
Xuenan Avatar
Posted By Xuenan
Sat Nov 03 2018, 01:08 PM
Make the 8051 frequency exactly 11.0592 MHz in pro...