10整体代码

appdemo.c

#include "hwjs.h" 
#include "system.h"
#include "SysTick.h"
#include "led.h"
#include "usart.h"
#include "oled.h"
#include "beep.h"
#include "dc_motor.h"
#include "ds18b20.h"
#include "key.h"
#include "smg.h"
#include "appdemo.h"
TypeFlag Myflag;
_sys_ctrl sys_ctrl;
void Myflag_init(void)
{
Myflag.Timeflag=0;//??????/????/????
	Myflag.s=0;
	Myflag.h=32;
	Myflag.l=25;
	 
	Myflag.c=0;
}

void OLED_1(void)
{
	OLED_Clear();
	OLED_ShowString(0,0,"T:",12);
	OLED_ShowString(0,15,"H:",12);
	OLED_ShowString(0,30,"L:",12);
		OLED_ShowString(0,45,"S:",12);
	OLED_Refresh_Gram();

}



void sys_data_get(void)
{
	u8 i=0;
	
	while(1)
	{
		//????
		i++;
		if(i%1==0)
			Myflag.t=DS18B20_GetTemperture()*10;
		
		break;
	}
}

void show(void)
{
u8 c[5];
	while(1)
	{
	    c[0]=Myflag.t/100+0x30;;
		c[1]=Myflag.t%100/10+0x30;;
		c[2]='.';
		c[3]=Myflag.t%100%10+0x30;;
		c[4]='\0';
	OLED_ShowString(12,0,c,12);
		
	OLED_ShowNum(12,15,Myflag.h,2,12);	
		OLED_ShowNum(12,30,Myflag.l,2,12);	
		switch(Myflag.s)
		{
			case 0:
			OLED_ShowString(12,40,"off",12);		
			break;
			case 1:
				OLED_ShowString(12,40,"hot",12);		
			break;
			case 2:
				OLED_ShowString(12,40,"cold",12);
			break;
		
		}
			switch(Myflag.Timeflag)
		{
			case 1:
				OLED_ShowNum(12,15,Myflag.h,2,12);//??
				OLED_Refresh_Gram();
				delay_ms(10);
				OLED_ShowString(12,15, "  ",12);
				break;
			case 2:
				OLED_ShowNum(12,30,Myflag.l,2,12);//??
				OLED_Refresh_Gram();
				delay_ms(10);
				OLED_ShowString(12,30, "  ",12);
				break;
		}
		OLED_Refresh_Gram();
		
		break;
	}

}
	void msgset(void)
	{u8 key1=0;
			u8 buf[8];
		key1=KEY_Matrix_Scan();
	switch(key1)
{
	case 1: break;//??????
		case 2:break;
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
		case 9: break;
		case 10:break;
		case 11:break;
		case 12:break;
		case 13://??????(S13)
		case 14:break;//??????(S14)
		case 15:Myflag.c=0;break;//??????(S15)
		case 16:Myflag.c=1;break;
				//????????????????(S16)
}
if(Myflag.c==0)
{
		buf[0]=0x00;
		buf[1]=0x00;
		buf[2]=0x00;
		buf[3]=0x00;
	buf[4]=gsmg_code[Myflag.t/100];
		buf[5]=gsmg_code[Myflag.t%100/10]|0x80;
		buf[6]=gsmg_code[Myflag.t%100%10];
		buf[7]=0x39;
	SMG_Display(buf,1);
}
else 
{
	buf[0]=gsmg_code[Myflag.l/100];
		buf[1]=gsmg_code[Myflag.l%100/10]|0x80;
		buf[2]=gsmg_code[Myflag.l%100%10];
	buf[3]=0x40;
	buf[4]=gsmg_code[Myflag.h/100];
		buf[5]=gsmg_code[Myflag.h%100/10]|0x80;
		buf[6]=gsmg_code[Myflag.h%100%10];
		buf[7]=0x39;
SMG_Display(buf,1);
}
	
	}
