求个51单片机at89c51心形流水灯,程序

 我来答
  • 你的回答被采纳后将获得:
  • 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
百度网友5a2dedd
2016-04-10 · TA获得超过122个赞
知道小有建树答主
回答量:343
采纳率:0%
帮助的人:99.8万
展开全部
百度吧,一般人不会存这样的程序的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
宿兴电子
2024-11-28 广告
联系我们蜂鸣器是一种一体化结构的电子讯响器,采用直流电压供电,广泛应用于计算机、打印机、复印机、报警器、电子玩具、汽车电子设备、电话机、定时器等电子产品中作发声器件。蜂鸣器主要分为压电式蜂鸣器和电磁式蜂鸣器两种类型。蜂鸣器在电路中用字母“H... 点击进入详情页
本回答由宿兴电子提供
一吻不zhi
2016-04-10 · 超过26用户采纳过TA的回答
知道答主
回答量:396
采纳率:100%
帮助的人:30.5万
展开全部
这个。学过单片机得都会啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
修者世界
2016-04-10 · TA获得超过5852个赞
知道大有可为答主
回答量:5984
采纳率:61%
帮助的人:813万
展开全部

这是一个比较全的程序,花样较多,供参考。

#include<reg51.h>

#include <intrins.h>

#define uint unsigned int

#define uchar unsigned char

void delay(uint k)   


{    

       uinti,j;

       for(i=k;i--;i>0)

              for(j=100;j--;j>0);

}

void main()


