有办法停止循环吗

问题描述 投票:0回答:1

Settings of the MCUThis is the circuitProteus

我编写了这段代码,让 LED 仅闪烁一次,但它会闪烁无限次。

谁能告诉我如何在 Proteus 8 专业模拟器中停止自动循环这个程序

我已经正确检查并上传到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);
}
c embedded mplab proteus
1个回答
0
投票

您没有任何代码可以阻止

main()
返回。如果
main()
返回,许多 MCU 实现只是重新启动应用程序,因此 LED 会闪烁。

解决办法是在

main()
末尾插入死循环:

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

    for (;;) {
        /* do nothing */
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.