一乐电子

 找回密码
 请使用微信账号登录和注册会员

QQ登录

只需一步,快速开始

微信扫码登录

手机号码,快捷登录

手机号码,快捷登录

搜索
查看: 1658|回复: 1

[其他综合] 刚刚做的呼吸灯

[复制链接]
发表于 2013-4-20 02:06 | 显示全部楼层 |阅读模式
调了好久,效果还不错
#include<reg51.h>
#define uint unsigned int
sbit led=P0^0;
void delay(uint a)
{
        while(a--);
}                               
void delay1(uint q)
{
        uint w,e;
        for(w=q;w>0;w--)
                for(e=110;e>0;e--);
}
void main()                  
{
        uint x,y;
        while(1)
        {                       
                for(x=0;x<550;x++)
                {       
                        led=1;
                        delay(550-x);
                        led=0;
                        delay(x);
                }
                for(y=0;y<350;y++)
                {
                        led=0;
                        delay(350-y);
                        led=1;
                        delay(y);
                }
                led=1;
                delay1(700);
                                       
        }
}http://v.youku.com/v_show/id_XNTQ1MzU0ODIw.html

发表于 2014-7-4 19:41 | 显示全部楼层
LZ,那个DELAY 和DELAY1是多长呢? 这个是参照写的,但效果不太理想。

int main(void)
{
    INT8U  i;
    INT8U  j;
     
    PortInit();   
    while(1)
    {
        
      for (i=0 ; i< 500 ; i++)
      {
        SetPB(4);
            Delay_us (500-i);
        ClrPB(4);
            Delay_us (i);
      }
      
      for (j=0; j<350 ; j++)
      {
        ClrPB(4);
            Delay_us (350-j);
        SetPB(4);
            Delay_us (j);
      }     
  
}
}
回复

使用道具 举报

本版积分规则

QQ|一淘宝店|手机版|商店|一乐电子 ( 粤ICP备09076165号 ) 公安备案粤公网安备 44522102000183号

GMT+8, 2025-10-31 23:53 , Processed in 0.035552 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表