229 lines
5.3 KiB
C
229 lines
5.3 KiB
C
|
#include "main.h"
|
|||
|
/* LED<45><44>ʾ */
|
|||
|
uchar ucLed[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ */
|
|||
|
uchar Seg_Slow_Down; // <20><><EFBFBD><EFBFBD><EFBFBD>ܼ<EFBFBD><DCBC><EFBFBD>
|
|||
|
uchar Seg_Buf[8] = {5, 10, 10, 10, 10, 10, 10, 10}; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ֵ
|
|||
|
uchar Seg_Pos; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָʾ
|
|||
|
uchar Seg_Point[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // ijλ<C4B3>Ƿ<EFBFBD><C7B7><EFBFBD>ʾС<CABE><D0A1><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
/* ʱ<>䷽<EFBFBD><E4B7BD> */
|
|||
|
uchar ucRtc[3] = {0x13, 0x11, 0x11}; // <20><>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>13:11:11
|
|||
|
|
|||
|
/* <20><><EFBFBD>̷<EFBFBD><CCB7><EFBFBD> */
|
|||
|
uchar Key_Slow_Down;
|
|||
|
|
|||
|
/* <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
uchar Seg_show_mode; // 0 <20>¶<EFBFBD> 1 ʱ<><CAB1> 2 <20><><EFBFBD><EFBFBD>
|
|||
|
bit Control_mode; // <20><><EFBFBD><EFBFBD>ģʽ 0 <20>¶<EFBFBD> 1 ʱ<><CAB1>
|
|||
|
bit Time_show_mode; // ʱ<><CAB1><EFBFBD><EFBFBD>ʾģʽ 0 ʱ<><CAB1> 1 <20><><EFBFBD><EFBFBD>
|
|||
|
bit Temperature_mode; // <20>¶ȿ<C2B6><C8BF>Ƶ<EFBFBD><C6B5><EFBFBD>
|
|||
|
bit Time_mode; // ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>
|
|||
|
bit Time_Led; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
bit Led_show; // <20><>˸
|
|||
|
/* <20><><EFBFBD><EFBFBD> */
|
|||
|
uint Temperature_value_10x; // <20>¶Ȳ<C2B6><C8B2><EFBFBD>ֵ 10<31><30>
|
|||
|
uchar Temperature_para = 23; // <20>¶Ȳ<C2B6><C8B2><EFBFBD>
|
|||
|
|
|||
|
/* ʱ<><CAB1> */
|
|||
|
uint time_5s;
|
|||
|
uint time_5s_led;
|
|||
|
uchar time_100ms;
|
|||
|
|
|||
|
/* <20><><EFBFBD>̴<EFBFBD><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Key_Proc()
|
|||
|
{
|
|||
|
static uchar Key_Val, Key_Down, Key_Up, Key_Old;
|
|||
|
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;
|
|||
|
if (Key_Down == 12)
|
|||
|
Seg_show_mode = (++Seg_show_mode) % 3;
|
|||
|
if (Key_Down == 13)
|
|||
|
Control_mode ^= 1;
|
|||
|
if (Seg_show_mode == 2)
|
|||
|
{
|
|||
|
if (Key_Down == 16)
|
|||
|
Temperature_para = (++Temperature_para > 99) ? 99 : Temperature_para;
|
|||
|
if (Key_Down == 17)
|
|||
|
Temperature_para = (--Temperature_para < 10) ? 10 : Temperature_para;
|
|||
|
}
|
|||
|
if (Seg_show_mode == 2)
|
|||
|
{
|
|||
|
if (Key_Old == 17)
|
|||
|
Time_show_mode = 1;
|
|||
|
if (Key_Up == 17)
|
|||
|
Time_show_mode = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Seg_Proc()
|
|||
|
{
|
|||
|
if (Seg_Slow_Down)
|
|||
|
return;
|
|||
|
Seg_Slow_Down = 1;
|
|||
|
Seg_Buf[0] = 11; // U
|
|||
|
Seg_Buf[1] = Seg_show_mode + 1;
|
|||
|
Read_Rtc(ucRtc);
|
|||
|
Temperature_value_10x = rd_temperature() * 10;
|
|||
|
switch (Seg_show_mode)
|
|||
|
{
|
|||
|
case 0:
|
|||
|
/* <20>¶<EFBFBD> */
|
|||
|
Seg_Buf[2] = Seg_Buf[3] = Seg_Buf[4] = 10;
|
|||
|
Seg_Buf[5] = Temperature_value_10x / 100 % 10;
|
|||
|
Seg_Buf[6] = Temperature_value_10x / 10 % 10;
|
|||
|
Seg_Buf[7] = Temperature_value_10x % 10;
|
|||
|
Seg_Point[6] = 1;
|
|||
|
break;
|
|||
|
case 1:
|
|||
|
/* ʱ<><CAB1> */
|
|||
|
|
|||
|
Seg_Buf[2] = 10;
|
|||
|
Seg_Buf[3] = Time_show_mode ? ucRtc[1] / 16 : ucRtc[0] / 16;
|
|||
|
Seg_Buf[4] = Time_show_mode ? ucRtc[1] % 16 : ucRtc[0] % 16;
|
|||
|
Seg_Buf[5] = 12; //-
|
|||
|
Seg_Buf[6] = Time_show_mode ? ucRtc[2] / 16 : ucRtc[1] / 16;
|
|||
|
Seg_Buf[7] = Time_show_mode ? ucRtc[2] % 16 : ucRtc[1] % 16;
|
|||
|
Seg_Point[6] = 0;
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
/* <20><><EFBFBD><EFBFBD> */
|
|||
|
Seg_Buf[2] = Seg_Buf[3] = Seg_Buf[4] = Seg_Buf[5] = 10;
|
|||
|
Seg_Buf[6] = Temperature_para / 10 % 10;
|
|||
|
Seg_Buf[7] = Temperature_para % 10;
|
|||
|
Seg_Point[6] = 0;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/* LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Led_Proc()
|
|||
|
{
|
|||
|
// ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (Control_mode)
|
|||
|
{
|
|||
|
Temperature_mode = 0; // <20>ر<EFBFBD><D8B1>¶ȱ<C2B6><C8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻȻ<CDBB>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>bug
|
|||
|
// <20><><EFBFBD>ֺ<EFBFBD><D6BA><EFBFBD>ͬʱ<CDAC><CAB1>0x00<30><30>ʱ<EFBFBD><CAB1>
|
|||
|
if ((ucRtc[1] || ucRtc[2]) == 0)
|
|||
|
Time_mode = 1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
}
|
|||
|
// <20>¶ȿ<C2B6><C8BF><EFBFBD>
|
|||
|
else
|
|||
|
{
|
|||
|
Time_mode = 0; // <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻȻ<CDBB>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>bug
|
|||
|
if (Temperature_value_10x >= Temperature_para * 10)
|
|||
|
Temperature_mode = 1; // <20>¶ȱ<C2B6><C8B1><EFBFBD>
|
|||
|
else
|
|||
|
Temperature_mode = 0; // <20>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
Relay(Temperature_mode || Time_mode); // <20><><EFBFBD><EFBFBD><EFBFBD>¶ȱ<C2B6><C8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
// <20><><EFBFBD>ֺ<EFBFBD><D6BA><EFBFBD>ͬʱ<CDAC><CAB1>0x00<30><30>ʱ<EFBFBD><CAB1>
|
|||
|
if ((ucRtc[1] || ucRtc[2]) == 0)
|
|||
|
Time_Led = 1;
|
|||
|
ucLed[0] = Time_Led; // LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5s
|
|||
|
ucLed[1] = (Control_mode == 0);
|
|||
|
ucLed[2] = Led_show;
|
|||
|
}
|
|||
|
|
|||
|
/* <20><>ʱ<EFBFBD><CAB1>0<EFBFBD>жϳ<D0B6>ʼ<EFBFBD><CABC> */
|
|||
|
void Timer0_Init(void) // 1<><31><EFBFBD><EFBFBD>@12.000MHz
|
|||
|
{
|
|||
|
AUXR &= 0x7F; // <20><>ʱ<EFBFBD><CAB1>ʱ<EFBFBD><CAB1>12Tģʽ
|
|||
|
TMOD &= 0xF0; // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1>ģʽ
|
|||
|
TL0 = 0x18; // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1>ʼֵ
|
|||
|
TH0 = 0xFC; // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1>ʼֵ
|
|||
|
TF0 = 0; // <20><><EFBFBD><EFBFBD>TF0<46><30>־
|
|||
|
TR0 = 1; // <20><>ʱ<EFBFBD><CAB1>0<EFBFBD><30>ʼ<EFBFBD><CABC>ʱ
|
|||
|
ET0 = 1;
|
|||
|
EA = 1;
|
|||
|
}
|
|||
|
|
|||
|
/* <20><>ʱ<EFBFBD><CAB1>0<EFBFBD>жϺ<D0B6><CFBA><EFBFBD> */
|
|||
|
void Timer0_ISR(void) interrupt 1
|
|||
|
{
|
|||
|
if (++Key_Slow_Down == 10)
|
|||
|
Key_Slow_Down = 0;
|
|||
|
if (++Seg_Slow_Down == 500)
|
|||
|
Seg_Slow_Down = 0;
|
|||
|
if (++Seg_Pos == 8)
|
|||
|
Seg_Pos = 0;
|
|||
|
if (Time_mode)
|
|||
|
{
|
|||
|
if (++time_5s == 5000)
|
|||
|
{
|
|||
|
time_5s = 0;
|
|||
|
Time_mode = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
// <20><>ʱ<EFBFBD><CAB1>û<EFBFBD>п<EFBFBD><D0BF>Ƶ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ϊ0
|
|||
|
else
|
|||
|
{
|
|||
|
time_5s = 0;
|
|||
|
}
|
|||
|
|
|||
|
if (Time_Led)
|
|||
|
{
|
|||
|
if (++time_5s_led == 5000)
|
|||
|
{
|
|||
|
time_5s_led = 0;
|
|||
|
Time_mode = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (Temperature_mode || Time_mode)
|
|||
|
{
|
|||
|
if (++time_100ms == 100)
|
|||
|
{
|
|||
|
time_100ms = 0;
|
|||
|
Led_show ^= 1;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
time_100ms = 0;
|
|||
|
Led_show = 0;
|
|||
|
}
|
|||
|
Seg_Disp(Seg_Pos, Seg_Buf[Seg_Pos], Seg_Point[Seg_Pos]);
|
|||
|
Led_Disp(Seg_Pos, ucLed[Seg_Pos]);
|
|||
|
}
|
|||
|
|
|||
|
void Delay750ms(void) //@12.000MHz
|
|||
|
{
|
|||
|
unsigned char data i, j, k;
|
|||
|
|
|||
|
_nop_();
|
|||
|
_nop_();
|
|||
|
i = 35;
|
|||
|
j = 51;
|
|||
|
k = 182;
|
|||
|
do
|
|||
|
{
|
|||
|
do
|
|||
|
{
|
|||
|
while (--k)
|
|||
|
;
|
|||
|
} while (--j);
|
|||
|
} while (--i);
|
|||
|
}
|
|||
|
void main()
|
|||
|
{
|
|||
|
System_Init();
|
|||
|
Timer0_Init();
|
|||
|
Set_Rtc(ucRtc);
|
|||
|
Delay750ms();
|
|||
|
rd_temperature();
|
|||
|
while (1)
|
|||
|
{
|
|||
|
Key_Proc();
|
|||
|
Seg_Proc();
|
|||
|
Led_Proc();
|
|||
|
}
|
|||
|
}
|