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

}
相关推荐
华清远见IT开放实验室13 小时前
实验室建设案例 | 石家庄科技信息职业学院嵌入式实验室——从底层硬件到系统应用,一所应用型高校的嵌入式人才培养这样落地
linux·arm开发·stm32·嵌入式硬件·高校·实验室建设
AI的探索之旅15 小时前
AI辅助原理图评审:电源去耦、BOOT引脚、VCAP——19项逐一核查,遗漏?不存在的
人工智能·vscode·嵌入式硬件
茯苓gao15 小时前
嵌入式开发笔记:EtherCAT协议从硬件到软件完整配置指南——从零搭建一套EtherCAT通信系统
笔记·嵌入式硬件·学习
GeekArch16 小时前
第24讲:Vibe模式代码风格控制——适配Keil/STM32工程规范
人工智能·stm32·单片机·嵌入式硬件·mcu·决策树·ai编程
Freedom_my16 小时前
STM32项目3
stm32·单片机·嵌入式硬件
国科安芯17 小时前
星间光链路:AS32S601型抗辐射MCU在空间激光通信终端控制中的技术实现
服务器·网络·单片机·嵌入式硬件·物联网·安全·信息与通信
小李不困还能学19 小时前
基于 51 单片机的8 路抢答器设计教程
单片机·嵌入式硬件·mongodb·抢答器
CedarQR19 小时前
万字长文:从零在 RK3588 上部署 PaddleSpeech 中文 TTS 全流程(FastSpeech2 + HiFiGAN)
开发语言·c++·嵌入式硬件·ubuntu·json
萌动的小火苗19 小时前
嵌入式开发中的栈与队列:任务调度为什么依赖数据结构
数据结构·c++·单片机·嵌入式硬件
振浩微433射频芯片20 小时前
工业遥控器总在关键时刻“掉链子”?——433MHz芯片方案如何破局
网络·单片机·嵌入式硬件·物联网·工业遥控