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.

I ms delay creating in 8051

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,580
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,381
making one milli second delay in 8051 using timer mode is the following programme is correct ?
crystal frequency is 20MHz

Code:
#include <REGX51.H>void _ms_delay(unsigned int delay)
{
		while(delay != 0)  // mult delay 
		{	--delay;
            TMOD = 0x01;                            // Timer1 mode0


            TH0= 0xF9;                               //initial value for 1ms


            TL0 = 0x7D;


            TR0 = 1;                                       // timer start


            while (TF0 == 0);                     // check overflow condition


            TR0 = 0;                                      // Stop Timer


            TF0 = 0;                                      // Clear flag


}  }




void main()


{


_ms_delay(2); // calling two milli second




}
 

Too long time for me to recall this uC, but I did calculate all hardware clock cycle needed in that loop, then mulitiply with clock period to get delay time.
You should know how much clock cycles that your loop would take firstly.
 

Hi,

Using timer...

One thing is obvious: you have a 20MHz clock andneed to delay for 1ms.

20MHz x 1ms = 20000 clock ticks.

I can't find any information in yourcode how you want to achieve this.
(But I only had a quick view...I'm not familiar with 8051s and their periferals).

Maybe some comments or additional information could help.

Klaus
 
Last edited:

hello

Q=20Mhz MC=0,60µS
if 8051 timer is similar to PIC timer
you need to spend 1666 * 0,6 => 1 mS
load the timer with 65535-1666=63869 ..
TH0= 0xF9; //initial value for 1ms
TL0 = 0x7D;
0xF97D => 63869
so seems to be OK if timer has no prescaler or potsscaler
and use MC as clock.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top