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

📄 a.c

📁 51单片机花朵开放程序
💻 C
字号:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit motor_output_z=P2^0;
sbit motor_output_f=P2^1;
sbit key=P2^7;
sbit xianwei=P2^2;
uchar time_buff;
uchar key_time_buff;
uint flower_open_time_buff;
uint flower_close_time_buff;
uchar flag;
bit key_up;

void mcu_init(void)
{
	motor_output_z=0;
	motor_output_f=0;
	key=1;
	xianwei=1;
	TMOD=0x01;
	TH0=(65536-5000)/256;
	TL0=(65536-5000)%256;
	TR0=1;
	ET0=1;
	EA=1;		
}

void key_ord(void)
{
	if(key_up==1)
	{
		if(key_time_buff>1)
		{
			key_up=0;
			flag++;
			if(flag>1)
				flag=0;
		}
	}
}

void output_cnt(void)
{
	if(flag==0)
	{
		flower_open_time_buff=0;
		if(flower_close_time_buff<4000)//20s
		{
			flower_close_time_buff++;
			if(xianwei==0)
			{
				motor_output_z=0;
				motor_output_f=0;
			}
			else
			{
				motor_output_z=0;
				motor_output_f=1;				
			}	
		}
		else
		{
			motor_output_z=0;
			motor_output_f=0;	
		}
	}
	if(flag==1)
	{
		flower_close_time_buff=0;
		if(flower_open_time_buff<2000)//10s
		{
			flower_open_time_buff++;
			motor_output_z=1;
			motor_output_f=0;
		}
		else
		{
			motor_output_z=0;
			motor_output_f=0;
		}
	}
}

void main(void)
{
	mcu_init();
	while(1)
	{;}
}

void time_t0(void) interrupt 1
{
	TH0=(65536-5000)/256;
	TL0=(65536-5000)%256;
	output_cnt();
	if(time_buff<2)
	{
		time_buff++;
	}
	else
	{
		time_buff=0;
		if(motor_output_z==1||motor_output_f==1)
		{;}
		else
		{
			if(key==0)
			{
				if(key_time_buff<10)
				{
					key_time_buff++;
				}
			}
			else
			{
				key_time_buff=0;
				key_up=1;
			}	
			key_ord();
		}
	}	
}

⌨️ 快捷键说明

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