{    

       uchartemp0,temp1;

       ucharyi;

       ucharyi0,yi1;                  

       uinti,j,k,a,b;

       j=k=a=b=3;   

                                                               //全部亮

       P0=P1=P2=P3=0x00;

       delay(700);

       P0=P1=P2=P3=0xff;    

                                                               //每个io口独自亮

       for(i=2;i--;i>0)

       {

              P1=P0=0x00;

              delay(500);

              P1=P0=0xff;

              P3=P2=0x00;

              delay(500);

              P3=P2=0xff;

       }

                                                               //闪烁3次

       for(i=2;i--;i>0)

       {

              P0=P1=P2=P3=0x00;

              delay(100);

              P0=P1=P2=P3=0xff;

              delay(100);

       }

                                                               //P1、P2亮,P3、P0暗

       for(i=3;i--;i>0)

       {

              P1=0x00,P2=0x00; P3=0xff,P0=0xff;

              delay(500);

              P1=0xff,P2=0xff,P3=0x00,P0=0x00;

              delay(500);

       }

 

                                                               //四个点的流水

 

       while(j>0)

       {

              temp0=0xfe,temp1=0x7f;

              P1=P3=temp0,P2=P0=temp1;

              delay(100);

              for(i=7;i--;i>0)

              {

                     temp0=_crol_(temp0,1),temp1=_cror_(temp1,1);

                     P1=P3=temp0,P2=P0=temp1;

                     delay(100);

              }

               j--;

        }

                                                                //全部亮,闪三次

       for(i=3;i--;i>0)

       {

              P0=P1=P2=P3=0x00;

              delay(300);

              P0=P1=P2=P3=0xff;

              delay(300);

       }                     

 

                                                               //四个IO口同样跟踪流水

       while(k>0)

       {

              temp0=0xfe,temp1=0x7f;

              P1=P3=temp0,P2=P0=temp1;

              delay(60);

              for(i=7;i--;i>0)

              {

                     temp0=temp0<<1,temp1=temp1>>1;

                     P1=P3=temp0,P2=P0=temp1;

                     delay(60);

              }

              k--;

        }

        P0=P1=P3=P2=0xff;

        while(k<3)

        {

               temp0=0x7f,temp1=0xfe;

               P1=P3=temp0,P2=P0=temp1;

               delay(60);

               for(i=7;i--;i>0)

                {

                    temp0=temp0>>1,temp1=temp1<<1;

                     P1=P3=temp0,P2=P0=temp1;

                     delay(60);

                }

               k++;

        }

        P3=P2=0xff;

                                                       //两边单个从上向下流水

       yi=0xfe;

       P1=P0=yi;

       delay(50);

       for(i=7;i--;i>0)

       {

              yi=_crol_(yi,1);

              P1=P0=yi;

              delay(50);

       }

       P1=P0=0xff;

       yi=0xfe;

       P3=P2=yi;

       delay(50);

       for(i=7;i--;i>0)

       {

              yi=_crol_(yi,1);

              P3=P2=yi;

              delay(50);

       }

       P3=P2=0Xff;

                                                         //两边单个返回流水

       for(i=7;i--;i>0)                     

       {

              yi=_cror_(yi,1);

              P3=P2=yi;

              delay(50);

       }

       P3=P2=0xff;

       for(i=7;i--;i>0)

       {

              yi=_cror_(yi,1);

              P0=P1=yi;

              delay(50);

       }                                                     

                                                     //全部亮,闪三次

       P0=P1=P3=P2=0xff;

       for(i=3;i--;i>0)

       {

              P0=P1=P2=P3=0x00;

              delay(100);

              P0=P1=P2=P3=0xff;

              delay(100);

       }

                                                   //流水灯

 

       yi0=0xfe,yi1=0x7f;

       P3=P2=yi1,P1=P0=yi0;

       delay(100);

       for(i=7;i--;i>0)

       {

               yi0=yi0<<1, yi1=yi1>>1;

               P1=P0=yi0,P3=P2=yi1;

               delay(100);

       }

       P1=P2=P3=P0=0xff;

       delay(200);

       yi0=0x7f,yi1=0xfe;

       P1=P0=yi0,P3=P2=yi1;

       for(i=7;i--;i>0)

       {

              yi0=yi0>>1,yi1=yi1<<1;

              P1=P0=yi0,P3=P2=yi1;

              delay(100);    

       }

                                                      //大循环跟踪流水

       P1=P2=P3=P0=0xff;

       for(i=8;i--;i>0)

       {

               P1=P1<<1;

               delay(50);

       }

       for(i=8;i--;i>0)

       {

               P3=P3<<1;

               delay(50);

       }

 

       for(i=8;i--;i>0)

       {

               P2=P2>>1;

               delay(50);

       }

       for(i=8;i--;i>0)

       {

               P0=P0>>1;

               delay(50);

       }                                       

                                                            //逆向大循环跟踪流水

 

       P1=P2=P3=P0=0xff;

       for(i=8;i--;i>0)

       {

               P0=P0<<1;

               delay(50);

       }

       for(i=8;i--;i>0)

       {

               P2=P2<<1;

               delay(50);

       }

       for(i=8;i--;i>0)

       {

               P3=P3>>1;

               delay(50);

       }

       for(i=8;i--;i>0)

       {

               P1=P1>>1;

               delay(50);

       }


//全部亮,闪三次

       P0=P1=P3=P2=0xff;

       for(i=4;i--;i>0)

       {

              P0=P1=P2=P3=0x00;

              delay(100);

              P0=P1=P2=P3=0xff;

              delay(100);

       }

                                                                    //全部亮,只有一个暗的在流水

      

       temp0=0x01,temp1=0x00;

       P1=P0=temp0,P3=P2=temp1;

       delay(100);

       for(i=7;i--;i>0)

       {

              temp0=_crol_(temp0,1);

              P1=P0=temp0;

              delay(100);

       }

       P1=P0=0x00;

       temp1=0x01;

       P3=P2=temp1;

       delay(100);

       for(i=7;i--;i>0)

       {

              temp1=_crol_(temp1,1);

              P3=P2=temp1;

              delay(100);

       }

                                                                     //全部亮,逆向一个暗在流水

       temp0=0x00,temp1=0x80;

       P1=P0=temp0,P3=P2=temp1;

       delay(100);

       for(i=7;i--;i>0)

       {    

              temp1=_cror_(temp1,1);

              P3=P2=temp1;

              delay(100);

       }

       P3=P2=0x00;

       temp0=0x80;

       P1=P0=temp0;

       delay(100);

       for(i=7;i--;i>0)

       {

              temp0=_cror_(temp0,1);

              P1=P0=temp0;

              delay(100);

       }

                                                                  //花样

       temp0=0xaa,temp1=0x55;

       P1=P3=temp0,P2=P0=temp1;

       delay(500);

       for(;a--;a>0)

              {

                     for(i=7;i--;i>0)

                     {

                            temp0=_crol_(temp0,1),temp1=_cror_(temp1,1);

                            P1=P3=temp0,P2=P0=temp1;

                            delay(500);    

                     }

 

               }

       for(;b--;b>0)

              {

                     temp0=0xee,temp1=0x77;

                     P1=P3=temp0,P2=P0=temp1;

                     delay(300);

                     for(i=7;i--;i>0)

                     {

                            temp0=_crol_(temp0,1),temp1=_cror_(temp1,1);

                            P1=P3=temp0,P2=P0=temp1;

                            delay(300);    

                     }

              }   

                                                                            //环形逐个亮

                                                                                   

       P1=P2=P3=P0=0xff;

       for(i=8;i--;i>0)

       {

               P0=P0<<1;

               delay(50);

       }

       for(i=8;i--;i>0)

       {

               P2=P2<<1;

               delay(50);

       }

       for(i=8;i--;i>0)

       {

               P3=P3>>1;

               delay(50);

       }

       for(i=8;i--;i>0)

       {

               P1=P1>>1;

               delay(50);

       }

                                                                                          //逐个熄灭

       for(i=7;i--;i>0)

       {

              P0=~P0<<1;

              P0=~P0;

              delay(50);

       }

       P0=0xff;

 

       for(i=7;i--;i>0)

       {

              P2=~P2<<1;

              P2=~P2;

              delay(50);

       }

       P2=0xff;

       for(i=7;i--;i>0)

       {

              P3=~P3>>1;

              P3=~P3;

              delay(50);

       }

       P3=0xff;

       for(i=7;i--;i>0)

       {

              P1=~P1>>1;

              P1=~P1;

              delay(50);

       }

       P1=0xff;   

}

本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式