第十一届蓝桥杯大赛电子赛国赛代码

#include <control.H>

ulong systick;
uchar POS;
uchar data_dly;
uchar key_dly;

uint temperture;
uint AD_read;
uchar mode_flage;
uchar old_num=1;
uchar new_num=1;

uchar Timer_num = 17;
uchar Led_num = 4;
uchar temp_num = 25;
uchar Rtc_time;
uchar key_num;
uchar key4_flage;
uchar key5_flage1;
uchar key5_flage2;
uchar key8_flage;
uchar key9_flage;

uint count1=0;
uint count2=0;

bit Buzzer;
bit Relay;
bit read_flage;
bit bright_flage;

//*******************************************
void devies_init() //外设初始化
{
	if(data_dly < 50) return;
	else data_dly = 1;
  temperture = ds18b20_read_temp(1);
	AD_read = PCF8591_Read(0x01)*100/51.0;
}


//*******************************************
void smg_working(uchar channel) //显示任务
{
	switch(channel)  
	{
		case 0:
			SMG[0] = Timer_Read[2]/16;
			SMG[1] = Timer_Read[2]%16;
      SMG[2] = 10;
			SMG[3] = Timer_Read[1]/16;
			SMG[4] = Timer_Read[1]%16;
		  SMG[5] = 10;
			SMG[6] = Timer_Read[0]/16;
			SMG[7] = Timer_Read[0]%16;
		  DOT[6] = 0,DOT[2] = 0;
		break;
		
		case 1:
			SMG[0] = 13;
			SMG[1] = 12;
      SMG[2] = 12;
			SMG[3] = 12;
			SMG[4] = 12;
		  SMG[5] = temperture/100;
			SMG[6] = temperture/10%10;
			SMG[7] = temperture%10;
		  DOT[6] = 1,DOT[2] = 0;
		break;	
		
		case 2:
			SMG[0] = 14;
			SMG[1] = 12;
      SMG[2] = AD_read/100;
			SMG[3] = AD_read/10%10;
			SMG[4] = AD_read%10;
		  SMG[5] = 12;
			SMG[6] = 12;
			SMG[7] = mode_flage;
			DOT[6] = 0,DOT[2] = 1;
		break;
		
		case 3:
			SMG[0] = 14;
			SMG[1] = 4;
      SMG[2] = 12;
			SMG[3] = 12;
			SMG[4] = 12;
		  SMG[5] = 12;
			SMG[6] = Timer_num/10;
			SMG[7] = Timer_num%10;
			DOT[6] = 0,DOT[2] = 0;
		break;
		
		case 4:
			SMG[0] = 14;
			SMG[1] = 5;
      SMG[2] = 12;
			SMG[3] = 12;
			SMG[4] = 12;
		  SMG[5] = 12;
			SMG[6] = temp_num/10;
			SMG[7] = temp_num%10;
			DOT[6] = 0,DOT[2] = 0;
		break;
				
		case 5:
			SMG[0] = 14;
			SMG[1] = 6;
      SMG[2] = 12;
			SMG[3] = 12;
			SMG[4] = 12;
		  SMG[5] = 12;
			SMG[6] = 12;
			SMG[7] = Led_num%10;
			DOT[6] = 0,DOT[2] = 0;
		break;
	}	
}

//*******************************************
void key_working()
{
	if(key_dly <10) return;
	else key_dly = 1;
	key_num = key_2x2_scan();
	switch(key_num)
	{               
			case 4: key4_flage = 1 - key4_flage;
		break;
		  case 5:                                                           
				if(key4_flage == 0) {key5_flage1 = (1+key5_flage1)%3;}
				if(key4_flage == 1) {key5_flage2 = (1+key5_flage2)%3;}			
		break;
			case 8: key8_flage = 1; 
		break;
			case 9: key9_flage = 1; 
		break;						
	}	
	
	if(key4_flage == 0)
	{
		key5_flage2 = 0;
		if(key5_flage1 == 0) smg_working(0);
		else if(key5_flage1 == 1) smg_working(1);
		else if(key5_flage1 == 2) smg_working(2);
	}
	else if(key4_flage == 1)
	{
		key5_flage1 = 0;
		if(key5_flage2 == 0) 
		{
			smg_working(3);
			if(key8_flage == 1)
			{
				if(Timer_num>0)Timer_num = Timer_num - 1;
//				if(Timer_num<1)Timer_num = 0;
				key8_flage = 0;
			}
			if(key9_flage == 1)
			{
				if(Timer_num<23)Timer_num = Timer_num + 1;
//				if(Timer_num>=23)Timer_num = 23;
				key9_flage = 0;
			}	
		}
		
		else if(key5_flage2 == 1) 
		{
			smg_working(4);
			if(key8_flage == 1)
			{
				if(temp_num>0)temp_num = temp_num - 1;
				key8_flage = 0;
			}
			if(key9_flage == 1)
			{
				if(temp_num<99)temp_num = temp_num + 1;
				key9_flage = 0;
			}
		}
		else if(key5_flage2 == 2) 
		{
			smg_working(5);
			if(key8_flage == 1)
			{
				if(Led_num>4)Led_num = Led_num - 1;
				key8_flage = 0;
			}
			if(key9_flage == 1)
			{
				if(Led_num<8)Led_num = Led_num + 1;
				key9_flage = 0;
			}	
		}	
	}

}

*******************************************
void task_slove()
{
	Rtc_time = Timer_Read[2]/16*10 + Timer_Read[2]%16;
	
	if(AD_read > 100) 
	{
		mode_flage = 0;
		LED[Led_num-1] = 0;
	}
	else if(AD_read <= 100) 
	{	
		mode_flage = 1;
		LED[Led_num-1] = 1;
	}
	
	if(Rtc_time>=Timer_num) LED[0] = 1;
	else if(Rtc_time<Timer_num && Rtc_time>8) LED[0] = 0;
	
	if(temperture < temp_num*10) LED[1] = 1;
	else if(temperture >= temp_num*10) LED[1] = 0;

}


//*******************************************
void task_working()
{
	 ds1302_timer_read();
	 task_slove();
   devies_init();
	 key_working();
}

//*******************************************
void system_init()
{
	Timer1_Init();
	EA = 1;
	HC138_Init(0,0x00);
	HC138_Init(5,0x00);
	HC138_Init(4,0xff);
	ds1302_timer_write();
	ds18b20_read_begin();
}

//*******************************************
void Timer1_server() interrupt 3
{
	systick ++;
	data_dly ++;
	key_dly ++;
	led_display(LED,POS);
	smg_display(SMG,DOT,POS);
	if(++POS == 8) POS = 0;
	
	if(read_flage == 0)
	{
		old_num = mode_flage;
		read_flage = 1;
	}
	else
	{
		if(systick%50 == 0){new_num = mode_flage;}	
		if(new_num > old_num) {bright_flage=0,old_num=new_num;}
		if(new_num < old_num) {bright_flage=1,old_num=new_num;}
	}

	if(bright_flage == 0)
	{
		count2 = 0;
		count1 ++;
    if(count1>3000){LED[2] = 1;count1=0;}
	}
	
	if(bright_flage == 1)
	{
		count1 = 0;
		count2 ++;
		if(count2>3000){LED[2] = 0;count2=0;}
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小邓分享官

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值