#include "main.h"
uchar LED[] = {0,0,0,0,0,0,0,0};
uchar SMG[] = {16,16,16,16,16,16,16,16};
uchar dot[] = {0,0,0,0,0,0,0,0};
uchar time_now[] = {0,0,0,0,0,0,0};
uchar key_num = 0;
uint temp = 0,temp_old = 0;
uchar temp_set = 23;
uchar display_state1 = 0;
uchar mode = 0;
uchar L3_flag;
void temp_display()
{
temp_old = temp;
temp = ds18b20_read(1);
if(temp > temp_old)
{
if((temp - temp_old) > 30)
temp = temp_old;
}
else
{
if((temp_old - temp) > 30)
temp = temp_old;
}
SMG[0] = 18;
SMG[1] = 1;
SMG[2] = 16;
SMG[3] = 16;
SMG[4] = 16;
SMG[5] = temp/100;
SMG[6] = temp%100/10;
SMG[7] = temp%10;
dot[6] = 1;
}
void time_display_hour_min()
{
ds1302_read(time_now);
SMG[0] = 18;
SMG[1] = 2;
SMG[2] = 16;
SMG[3] = time_now[2]/16;
SMG[4] = time_now[2]%16;
SMG[5] = 17;
SMG[6] = time_now[1]/16;
SMG[7] = time_now[1]%16;
dot[6] = 0;
}
void time_display_min_sec()
{
ds1302_read(time_now);
SMG[0] = 18;
SMG[1] = 2;
SMG[2] = 16;
SMG[3] = time_now[1]/16;
SMG[4] = time_now[1]%16;
SMG[5] = 17;
SMG[6] = time_now[0]/16;
SMG[7] = time_now[0]%16;
dot[6] = 0;
}
void parameter()
{
SMG[0] = 18;
SMG[1] = 3;
SMG[2] = 16;
SMG[3] = 16;
SMG[4] = 16;
SMG[5] = 16;
SMG[6] = temp_set/10;
SMG[7] = temp_set%10;
dot[6] = 0;
}
void led_pro()
{
/*if(led_delay) return;
led_delay = 1;*/
if(mode == 0)
{
LED[1] = 1;
if(temp > temp_set*10)
{
reply(1);
L3_flag = 1;
}
else
{
reply(0);
L3_flag = 0;
}
}
else
{
LED[1] = 0;
if(time_now[0] == 0 && time_now[1] == 0)
reply_flag = 1;
if(reply_flag == 1)
{
reply(1);
LED[0] = 1;
L3_flag = 1;
}
else
{
reply(0);
LED[0] = 0;
L3_flag = 0;
}
}
if(L3_flag == 1 && led_flag == 0)
LED[2] = 1;
else
LED[2] = 0;
led(LED);
}
void smg_pro()
{
switch(display_state1)
{
case 0:temp_display();
break;
case 1:
{
if(s17_flag == 0)
time_display_hour_min();
else
time_display_min_sec();
}
break;
case 2:parameter();
break;
}
display(SMG,dot);
}
void key_pro()
{
key_num = key_scan();
switch(key_num)
{
case 1:mode = !mode;
break;
case 2:
{
if(display_state1 == 2)
temp_set--;
if(temp_set == 9)
temp_set = 99;
}
break;
case 3:display_state1 = (++display_state1)%3;
break;
case 4:
{
if(display_state1 == 2)
temp_set++;
if(temp_set == 100)
temp_set = 10;
}
break;
}
}
void main()
{
init_all();
ds1302_init();
temp = ds18b20_read(1);
ds1302_read(time_now);
delayus(750);
temp = ds18b20_read(1);
Timer0Init();
EA = 1;
while(1)
{
led_pro();
smg_pro();
key_pro();
}
}