#include "init.h"
#include "led.h"
#include "timer.h"
#include "seg.h"
#include "key.h"
#include "onewire.h"
#include "iic.h"
#include "stdio.h"
unsigned char ucLed; //存放灯的状态
unsigned char seg_buf[8],seg_string[9];
unsigned char pos=0;
unsigned int Seg_Slow,Key_Slow;
unsigned char Key_Down,Key_Up,Key_Old,Key_Value; //三行按键
void Led_Proc();
void Seg_Proc();
void Key_Proc();
void PCF_Proc();
unsigned char Seg_Disp_Mode=0;
unsigned char AD_Mode=0;
unsigned char tmp_param;//用于设置显示的温度参数
unsigned char tmp_param_control=25; //用于实际控制比较的温度参数
float tmp_value;
float AD_out;
void main(void)
{
All_Init();
Timer2Init();
rd_temperature();
Delay750ms();
while(1)
{
Led_Proc();
Key_Proc();
Seg_Proc();
PCF_Proc();
}
}
void t2int() interrupt 12
{
if(++Seg_Slow==500) Seg_Slow=0;
if(++Key_Slow==10) Key_Slow=0;
Seg_Disp(seg_buf,pos);
if(++pos==8) pos=0;
Led_Disp(ucLed);
}
void Key_Proc(void)
{
if(Key_Slow) return;
Key_Slow=1;
Key_Value = Read_Key();
Key_Down = Key_Value & (Key_Old ^ Key_Value);
Key_Up = ~Key_Value & (Key_Old ^ Key_Value);
Key_Old = Key_Value;
switch(Key_Down)
{
case 4:
if(++Seg_Disp_Mode == 3) Seg_Disp_Mode=0;
//设定的温度在退出参数设置时生效
if(Seg_Disp_Mode==1) tmp_param=tmp_param_control; //将实际控制数据赋值给设置变量 便于数据更改
if(Seg_Disp_Mode==2) tmp_param_control=tmp_param; //将设置数据保存到控制变量
break;
case 8:
if(Seg_Disp_Mode == 1)
{
if(--tmp_param == 255) tmp_param=0;
}
break;
case 9:
if(Seg_Disp_Mode == 1)
{
if(++tmp_param == 100) tmp_param=99;
}
break;
case 5:
AD_Mode^=1;
break;
}
}
void Seg_Proc(void)
{
if(Seg_Slow) return;
Seg_Slow=1;
tmp_value = rd_temperature()/16.0;
switch(Seg_Disp_Mode)
{
case 0:
sprintf(seg_string,"C %4.2f",tmp_value);
break;
case 1:
sprintf(seg_string,"P %02d",(unsigned int)tmp_param);
break;
case 2:
sprintf(seg_string,"A %3.2f",AD_out);
break;
}
Seg_Trans(seg_buf,seg_string);
}
void Led_Proc(void)
{
if(AD_Mode==0) ucLed |= 0X01;
else ucLed &= ~0x01;
if(Seg_Disp_Mode==0) ucLed |= 0x02;
else ucLed &= ~0x02;
if(Seg_Disp_Mode==1) ucLed |= 0x04;
else ucLed &= ~0x04;
if(Seg_Disp_Mode==2) ucLed |= 0x08;
else ucLed &= ~0x08;
}
void PCF_Proc(void)
{
if(AD_Mode==1)
{
if(tmp_value<20) AD_out=1;
else if (tmp_value>40) AD_out=4;
else AD_out=0.15*(tmp_value - 20) + 1;
}
else
{
if(tmp_value<tmp_param_control) AD_out=0;
else AD_out=5;
}
PCF8591_DAC(AD_out*51);
}
考点串写(二) 十二届省赛第一场
最新推荐文章于 2024-09-01 06:35:56 发布