[51] Delay between two pulses

Status
Not open for further replies.

yogendra82

Newbie level 1
Joined
Sep 3, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
9
Hi want to generate two Pulses with 1 Hz frequency but one pulse is 14 msec is high and rest 986 msec is low. Second pulse will begin just before 14 mesc of first pulse, 5 msec is high and rest 995 mesc is low.

I written a source code in Kiel compiler for AT59C52:

Code:
#include<reg52.h>  // special function register declarations  
                   // for the intended 8051 derivative       

#include<stdio.h>  // prototype declarations for I/O functions

#define PORTP1^0 
#define PORTP1^1

void Delay();     // Function prototype declaration

void main (void) 
{
    while(1)                //infinite loop 
    {
       P1^0 = 0xFF;
	   P1^1 = 0x00;
       Delay(14);
	   P1^0 = 0x00;
	   Delay (981);
	   P1^1 = 0xFF;
       Delay(5);
    }
}

void Delay()
{
    int j;
    int i;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10000;j++)
        {
        }
    }
}
that code is not working. compiler shows syntax error.

please modify to this code for fullfill to above mention purpose.
 

Definitely wrong:
Code:
#define PORTP1^0 
#define PORTP1^1

What is your intension on writing something like that:
Code:
P1^1 = 0xFF;
 

Firstly, what compiler toolsuite are you using?

Besides the meaningless #define's mentioned by xenos, one issue is your delay() routine and its associated prototype are incorrectly defined.

You are passing presumably a msec value to the Delay() routine, however the routine and the prototype are defined to accept no parameters:

Code:
#include<reg52.h>  // special function register declarations  
                   // for the intended 8051 derivative       

#include<stdio.h>  // prototype declarations for I/O functions

#define PORTP1^0 
#define PORTP1^1

[COLOR="#FF0000"]void Delay();[/COLOR]     // Function prototype declaration

void main (void) 
{
    while(1)                //infinite loop 
    {
       P1^0 = 0xFF;
	   P1^1 = 0x00;
       Delay([COLOR="#FF0000"]14[/COLOR]);
	   P1^0 = 0x00;
	   Delay ([COLOR="#FF0000"]981[/COLOR]);
	   P1^1 = 0xFF;
       Delay([COLOR="#FF0000"]5[/COLOR]);
    }
}

[COLOR="#FF0000"]void Delay()[/COLOR]
{
    int j;
    int i;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10000;j++)
        {
        }
    }
}

Also, if you are utilizing an AT89C52, include the AT89X52.H header, if available.

Utilizing a timer interrupt and ISR is certainly a preferable method over utilizing software delays to generate two different pulse trains.

The use of software delays where accurate time is concerned is plagued with possible problems.

BigDog
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…