zoukankan      html  css  js  c++  java
  • led流水灯

    置顶的意思是这个没搞懂,再研究研究。

    我也不知道啥叫流水灯。我做出来的是,D1亮一段时间,然后D1熄灭,D2亮一段时间。。。

    是我没有看任何资料自己做出来的,挺有成就感的哈。

    #include "reg52.h"
    
    typedef unsigned char u8;
    typedef unsigned int u16;
    
    sbit ledD1=P2^0; //P20     
    sbit ledD2=P2^1;
    sbit ledD3=P2^2;
    sbit ledD4=P2^3;
    sbit ledD5=P2^4;
    sbit ledD6=P2^5;
    sbit ledD7=P2^6;
    sbit ledD8=P2^7;//P27
    
    void delay(u16 i) //延时函数
    {
        while(i--)
        {
            //什么也不做
        };                            
    }
    void main()
    {
             while(1)
             {
                 ledD1=0;
                delay(60000);
                ledD1=1;
                delay(60000);
    
                ledD2=0;
                delay(60000);
                ledD2=1;
                delay(60000);
    
                ledD3=0;
                delay(60000);
                ledD3=1;
                delay(60000);
    
                ledD4=0;
                delay(60000);
                ledD4=1;
                delay(60000);
    
                ledD5=0;
                delay(60000);
                ledD5=1;
                delay(60000);
    
                ledD6=0;
                delay(60000);
                ledD6=1;
                delay(60000);
    
                ledD7=0;
                delay(60000);
                ledD7=1;
                delay(60000);
    
                ledD8=0;
                delay(60000);
                ledD8=1;
                delay(60000);
    
    
                
             }
    
    }

    我这个好象不对哈,哈哈。

    刚根据视频画了一个流水灯的示意图。

    代码我再琢磨琢磨

    其实改进也很简单,让D7到D2依次亮就可以了。

    #include "reg52.h"
    #include "intrins.h"
    typedef unsigned char u8;
    typedef unsigned int u16;
    
    sbit ledD1=P2^0;
    sbit ledD2=P2^1;
    sbit ledD3=P2^2;
    sbit ledD4=P2^3;
    sbit ledD5=P2^4;
    sbit ledD6=P2^5;
    sbit ledD7=P2^6;
    sbit ledD8=P2^7;
    
    
    
    void delay(u16 i) //延时函数
    {
        while(i--)
        {
            //什么也不做
        };                            
    }
    
    
    void main()
    {
        
        //D1到D8依次亮
        
        while(1)
        {
    
        ledD1=0;
        delay(60000);
        ledD1=1;
        delay(60000);
    
        ledD2=0;
        delay(60000);
        ledD2=1;
        delay(60000);
    
        ledD3=0;
        delay(60000);
        ledD3=1;
        delay(60000);
    
        ledD4=0;
        delay(60000);
        ledD4=1;
        delay(60000);
    
        ledD5=0;
        delay(60000);
        ledD5=1;
        delay(60000);
    
        ledD6=0;
        delay(60000);
        ledD6=1;
        delay(60000);
    
        ledD7=0;
        delay(60000);
        ledD7=1;
        delay(60000);
    
        ledD8=0;
        delay(60000);
        ledD8=1;
        delay(60000);
    
        //以上的代码就是D1到D8依次亮
    
        //D7到D2依次亮 
    
        ledD7=0;
        delay(60000);
        ledD7=1;
        delay(60000);
    
        ledD6=0;
        delay(60000);
        ledD6=1;
        delay(60000);
    
        ledD5=0;
        delay(60000);
        ledD5=1;
        delay(60000);
    
        ledD5=0;
        delay(60000);
        ledD5=1;
        delay(60000);
    
        ledD4=0;
        delay(60000);
        ledD4=1;
        delay(60000);
        
        ledD3=0;
        delay(60000);
        ledD3=1;
        delay(60000);    
    
        ledD2=0;
        delay(60000);
        ledD2=1;
        delay(60000);
    
    
        }
    
    
    }

    两个灯一起亮的流水灯

    #include "reg52.h"
    #include "intrins.h"
    typedef unsigned char u8;
    typedef unsigned int u16;
    
    sbit ledD1=P2^0;
    sbit ledD2=P2^1;
    sbit ledD3=P2^2;
    sbit ledD4=P2^3;
    sbit ledD5=P2^4;
    sbit ledD6=P2^5;
    sbit ledD7=P2^6;
    sbit ledD8=P2^7;
    
    
    
    void delay(u16 i) //延时函数
    {
        while(i--)
        {
            //什么也不做
        };                            
    }
    
    
    void main()
    {
        
        //D1到D8依次亮
        
        while(1)
        {
    
        //D1 D2一起亮
        ledD1=0;
        ledD2=0;
        delay(60000);
        ledD1=1;
        ledD2=1;
        delay(60000);
    
        //D3 D4一起亮
        ledD3=0;
        ledD4=0;
        delay(60000);
        ledD3=1;
        ledD4=1;
        delay(60000);
    
        //D5 D6一起亮
        ledD5=0;
        ledD6=0;
        delay(60000);
        ledD5=1;
        ledD6=1;
        delay(60000);
    
        //D7 D8一起亮
        ledD7=0;
        ledD8=0;
        delay(60000);
        ledD7=1;
        ledD8=1;
        delay(60000);
    
    
        //D6 D5一起亮
        ledD5=0;
        ledD6=0;
        delay(60000);
        ledD5=1;
        ledD6=1;
        delay(60000);
    
        //D4 D3
        ledD3=0;
        ledD4=0;
        delay(60000);
        ledD3=1;
        ledD4=1;
        delay(60000);
    
        
    
    
        }
    
    
    }

    给自己留了一个作业,当D1到D8的时候灯移动的速度越来越快,而从D8到D2的时候是灯移动越来越慢。

    #include "reg52.h"
    #include "intrins.h"
    typedef unsigned char u8;
    typedef unsigned int u16;
    
    sbit ledD1=P2^0;
    sbit ledD2=P2^1;
    sbit ledD3=P2^2;
    sbit ledD4=P2^3;
    sbit ledD5=P2^4;
    sbit ledD6=P2^5;
    sbit ledD7=P2^6;
    sbit ledD8=P2^7;
    
    
    
    void delay(u16 i) //延时函数
    {
        while(i--)
        {
            //什么也不做
        };                            
    }
    
    
    void main()
    {
        
        //D1到D8依次亮
        
        while(1)
        {
    
        ledD1=0;
        delay(60000);
        ledD1=1;
        delay(60000);
    
        ledD2=0;
        delay(55000);
        ledD2=1;
        delay(55000);
    
        ledD3=0;
        delay(50000);
        ledD3=1;
        delay(50000);
    
        ledD4=0;
        delay(45000);
        ledD4=1;
        delay(45000);
    
        ledD5=0;
        delay(40000);
        ledD5=1;
        delay(40000);
    
        ledD6=0;
        delay(35000);
        ledD6=1;
        delay(35000);
    
        ledD7=0;
        delay(30000);
        ledD7=1;
        delay(30000);
    
        ledD8=0;
        delay(25000);
        ledD8=1;
        delay(25000);
    
        //以上的代码就是D1到D7依次亮
    
        //D7到D2依次亮 
    
        ledD7=0;
        delay(30000);
        ledD7=1;
        delay(30000);
    
        ledD6=0;
        delay(35000);
        ledD6=1;
        delay(35000);
    
        ledD5=0;
        delay(40000);
        ledD5=1;
        delay(40000);
    
        ledD4=0;
        delay(45000);
        ledD4=1;
        delay(45000);
    
        ledD3=0;
        delay(50000);
        ledD3=1;
        delay(50000);
        
        ledD2=0;
        delay(55000);
        ledD2=1;
        delay(55000);    
    
    
    
        }
    
    
    }
  • 相关阅读:
    Kubernetes(k8s)中namespace的作用、反向代理访问k8s中的应用、k8s监控服务heapster
    Kubernetes(k8s)中dashboard的部署。
    Kubernetes(k8s)中Pod资源的健康检查
    Kubernetes(k8s)安装dns附件组件以及使用
    Kubernetes(k8s)的deployment资源
    Kubernetes(k8s)的Service资源
    Kubernetes(k8s)的RC(Replication Controller)副本控制器
    Kubernetes(k8s)常用资源的使用、Pod的常用操作
    简易图书管理系统(主要是jsp+servlet的练习),基于jsp+servlet的图书管理系统
    js 提取 sql 条件 表名 limit
  • 原文地址:https://www.cnblogs.com/yfish/p/10846706.html
Copyright © 2011-2022 走看看