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.

[51] Delay between two pulses

Status
Not open for further replies.

yogendra82

Newbie level 1
Newbie level 1
Joined
Sep 3, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
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.
 

Do you want us to guess what the syntax error is? Cool.
 

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top