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

标题: 流水灯 [打印本页]

作者: 123321    时间: 2015-4-14 20:57
标题: 流水灯
/********************************************************************
                            汇诚科技
网址:http://www.ourhc.cn
产品有售淘宝店:http://shop36330473.taobao.com   
*********************************************************************/
#include<reg52.h>                 //库文件
#define uchar unsigned char//宏定义无符号字符型
#define uint unsigned int  //宏定义无符号整型
/********************************************************************
                            初始定义
*********************************************************************/
uchar temp;           //定义字符型变量
uchar a,b,i;
/********************************************************************
                            延时函数
*********************************************************************/
void delay()//延时程序
{
        uchar m,n,s;
        for(m=20;m>0;m--)
        for(n=20;n>0;n--)
        for(s=248;s>0;s--);
}
/********************************************************************
                            主函数
*********************************************************************/
void main()
{
        temp=0xfe; //11111110定义每次一个灯亮
        while(1)
        {
                P3=P2=P0=P1=temp;//直接对1/0口赋值,使批输出低电平。
                delay();//延时
                for(i=1;i<8;i++)//实现广告灯的从右到左移动
                        {
                                a=temp<<i;                //左移i位
                                P3=P2=P0=P1=a;//相与求值
                                delay();
                        }
        }
}       
       
/********************************************************************
                              结束
*********************************************************************/
[attach]2266[/attach]







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