Is there an solution to stop looping this

72 views Asked by At

Settings of the MCU:

Settings of the MCU

This is the circuit in Proteus:

This is the circuit

I wrote this code for the led to blink for one time only but it's blinking for infinite times.

Could anyone tell how to stop automatically looping this program in Proteus 8 professional simulator?

I've correctly checked and uploaded it to the PIC16F877A MCU.

#include<pic.h>

#define _XTAL_FREQ 20000000
__CONFIG(0x3D72);

void delay();

void main()
{
    TRISD=0X00;
    PORTD=0X00;
    RD4=1;
    delay();
    RD4=0;
    delay();
}

void delay()
{
    for(int i=0;i<50;i++)
        __delay_ms(10);
}
1

There are 1 answers

0
the busybee On

You have no code that stops main() from returning. And many MCU implementations just restart the application if main() returns. Your system apparently does this, too, therefore your LED blinks.

The solution is to insert an endless loop at the end of main():

void main()
{
    TRISD=0X00;
    PORTD=0X00;
    RD4=1;
    delay();
    RD4=0;
    delay();

    for (;;) {
        /* do nothing */
    }
}