51 单片机 led 灯光操作

led流水灯

c 复制代码
#include <REGX52.H>
#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);
	}

}

延时代码

c 复制代码
#include "INTRINS.H"

void Delay(unsigned int xms)		
{
	unsigned char i, j;
	while(xms--){
			_nop_();
			i = 2;
			j = 199;
			do
			{
				while (--j);
			} while (--i);
	}


}

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

c 复制代码
#include <REGX52.H>

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;
	}

}

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

c 复制代码
#include <REGX52.H>


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;
		}

	
	}

}

独立按键 led二进制

c 复制代码
#include <REGX52.H>


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;
		}

	
	}

}

独立按键控制led移位

c 复制代码
#include <REGX52.H>


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);
		}
	
	}

}
相关推荐
无畏jh23 分钟前
TLE5012B磁阻芯片解读
嵌入式硬件·汽车嵌入式·磁阻芯片
培林将军32 分钟前
Altium Designer 22的安装与汉化
嵌入式硬件·ad工具安装
idcardwang33 分钟前
xl9555-IO拓展芯片
stm32·单片机·嵌入式硬件
Y1rong37 分钟前
STM32之EXTI
stm32·单片机·嵌入式硬件
兆龙电子单片机设计42 分钟前
【STM32项目开源】STM32单片机智能语音家居控制系统
stm32·单片机·嵌入式硬件·物联网·开源·自动化
TaidL1 小时前
茂捷M1020电感式编码器芯片赋能工业智能升级,适用于工业及机器人等领域的各种应用场景
单片机·嵌入式硬件
意法半导体STM321 小时前
【官方原创】SAU对NSC分区的影响 LAT1578
stm32·单片机·嵌入式硬件·mcu·信息安全·trustzone·stm32开发
SmartRadio1 小时前
MK8000(UWB射频芯片)与DW1000的协议适配
c语言·开发语言·stm32·单片机·嵌入式硬件·物联网·dw1000
LDR0061 小时前
芯片电路的引脚标识代表什么?
stm32·单片机·嵌入式硬件
恒锐丰小吕2 小时前
屹晶微 EG3116 600V高压、2A/2.5A驱动、双高有效输入逻辑的半桥栅极驱动芯片技术解析
嵌入式硬件·硬件工程