蓝桥杯单片机第五届模拟题(模拟灌溉)

Posted 一心向月

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了蓝桥杯单片机第五届模拟题(模拟灌溉)相关的知识,希望对你有一定的参考价值。

全部文件:提取码:azxy


#include "STC15F2K60S2.h"
#include "ds1302.h"
#include "iic.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit S4=P3^3;
sbit S5=P3^2;
sbit S6=P3^1;
sbit S7=P3^0;

u8 code duan[15]=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf,0xc1,0x8e,0xc6;
extern u8 Time[3];
u8 model=0;
u16 humid=0;
u8 humid_cc=50;
u8 stat=1;
u8 been_flag=0;
u8 jdq_flag=0;
u8 flag=0;

void delay(u16 i)

	while(i--);


void Chan_hc573(chose)

	switch(chose)
	
		case 4:
			P2 = (P2 & 0x1f) | 0x80; break;
		case 5:
			P2 = (P2 & 0x1f) | 0xa0; break;
		case 6:
			P2 = (P2 & 0x1f) | 0xc0; break;
		case 7:
			P2 = (P2 & 0x1f) | 0xe0; break;
		case 0:
			P2 = (P2 & 0x1f) | 0x00; break;
	


void Init_system()

	Chan_hc573(5);
	P0=0x00;
	Chan_hc573(4);
	P0=0xff;


void Smg_display(u8 com,u8 dat)

	Chan_hc573(7);
	P0=0xff;
	Chan_hc573(6);
	P0=0x01<<com;
	Chan_hc573(7);
	P0=dat;


void Close_smg()

	Chan_hc573(6);
	P0=0x00;
	Chan_hc573(7);
	P0=0xff;


void model_display()

	if(model==0)
	
		Smg_display(0,duan[Time[0]/16]); delay(1000);
		Smg_display(1,duan[Time[0]%16]); delay(1000);
		Smg_display(2,duan[11]); delay(1000);
		Smg_display(3,duan[Time[1]/16]); delay(1000);
		Smg_display(4,duan[Time[1]%16]); delay(1000);
		Smg_display(5,duan[10]); delay(1000);
		Smg_display(6,duan[humid/10]); delay(1000);
		Smg_display(7,duan[humid%10]); delay(1000);
		Close_smg();
	
	else if(model==1)
	
		Smg_display(0,duan[11]); delay(1000);
		Smg_display(1,duan[11]); delay(1000);
		Smg_display(2,duan[10]); delay(1000);
		Smg_display(3,duan[10]); delay(1000);
		Smg_display(4,duan[10]); delay(1000);
		Smg_display(5,duan[10]); delay(1000);
		Smg_display(6,duan[humid_cc/10]); delay(1000);
		Smg_display(7,duan[humid_cc%10]); delay(1000);
		Close_smg();
	


void Key_down()

	if(S7==0)
	
		delay(100);
		if(S7==0)
		
			while(S7==0) model_display();
			jdq_flag=0;
			if(model==0)
			
				stat++;
				if(stat==3) stat=1;
			
		
	
	else if(S6==0)
	
		delay(100);
		if(S6==0)
		
			while(S6==0) model_display();
			if(stat==1) 
				
				humid_cc=EEPROM_read(0x01);
				model++;
				if(model==2) EEPROM_wire(0x01,humid_cc);model=0;
			
			else if(stat==2) flag=~flag;
		
	
	else if(S5==0)
	
		delay(100);
		if(S5==0)
		
			while(S5==0) model_display();
			if(stat==1) 
			
				if(model==1)
				
					if(humid_cc!=99) humid_cc++;
				
			
			else if(stat==2) jdq_flag=1;
		
	
	else if(S4==0)
	
		delay(100);
		if(S4==0)
		
			while(S4==0) model_display();
			if(stat==1) 
			
				if(model==1)
				
					if(humid_cc!=0) humid_cc--;
				
			
			else if(stat==2) jdq_flag=0;
		
	


void LED()

	Chan_hc573(4);
	if(stat==1) P00=0;
	else if(stat==2) P01=0;
	Chan_hc573(0);


void Been_JDQ()

	Chan_hc573(5);
	if(stat==1)
	
		if(humid_cc>humid) jdq_flag=1;
		else jdq_flag=0;
	
	if(stat==2)
	
		if(humid_cc>humid) been_flag=1;
		else been_flag=0;
	
	if(jdq_flag==1) P04=1;
	else P04=0;
	if(flag==0)
	
		if(been_flag==1) P06=1;
		else P06=0;
	
	else  P06=0;
	Chan_hc573(0);



void main()

	Init_system();
	wire_time();
	EEPROM_wire(0x01,humid_cc);
	while(1)
	
		LED();
		Been_JDQ();
		Key_down();
		read_time();
		model_display();
		humid=PCF8591_read(3)*99/255;
	

以上是关于蓝桥杯单片机第五届模拟题(模拟灌溉)的主要内容,如果未能解决你的问题,请参考以下文章

蓝桥杯单片机第十三届模拟题

蓝桥杯单片机第十三届模拟题

《蓝桥杯真题》:2021单片机省赛第二场暨第十三届蓝桥杯赛前模拟试题

《蓝桥杯真题》:2021单片机省赛第二场(第十二届第二场)暨第十三届蓝桥杯赛前模拟试题

蓝桥杯单片机第五届

蓝桥杯单片机第五届