main.c

#include "Timer.h"
#include "Key.h"
#include "Init.h"
#include "Led.h"
#include "Smg.h"
#include <stdio.h>
#include "iic.h"
#include "onewire.h"

//函数声明
void Key_Proc();
void Led_Proc();
void Smg_Proc();
void DAC_Proc();

//显示刷新变量
unsigned char Key_Slow;
unsigned char Led_Slow;
unsigned int Smg_Slow;
unsigned char DAC_Slow;
//Led显示变量
unsigned char ucled;

//数码管显示变量
unsigned char string[10];
unsigned char buf[8]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
unsigned char pos;

//Key变量
unsigned char Key_Old;


//模式转换变量
bit S4_mode=0;
bit S5_mode=0;

float DAC_para;
float T_para;
unsigned char Sun_para;

void Delay600ms()		//@12.000MHz
{
	unsigned char i, j, k;

	_nop_();
	_nop_();
	i = 28;
	j = 92;
	k = 196;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}


int main()
{
	Sys_Init();
	Timer1Init();
	EA=1;
	rd_temperature();
	Pcf8591_ADC(Res_Sun);
	Delay600ms();
	while(1)
	{
		DAC_Proc();
		Key_Proc();
		Led_Proc();
		Smg_Proc();
	}
}

void tm1_isr() interrupt 3
{
	if(++Key_Slow == 20) Key_Slow=0;
	if(++Led_Slow == 100) Led_Slow=0;
	if(++Smg_Slow == 500) Smg_Slow=0;
	if(++DAC_Slow == 150) DAC_Slow=0;
	
	
	
	Led_Disp(ucled);
	Smg_Disp(buf,pos);
	if(++pos == 8) pos=0;

}

void Key_Proc()
{
	unsigned char Key_Value,Key_Down;
	if(Key_Slow) return;
	Key_Slow=1;
	
	Key_Value=Read_KBD();
	Key_Down=Key_Value&(Key_Value^Key_Old);
	Key_Old=Key_Value;
	
	switch(Key_Down)
	{
		case 4:
			if(S5_mode == 0)
				S4_mode^=1; 
		break;
			
		case 5: S5_mode^=1; break;
	}
	
}

void Led_Proc()
{
	if(Led_Slow) return;
	Led_Slow=1;
	
	if(S4_mode == 0)
		ucled = ucled&0xfc|0x01;
	else
		ucled = ucled&0xfc|0x02;
}

void Smg_Proc()
{
	if(Smg_Slow) return;
	Smg_Slow=1;
	Pcf8591_DAC((unsigned char)DAC_para);

	if(S5_mode == 0)
	{
		if(S4_mode == 0)
			sprintf(string,"1    %3.1f",(unsigned int)rd_temperature()/16.0);
		else
			sprintf(string,"2    %3d",(unsigned int)Pcf8591_ADC(Res_Sun));
	}
	else
	{
		sprintf(string,"U     %2.1f",(unsigned int)DAC_para/51.0);
	}
	
	Smg_Trans(string,buf);
}

void DAC_Proc()
{
	if(DAC_Slow) return;
	DAC_Slow =1;
	
	if(S5_mode == 1)
	{
		if(S4_mode == 0)
		{
			T_para=rd_temperature()/16.0;

			if(T_para <= 10)
				DAC_para=51;
			else if(T_para >= 40)
				DAC_para=255;
			else
				DAC_para=6.8*T_para -17;
		}
		else
		{
			Sun_para=Pcf8591_ADC(Res_Sun);
			if(Sun_para <= 10)
				DAC_para=51;
			else if(Sun_para >= 240)
				DAC_para=255;
			else
				DAC_para=0.9*Sun_para+42.1;
		}
	}
	else
		DAC_para=0;
}

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