考点串写(三)第十三届省赛第一场

#include "init.h"
#include "led.h"
#include "relay.h"
#include "timer.h"
#include "seg.h"
#include "key.h"
#include "onewire.h"
#include "ds1302.h"
#include "stdio.h"

unsigned char ucLed[8] = {0,0,0,0,0,0,0,0};
unsigned char seg_buf[8],seg_string[10];
unsigned char pos=0;
unsigned char Seg_Disp_Mode=0;

unsigned int Seg_Slow;
unsigned char Key_Slow;
unsigned char Key_Val,Key_Down,Key_Up,Key_Old;

bit Relay_flag; //0不吸合,1吸合
bit Control_Mode; //0温度控制,1时间控制
bit time_flag; //用来判断,时间显示时分还是分秒
bit Hour_flag; //在时间控制下,判断时间是否整点,过5秒
bit led_flag;  //L3 0.2秒切换标志

void Led_Proc();
void Seg_Proc();
void Key_Proc();

unsigned char ucRtc[3]={00,00,00};
float temperature;
unsigned char temperature_param_control=23;
unsigned char temperature_param=23;
unsigned char t_ms;

void main(void)
{
	rd_temperature();
	Delay750ms();
	Write_ucRtc(ucRtc);
	All_Init();
	Timer0Init();
	
	while(1)
	{
		Key_Proc();
		Seg_Proc();
		Led_Proc();
	}
	
}

void tm0_isr() interrupt 1 
{
	
	if(++Seg_Slow==500) Seg_Slow=0;
	if(++Key_Slow==10) Key_Slow=0;
		
	if(++pos==8) pos=0;
	Seg_Disp(seg_buf,pos);
	Led_Disp(pos,ucLed[pos]);
	
	Relay_Disp(Relay_flag);
	
	if(++t_ms==100)
	{
		t_ms=0;
		led_flag^=1; 
	}
}

void Key_Proc(void)
{
	if(Key_Slow) return;
	Key_Slow=1;
	
	Key_Val = Read_Key();
	Key_Down = Key_Val & (Key_Old^Key_Val);
	Key_Up = ~Key_Val & (Key_Old^Key_Val);
	Key_Old = Key_Val;
	
	switch(Key_Down)
	{
		case 12:
			if(++Seg_Disp_Mode==3) 
			{
				Seg_Disp_Mode=0; 
				temperature_param_control=temperature_param;
			}
		break;
		
		case 13:
			Control_Mode^=1;
		break;
		
		case 16:
			if(Seg_Disp_Mode==2)
			{
				if(++temperature_param==100) temperature=99;
			}
		break;
			
		case 17:
			if(Seg_Disp_Mode==2)
			{
				if(--temperature_param==9) temperature=10;
			}
		break;
	}
	
	if(Seg_Disp_Mode==1)
	{
		if(Key_Old==17) //长按是Old
		{
			time_flag=1;  
		}
		else 	time_flag=0;
	}
	
}

void Seg_Proc(void)
{
	if(Seg_Slow) return;
	Seg_Slow=1;
	
	temperature = rd_temperature()/16.0;
	Read_ucRtc(ucRtc);
	
	switch(Seg_Disp_Mode)
	{
		case 0:
			sprintf(seg_string,"U1   %3.1f",temperature);
		break;
		
		case 1:
			sprintf(seg_string,"U2 %02u-%02u",(unsigned int)ucRtc[0+(unsigned char)time_flag],(unsigned int)ucRtc[1+(unsigned char)time_flag]);
		break;
		
		case 2:
			sprintf(seg_string,"U3    %02u,",(unsigned int)temperature_param);
		break;
	}
	
	Seg_Trans(seg_buf,seg_string);
}

void Led_Proc(void)
{
	if(ucRtc[1] == 0 && ucRtc[2] == 0)
	{
		Hour_flag=1;
	}
	if(ucRtc[2] == 0x05)
	{
		Hour_flag=0;
	}
		
	ucLed[0] = Hour_flag;
	ucLed[1] = ~Control_Mode;
	ucLed[2] = led_flag?Relay_flag:0;
	//led3 是否在亮的间隔内,是的话再由继电器状态判断是否亮,否则是不亮的
	
	
	
	
	//继电器控制
	if(Control_Mode==0)
	{
		if((unsigned char)temperature>temperature_param_control)
		{
			Relay_flag=1;
		}
		else Relay_flag=0;
	}
	else
	{
		Relay_flag = Hour_flag;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值