51单片机c语言流水灯单次循环程序怎么编写啊

[复制链接]
3948|8
 楼主| 614325 发表于 2013-3-17 21:29 | 显示全部楼层 |阅读模式
51单片机c语言流水灯单次循环程序怎么编写啊
zhangbtj 发表于 2013-3-17 21:33 | 显示全部楼层
弄个条件循环,设个变量设置循环次数,跳出就OK了
 楼主| 614325 发表于 2013-3-17 22:00 | 显示全部楼层
#define uint unsigned int
#define uchar unsigned char
void delay(uint);
uchar temp;
void main()
{
  P1=0xfe;
        P1=0xff;

       
        temp=0xfe;
  while (P1!=0x7f)
  {
                temp=_crol_(temp,1);
                delay(100);
                P1=temp;
        }       



}
void delay(uint z)
{

        uint x,y;
        for(x=z;x>0;x--)
          for(y=500;y>0;y--);
}

这个程序为什么第一个灯不亮呢怎么改压
 楼主| 614325 发表于 2013-3-17 22:02 | 显示全部楼层
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
void delay(uint);
uchar temp;
void main()
{


       
        temp=0xfe;
  while (P1!=0x7f)
  {
                temp=_crol_(temp,1);
                delay(100);
                P1=temp;
        }       



}
void delay(uint z)
{

        uint x,y;
        for(x=z;x>0;x--)
          for(y=500;y>0;y--);
}
是这个不是上面那个
 楼主| 614325 发表于 2013-3-17 22:30 | 显示全部楼层
有人懂么
sin0725 发表于 2013-3-17 23:27 | 显示全部楼层
是不是第一个灯跟第二个灯之间的延时太短了
nano313 发表于 2013-3-18 00:13 | 显示全部楼层
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
void delay(uint);
uchar temp;
void main()
{      
temp=0xfe;
  while (P1!=0x7f)
  {
   P0=temp;
   delay(100);
   temp=_crol_(temp,1);
  }        
}
void delay(uint z)
{
uint x,y;
  for(x=z;x>0;x--)
   for(y=500;y>0;y--);
}
先让灯亮一会再作移位
 楼主| 614325 发表于 2013-3-18 15:54 | 显示全部楼层
谢谢,问题已经解决啦,最后在放一个while(1)的死好啦
IC采购哪里去 发表于 2013-3-18 16:41 | 显示全部楼层
这个我见过,我们大学时候考试就考这个,不过现在是真心想不起来了,但是知道流水灯是怎么回事!嘿嘿!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

15

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部