一、题目




二、代码实现
1.main.c
#include <STC15F2K60S2.H>
#include "intrins.h"
#include "onewire.h"
#include "iic.h"
#include "Led.h"
#include "Key.h"
/*****************************************************************/
/*****************************************************************/
//1.遇到离谱问题时请重新创建工程(上个工程中按键程序都写了break,还会执行到其他按键的功能)
//2.L1老是闪烁,其他地方也没有更改L1的值
//2.已解决:因为初始把温度读取函数放在LED处理函数中,读取速度过快,导致数据不太稳定
unsigned char Seg_slow_down,Key_slow_down; //按键、数码管减速变量
unsigned char Key_down,Key_up,Key_old,Key_val; //按键读取变量
unsigned char Seg_pos; //数码管扫描变量
unsigned char Seg_buff[8] = {10,10,10,10,10,10,10,10};
unsigned char Seg_point_buff[8] = {0,0,0,0,0,0,0,0};
unsigned char Led_buff[8] = {0,0,0,0,0,0,0,0};
unsigned int wendu_dsp = 25; //温度显示变量
unsigned char Seg_mode = 0; //数码管模式变量:0--数据界面;1--参数界面
unsigned char temp_buff[2] = {30,20}; //参数显示变量
unsigned char temp_buff_control[2] = {30,20}; //参数控制变量
bit temp_or = 1; //参数数组索引变量
bit flag_canshu = 0; //参数改变标志位,如果参数改变则显示改变的参数值
float DS18B20_Read_T();
void PCF8591_DAC(unsigned char dat);
void Key_pro()
{
if(Key_slow_down) return;
Key_slow_down = 1;
Key_val = Key_Read();
Key_down = Key_val & (Key_old ^ Key_val);
Key_up = ~Key_val & (Key_old ^ Key_val);
Key_old = Key_val;
switch(Key_down)
{
case 4: //界面切换
if(++Seg_mode == 2) Seg_mode = 0;
flag_canshu = 0;
if(Seg_mode == 1){
temp_or = 1;
temp_buff_control[0] = temp_buff[0];
temp_buff_control[1] = temp_buff[1];
}
else
{ if(temp_buff_control[0] >= temp_buff_control[1]){ //参数合理性验证
temp_buff[0] = temp_buff_control[0];
temp_buff[1] = temp_buff_control[1];
Led_bu