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

}
相关推荐
硅基手札5 小时前
【串口技术系列文档 10】低功耗与唤醒机制
驱动开发·stm32·单片机·嵌入式硬件·mcu·计算机外设
yuehuaxin016 小时前
上海贝岭 BL6523GX(D78) 单相计量芯片开发笔记:引脚定义、寄存器配置与校表流程
嵌入式硬件·智能家居·适配器模式·智能硬件
Kuakewei8887 小时前
可调OVP/OCP USB限流保护芯片IC的50μs过流响应测试
嵌入式硬件
HRTOS7 小时前
HRTOS 官网内容调整记录:首页、系统架构与文档页面优化
单片机·系统架构·51单片机
雨田言炎7 小时前
STM32之SysTick--系统定时器(内容简单但重要,附件有程序源码)
stm32·单片机·嵌入式硬件
ccbw168 小时前
CH32M007K8U7:集成48V三相预驱的RISC-V电机MCU
单片机·嵌入式硬件
编程圈子9 小时前
I.MX6U 裸机开发 24. 电容触摸屏与 I2C 驱动
单片机·嵌入式硬件
Zwawa10 小时前
传感器模块都在交出什么:从模拟电压到数字协议
c语言·单片机·嵌入式
FakeOccupational11 小时前
【电路笔记 STM32】Cortex-M7 UART 中断模式(串口接收中断+串口空闲中断)
笔记·stm32·单片机
小李不想当小白11 小时前
USART串口协议(STM32标准库学习笔记)
经验分享·笔记·stm32·单片机·嵌入式硬件·学习