#include <reg52.h>
void delay(unsigned int t)
{
while(t--);
}
void DelayUs2x(unsigned char t)
{
while(--t);
}
void DelayMs(unsigned char t)
{
while(t--)
{
DelayUs2x(245);
DelayUs2x(245);
}
}
void main(void)//方向灯
{
P0 = 0xff;
P1 = 0xff;
while(1)
{
if(~P1)
{
DelayMs(10);//delay 10 ms
if(~P1)//第二次判断
{
while(~P1)
{
P0 = P1;
delay(50000);
P0 = 0xff;
delay(50000);
}
P0 = P1;
}
}
}
}
void delay(unsigned int t)
{
while(t--);
}
void DelayUs2x(unsigned char t)
{
while(--t);
}
void DelayMs(unsigned char t)
{
while(t--)
{
DelayUs2x(245);
DelayUs2x(245);
}
}
void main(void)//方向灯
{
P0 = 0xff;
P1 = 0xff;
while(1)
{
if(~P1)
{
DelayMs(10);//delay 10 ms
if(~P1)//第二次判断
{
while(~P1)
{
P0 = P1;
delay(50000);
P0 = 0xff;
delay(50000);
}
P0 = P1;
}
}
}
}
本文介绍了一个基于51单片机的方向灯控制程序实现,通过使用P0和P1端口来控制方向灯的状态,并包含了定时延时函数以实现灯光的闪烁效果。该程序利用了简单的循环结构来检测P1端口状态变化,并在此基础上实现了方向灯的开关功能。

7548

被折叠的 条评论
为什么被折叠?



