• 51 单片机 led 灯光操作


    led流水灯

    #include 
    #include "INTRINS.H"
    
    void Delay(unsigned int xms)		
    {
    	unsigned char i, j;
    	while(xms--){
    			_nop_();
    			i = 2;
    			j = 199;
    			do
    			{
    				while (--j);
    			} while (--i);
    	}
    
    
    }
    
    void main(){
    	while(1){
    		P2=0xFE;
    		Delay(500);
    			P2=0xFD;
    		Delay(500);
    			P2=0xFB;
    		Delay(500);
    		P2=0xF7;
    		Delay(500);
    			P2=0xEF;
    		Delay(500);
    			P2=0xDF;
    		Delay(500);	
    			P2=0xBF;
    		Delay(500);
    			P2=0x7F;
    		Delay(500);
    	}
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    延时代码

    #include "INTRINS.H"
    
    void Delay(unsigned int xms)		
    {
    	unsigned char i, j;
    	while(xms--){
    			_nop_();
    			i = 2;
    			j = 199;
    			do
    			{
    				while (--j);
    			} while (--i);
    	}
    
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    独立按键控制led(松发式)

    #include 
    
    void main(){
    
    
    	while(1){
    	
    		if(P3_1==0)
    			P2_0=0;
    		else
    			P2=0xFF;
    		if(P3_0==0)
    			P2=0xFD;
    		else
    			P2=0xFF;
    		if(P3_2==0)
    			P2=0xFB;
    		else
    			P2=0xFF;
    		if(P3_3==0)
    			P2=0xF7;
    		else
    			P2=0xFF;
    	}
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    独立按键控制led 按键去除抖动

    #include 
    
    
    void Delay(unsigned int xms)		
    {
    	unsigned char i, j;
    	while(xms--){
    			i = 2;
    			j = 199;
    			do
    			{
    				while (--j);
    			} while (--i);
    	}
    
    
    }
    
    void main(){
    
    
    	while(1){
    	
    		if(P3_1==0){
    			Delay(20);
    			while(P3_1==0);
    			Delay(20);
    			P2_0=~P2_0;
    		}
    
    	
    	}
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    独立按键 led二进制

    #include 
    
    
    void Delay(unsigned int xms)		
    {
    	unsigned char i, j;
    	while(xms--){
    			i = 2;
    			j = 199;
    			do
    			{
    				while (--j);
    			} while (--i);
    	}
    
    
    }
    
    void main(){
    	unsigned char x=0;
    
    	while(1){
    	
    		if(P3_1==0){
    			Delay(20);
    			while(P3_1==0);
    			Delay(20);
    			
    			x++;
    			P2=~x;
    		}
    
    	
    	}
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    独立按键控制led移位

    #include 
    
    
    void Delay(unsigned int xms)		
    {
    	unsigned char i, j;
    	while(xms--){
    			i = 2;
    			j = 199;
    			do
    			{
    				while (--j);
    			} while (--i);
    	}
    
    
    }
    
    void main(){
    	unsigned char x=0;
    	P2_0=0;
    	while(1){
    	
    		if(P3_0==0){
    			Delay(20);
    			while(P3_0==0);
    			Delay(20);
    			
    			x++;
    			x=x%8;
    		
    			P2=~(0x01<<x);
    		}
    		if(P3_1==0){
    			Delay(20);
    			while(P3_1==0);
    			Delay(20);
    			
    		
    			if(x==0)
    				x=7;
    			else
    				x--;
    		
    			P2=~(0x01<<x);
    		}
    	
    	}
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
  • 相关阅读:
    IV implied volatility surf
    万字Numpy教程带你从入门到放弃
    七.结构体
    C++11并发编程-线程的启用与销毁
    如何利用WhatsApp群发功能减轻团队工作量
    【无标题】
    天软特色因子看板 (2023.09 第09期)
    万字详解:MySql,Redis,Mq,ES的高可用方案解析
    Apifox --- 全套服务提升了团队效率,让研测之间充满了爱(记Apifox在工程中的实际应用)【云原生】
    ChatGPT在电子健康记录和医疗信息查询中的应用前景如何?
  • 原文地址:https://blog.csdn.net/weixin_45079974/article/details/132921040