以下是使用 Keil-51 软件编写的程序,实现 P1 口的 1 个 LED 小灯每隔 1S 交替闪亮:

#include <reg52.h>

void delay(unsigned int count) // 延时函数
{
    unsigned int i;
    for (i = 0; i < count; i++);
}

void main()
{
    while (1)
    {
        P1 = 0x01; // P1.0 灯亮
        delay(50000); // 延时 1S
        P1 = 0x00; // P1.0 灯灭
        delay(50000); // 延时 1S
    }
}

程序的流程是先点亮 P1.0 口的 LED 灯,然后通过延时函数等待 1 秒(延时函数中的计数值需要根据实际情况进行调整),再将 P1.0 口的 LED 灯熄灭,再次延时 1 秒。如此往复,实现 LED 灯每隔 1 秒交替闪亮。

Keil-51 编程实现 LED 灯每秒交替闪烁

原文地址: https://www.cveoy.top/t/topic/opSg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录