[51]跑马灯

本文介绍了一个基于51单片机的简单程序,该程序实现了LED流水灯的效果,并通过循环左移和右移操作切换灯光状态。代码中包含了延迟函数以控制灯的变化速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<reg52.h>
#include <intrins.h>
#define uint unsigned int 
#define uchar unsigned char 
void delay(uint z)
{
    uint x,y;
    for(x=z;x>0;x--)
        for(y=110;y>0;y--);    
}
void main()
{
    uchar temp=0xfe;
    while(1)
    {
    P1=temp;
    temp=_crol_(temp,1);
        if(temp==0xfe)
        {    
        temp=0x7f;
            while(1)
            {
             temp=_cror_(temp,1);
             delay(200);
             P1=temp;
             if(temp==0xfe){temp=0xfe;break;}
            }
        continue;
        }
    delay(200);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值