⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 led12.c

📁 yi ge hen jian dan de zi liao
💻 C
字号:
#include<reg52.h>
#include<intrins.h>

#define uchar unsigned char
#define uint  unsigned int

sbit LED1=P0^0;
sbit LED2=P0^1;
sbit LED3=P0^2;
sbit LED4=P0^3;
sbit LED5=P0^4;


sbit KEY1=P3^1;
sbit KEY2=P3^2;
sbit KEY3=P3^3;
sbit KEY4=P3^4;
sbit KEY5=P3^5;

#define ON  0
#define OFF 1

uchar LED1_cnt=0;
uchar LED2_cnt=0;
uchar LED3_cnt=0;
uchar LED4_cnt=0;
uchar LED5_cnt=0;

uint cnt1=0;
uint cnt2=0;
uint cnt3=0;
uint cnt4=0;
uint cnt5=0;

void Delay(uint n)
{
	while(n--);
}

void main()
{
	uint n=30;
	LED1=ON;
	LED2=ON;
	LED3=ON;
	LED4=ON;
	LED5=ON;
	
	while(1)
	{
		Delay(n);

if(KEY1==0)
		{
			cnt1=1;
			LED1_cnt=100;
		}

		if(cnt1==1000)
		{
			cnt1++;
			if(LED1_cnt){LED1=OFF;LED1_cnt--;}
			else cnt1=0;
			
		}
		else if(cnt1==3000)
		{
			cnt1=1;
			LED1=ON;
		//	LED2=ON;
		}
		else if(cnt1)cnt1++;

	
if(KEY2==0)
		{
			cnt2=1;
			LED2_cnt=100;
		}

		if(cnt2==1000)
		{
			cnt2++;
			if(LED2_cnt){LED2=OFF;LED2_cnt--;}
			else cnt2=0;
		}
		else if(cnt2==3000)
		{
			cnt2=1;
		//	LED1=ON;
			LED2=ON;
		}
		else if(cnt2)cnt2++;

if(KEY3==0)
		{
			cnt3=1;
			LED3_cnt=100;
		}

		if(cnt3==1000)
		{
			cnt3++;
			if(LED3_cnt){LED3=OFF;LED3_cnt--;}
			else cnt3=0;
		}
		else if(cnt3==3000)
		{
			cnt3=1;
		//	LED1=ON;
			LED3=ON;
		}
		else if(cnt3)cnt3++;
if(KEY4==0)
		{
			cnt4=1;
			LED4_cnt=100;
		}

		if(cnt4==1000)
		{
			cnt4++;
			if(LED4_cnt){LED4=OFF;LED4_cnt--;}
			else cnt4=0;
		}
		else if(cnt4==3000)
		{
			cnt4=1;
		//	LED1=ON;
			LED4=ON;
		}
		else if(cnt4)cnt4++;
if(KEY5==0)
		{
			cnt5=1;
			LED5_cnt=100;
		}

		if(cnt5==1000)
		{
			cnt5++;
			if(LED5_cnt){LED5=OFF;LED5_cnt--;}
			else cnt5=0;
		}
		else if(cnt5==3000)
		{
			cnt5=1;
		//	LED1=ON;
			LED5=ON;
		}
		else if(cnt5)cnt5++;

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -