Keil-51软件进行程序的编写与调试。用程序延时的方法让P1口的1个LED小灯每隔1S交替闪亮。
以下是使用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秒交替闪亮。
原文地址: https://www.cveoy.top/t/topic/fKPU 著作权归作者所有。请勿转载和采集!