void Keyset(void)
{

	u8 key=0;
	key=KEY_Scan(1);
	if(key==KEY3_PRESS){
		Myflag.Timeflag++;
		if(Myflag.Timeflag>2)Myflag.Timeflag=1;
	}
	if(Myflag.Timeflag!=0){
		if(key==KEY1_PRESS|LEV_ADD){
			switch(Myflag.Timeflag){
				case 1:Myflag.h++;
					if(Myflag.h>99)Myflag.h=0;
					break;
				case 2:Myflag.l++;
					if(Myflag.l>99)Myflag.l=0;
					break;
			}
		}
		else if(key==KEY2_PRESS|LEV_MIN){
			switch(Myflag.Timeflag){
				case 1://Myflag.h--;
					if(Myflag.h<0)Myflag.h=99;
					break;
				case 2:Myflag.l--;
					if(Myflag.l<0)Myflag.l=99;
					break;
			}
		}
		else if(key==KEY4_PRESS|LEV_CLOSE){
			Myflag.Timeflag=0;
		}
	}
}


void	Keycontrol(void)
{
	if(Myflag.Timeflag==0)
	{
if(Myflag.t>Myflag.h*10)
{
Myflag.s=1;
LED1=0;
	BEEP_Alarm(100,100);
	TIM_SetCompare3(TIM4,(Myflag.t-Myflag.h*10)*1.5);
}
if(Myflag.t<Myflag.l*10)
{
Myflag.s=2;
LED2=0;
	BEEP_Alarm(100,100);
}
else{
	Myflag.s=0;
	LED2=1;
	LED1=1;
}
}


}	

void app_sys_ctrl_demo(void)
{

	u8 i=10;
//	
//	
	SysTick_Init(72);
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  //ÖжÏÓÅÏȼ¶·Ö×é·Ö2×é
	USART1_Init(115200);
	LED_Init();
	SMG_Init();
	DC_Motor_Init();
	Hwjs_Init();
	OLED_Init();
	KEY_Init();
	KEY_Matrix_Init();
	BEEP_Init();
		TIM4_CH3_PWM_Init(500,72-1);//???2Kh
	TIM_SetCompare3(TIM4,0); 
	OLED_ShowString(0,0,"DS18B20 Init...",12);
	OLED_Refresh_Gram();
	while(DS18B20_Init())
	{
		OLED_ShowString(0,0,"DS18B20 Error...",12);
		OLED_Refresh_Gram();
		printf("DS18B20¼ì²âʧ°Ü£¬Çë²åºÃ!\r\n");
		delay_ms(500);
	}
	printf("DS18B20¼ì²â³É¹¦!\r\n");
	
	
		while(i--)
		{
			Myflag.t=DS18B20_GetTemperture()*10;
		delay_ms(100);
			
		}
		 Myflag_init();
         OLED_1();
while(1)
	{	
		if(hw_jsbz==1)	//???????
		{
			hw_jsbz=0;	   //??
			printf("????? %0.8X\r\n",hw_jsm);	//??
			sys_ctrl.code=hw_jsm>>8;
			hw_jsm=0;					//?????
		}	
		
	
		sys_data_get();	
		show();
		if(Myflag.t<0)
			{
				printf("¼ì²âµÄζÈΪ£º-");
			}
			else
			{
				printf("¼ì²âµÄζÈΪ£º ");
			}
			printf("%.1f¡ãC\r\n",(float)Myflag.t/10);
			msgset();
		
		Keyset();
		Keycontrol();	

			LED0=!LED0;


	}

}

appdemo.h

#ifndef _appdemo_H
#define _appdemo_H

#include "system.h"
extern u8 buf[8];
typedef struct{
	u8 Timeflag;//??????/????/????
	int h;
	int l;
	u8 s;
	u8 c;
	int t;	//????????
}TypeFlag;
extern TypeFlag Myflag;
typedef struct
{
	int level;//??,0-5
	u8 code;//????
}_sys_ctrl;
extern _sys_ctrl sys_ctrl;
#define LEV_ADD			0X90
#define LEV_MIN			0XA8
#define LEV_CLOSE		0XE0

void app_sys_ctrl_demo(void);
#endif

main.c

int main()
{
	
app_sys_ctrl_demo();
	
}

要压缩包才能上传,明天我将完善程序,加入按键与红外(移位,改数字)等操作后上传

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值