单片机流水灯的控制设计

单片机流水灯的控制设计
#include <reg51.h>
#include <intrins.h>
#include <math.h>
typedef unsigned char uchar;
void Delay()                   //延时0.5s
{
 uchar i,j;
 for(i=0;i<150;i++)
    {
   for(j=0;j<255;j++)
        _nop_();  
 } 
}

void main()
{
 uchar i,count ;
 P1 = 0xff ;                     //初始灯状态为关闭
    count = 0 ;
   while(1)
 {
  count++;
        if(count==1)
        {
           for(i=0;i<10;i++)
     {
             Delay();                   //延时0.5s
             P1 = 0xFE;                 //第一个灯亮
             Delay();                   //延时0.5s
             P1 = 0XFF ;                //灯灭
           }
        }
        else if(count==2)
        {
           for(i=0;i<10;i++)
     {
             Delay();                   //延时0.5s
             P1 = 0xFD;                 //第二个灯亮
             Delay();                   //延时0.5s
             P1 = 0XFF ;                //灯灭
           }
        }
  else if(count==3)
        {
           for(i=0;i<10;i++)
     {
             Delay();                   //延时0.5s
             P1 = 0xFB;                 //第三个灯亮
             Delay();                   //延时0.5s
             P1 = 0XFF ;                //灯灭
           }
        }
  else if(count==4)
        {
           for(i=0;i<10;i++)
     {
             Delay();                   //延时0.5s
             P1 = 0xF7;                 //第四个灯亮
             Delay();                   //延时0.5s
             P1 = 0XFF ;                //灯灭
           }
        }
  else if(count==5)
        {
           for(i=0;i<10;i++)
     {
             Delay();                   //延时0.5s
             P1 = 0xEF;                 //第五个灯亮
             Delay();                   //延时0.5s
             P1 = 0XFF ;                //灯灭
           }
        }
  else if(count==6)
        {
           for(i=0;i<10;i++)
     {
             Delay();                   //延时0.5s
             P1 = 0xDF;                 //第六个灯亮
             Delay();                   //延时0.5s
             P1 = 0XFF ;                //灯灭
           }
        }
     else if(count==7)
        {468

[1] [2] [3] [4] [5] 下一页

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有