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

}
相关推荐
FanXing_zl10 小时前
在整数MCU上实现快速除法计算:原理、方法与优化
单片机·嵌入式硬件·mcu·算法·定点运算
Dunkle.T12 小时前
单片机中NRST引脚复用为GPIO
单片机·嵌入式硬件·复用·py32f002bl15s7·nrst
逆小舟12 小时前
【STM32】中断
stm32·单片机·嵌入式硬件
我先去打把游戏先12 小时前
ESP32C3开发指南(基于IDF):console控制台命令行交互功能
笔记·嵌入式硬件·mcu·物联网·学习·esp32·交互
rit843249914 小时前
基于STM32+OV7725+DHT11+ESP8266的物联网数据采集与显示
stm32·嵌入式硬件·物联网
Shylock_Mister14 小时前
Linux 常用命令大全:从入门到精通
c语言·嵌入式硬件·物联网
准测仪器1 天前
6项提高电机制造质量的电气测试方案
单片机·嵌入式硬件·制造·电机·电气·放电测试·局部放电测试
ACP广源盛139246256731 天前
(ACP广源盛)GSV6172---MIPI/LVDS 信号转换为 Type-C/DisplayPort 1.4/HDMI 2.0 并集成嵌入式 MCU
c语言·开发语言·单片机·嵌入式硬件·音视频
hazy1k1 天前
51单片机基础-IO扩展(并转串 74HC165)
stm32·单片机·嵌入式硬件·fpga开发·51单片机·1024程序员节
Tony小周1 天前
使用QKeyEvent keyPress(QEvent::KeyPress, key模拟键盘发送事件,会导致主程序卡死
嵌入式硬件·qt