因仑“3+1”工程特种兵精英论坛

标题: 跑马灯一 [打印本页]

作者: 123321    时间: 2015-4-14 20:59
标题: 跑马灯一
/********************************************************************
                            汇诚科技
网址:http://www.ourhc.cn
产品有售淘宝店:http://shop36330473.taobao.com   
*********************************************************************/

/*P0~P3一个灯循环亮且由慢变快*/

#include<reg52.h>                 //库文件
#define uchar unsigned char//宏定义无符号字符型
#define uint unsigned int  //宏定义无符号整型

uint tc;                     /*延时变量tc*/

/********************************************************************
                             主函数
*********************************************************************/
void main()
                {
         void delay(int t);        /*定义延时函数delay(int t)或delay(t)但delay()是错的因此函数是有参数的。*/
         void light();      /*void函数应无类型int. float等 说明,定义亮灯函数 light(),其是无参数的。*/
         while(1)                        /*大循环*/
         {
         tc=5000;
          while(tc>500)                /*tc由5000开始到500循环*/
          {
          light();
          tc=tc-1500;
         }
         while(tc>=100)          /*tc由500开始到小于100循环*/
         {light();
          tc=tc-80;}
         }
        }                                /*継续大循环*/

/********************************************************************
                             亮灯子函数
*********************************************************************/
void light()                /*亮灯子函数 light()其无直接参数*/
         {
         uint c;
         int i;
         c=0x0fe;                        /*P0口亮*/
         for(i=1;i<=9;i++)
          {P0=c;
             delay(tc);
              c=c<<1|1;                       /*等价c=c<<1;c=c+0x01*/
          }                 /*注:若用P0=P0<<1|1;因读P0再右移再加1,当P0某个脚外电路拉底就不对了*/
        c=0x7f;
          for(i=1;i<=9;i++)
           {P2=c;
            delay(tc);
            c=c>>1|0X80;
           }
        c=0x7f;
          for(i=1;i<=9;i++)
           {P3=c;
            delay(tc);
            c=c>>1|0X80;
           }
        c=0x7f;
          for(i=1;i<=9;i++)
           {P1=c;
            delay(tc);
            c=c>>1|0X80;
           }
        }

/********************************************************************
                             延时函数
*********************************************************************/
void delay(int t)        /*延时函数delay(int t)*/
        {int i;
         for(i=1;i<=t;i++)
          {
           }
        }
/********************************************************************
                              结束
*********************************************************************/
[attach]2268[/attach]







欢迎光临 因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/) Powered by Discuz! X3.4