• 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
  • 相关阅读:
    记一次使用nacos2踩到的坑
    也许你低估了defaultdict的偷懒能力!
    还在用饼状图?来瞧瞧这些炫酷的百分比可视化新图形(附代码实现)
    技术管理实战之全貌
    【前端学习 Vue (8) 什么是SSR】
    csp201604
    Docker的Cgroup资源限制
    使用Eclipse搭建STM32嵌入式开发环境
    go:快速添加接口方法及其实现
    【移植代码】matlab.engine报错、numpy+mkl安装、Qt platform plugin报错总结
  • 原文地址:https://blog.csdn.net/weixin_45079974/article/details/132921040