305 lines
8.5 KiB
C
305 lines
8.5 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] = {10, 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] = {0x23, 0x59, 0x50}; // <20><>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>ʱ<EFBFBD><CAB1>23:59:50
|
|||
|
uchar alarmRtc[3] = {0x00, 0x00, 0x00}; // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>00:00:00
|
|||
|
uchar setUcRtc[3]; // ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ʮ<><CAAE><EFBFBD><EFBFBD>
|
|||
|
uchar setAlarmRtc[3]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ʮ<><CAAE><EFBFBD><EFBFBD>
|
|||
|
uchar setUcRtc_index;
|
|||
|
uchar setAlarmRtc_index;
|
|||
|
/* <20><><EFBFBD>̷<EFBFBD><CCB7><EFBFBD> */
|
|||
|
uchar Key_Slow_Down;
|
|||
|
|
|||
|
/* ʱ<>䷽<EFBFBD><E4B7BD> */
|
|||
|
uint time_all_1s;
|
|||
|
uint time_blink_1s; // 1s<31><73>˸
|
|||
|
uchar time_200ms;
|
|||
|
uint time_5s;
|
|||
|
/* <20><><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD> */
|
|||
|
uchar T_value; // <20>¶<EFBFBD>ֵ
|
|||
|
/* <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> */
|
|||
|
uchar Seg_show_mode; // 0 ʱ<><CAB1><EFBFBD><EFBFBD>ʾ 1 ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3 <20>¶<EFBFBD><C2B6><EFBFBD>ʾ
|
|||
|
/* <20>ж<EFBFBD> */
|
|||
|
bit Seg_blink_flag; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8>־
|
|||
|
bit Led_blink_flag; // LED<45><44>˸<EFBFBD><CBB8>־
|
|||
|
bit ring_flag; // <20><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
/* <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Data_Proc()
|
|||
|
{
|
|||
|
if (time_all_1s % 500 == 0)
|
|||
|
{
|
|||
|
// ʱ<><CAB1><EFBFBD><EFBFBD>ȡ
|
|||
|
Read_Rtc(ucRtc);
|
|||
|
if (ucRtc[0] == alarmRtc[0] && ucRtc[1] == alarmRtc[1] && ucRtc[2] == alarmRtc[2])
|
|||
|
// <20><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD>
|
|||
|
ring_flag = 1;
|
|||
|
}
|
|||
|
if (time_all_1s % 500 == 0)
|
|||
|
{
|
|||
|
// <20>¶ȶ<C2B6>ȡ
|
|||
|
T_value = rd_temperature();
|
|||
|
}
|
|||
|
}
|
|||
|
/* <20><><EFBFBD>̴<EFBFBD><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Key_Proc()
|
|||
|
{
|
|||
|
static uchar Key_Val, Key_Down, Key_Up, Key_Old;
|
|||
|
uchar i;
|
|||
|
if (time_all_1s % 10)
|
|||
|
return;
|
|||
|
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 (Seg_show_mode)
|
|||
|
{
|
|||
|
case 0:
|
|||
|
if (Key_Down == 7)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
for (i = 0; i < 3; i++)
|
|||
|
{
|
|||
|
setUcRtc[i] = ucRtc[i] / 16 * 10 + ucRtc[i] % 16;
|
|||
|
}
|
|||
|
Seg_show_mode = 1;
|
|||
|
}
|
|||
|
else if (Key_Down == 6)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
for (i = 0; i < 3; i++)
|
|||
|
{
|
|||
|
setAlarmRtc[i] = alarmRtc[i] / 16 * 10 + alarmRtc[i] % 16;
|
|||
|
}
|
|||
|
Seg_show_mode = 2;
|
|||
|
}
|
|||
|
if (Key_Old == 4)
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD><C2B6><EFBFBD>ʾ
|
|||
|
Seg_show_mode = 3;
|
|||
|
break;
|
|||
|
|
|||
|
case 1:
|
|||
|
if (Key_Down == 7)
|
|||
|
setUcRtc_index++;
|
|||
|
if (setUcRtc_index >= 3)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʾ
|
|||
|
Seg_show_mode = 0;
|
|||
|
setUcRtc_index = 0;
|
|||
|
for (i = 0; i < 3; i++)
|
|||
|
ucRtc[i] = setUcRtc[i] / 10 << 4 | setUcRtc[i] % 10;
|
|||
|
Set_Rtc(ucRtc);
|
|||
|
}
|
|||
|
if (Key_Down == 5)
|
|||
|
{
|
|||
|
if (setUcRtc_index == 0)
|
|||
|
// <20><EFBFBD>Сʱ
|
|||
|
setUcRtc[setUcRtc_index] = (setUcRtc[setUcRtc_index] >= 24) ? 24
|
|||
|
: setUcRtc[setUcRtc_index] + 1;
|
|||
|
else
|
|||
|
// <20>ķ<DEB8><C4B7><EFBFBD>
|
|||
|
setUcRtc[setUcRtc_index] = (setUcRtc[setUcRtc_index] >= 60) ? 60
|
|||
|
: setUcRtc[setUcRtc_index] + 1;
|
|||
|
}
|
|||
|
else if (Key_Down == 4)
|
|||
|
// <20><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
setUcRtc[setUcRtc_index] = (setUcRtc[setUcRtc_index] == 0) ? 0
|
|||
|
: setUcRtc[setUcRtc_index] - 1;
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
if (Key_Down == 6)
|
|||
|
setAlarmRtc_index++;
|
|||
|
if (setAlarmRtc_index >= 3)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʾ
|
|||
|
Seg_show_mode = 0;
|
|||
|
setAlarmRtc_index = 0;
|
|||
|
for (i = 0; i < 3; i++)
|
|||
|
alarmRtc[i] = setAlarmRtc[i] / 10 << 4 | setAlarmRtc[i] % 10;
|
|||
|
}
|
|||
|
if (Key_Down == 5)
|
|||
|
{
|
|||
|
if (setAlarmRtc_index == 0)
|
|||
|
// <20><EFBFBD>Сʱ
|
|||
|
setAlarmRtc[setAlarmRtc_index] = (setAlarmRtc[setAlarmRtc_index] >= 24) ? 24
|
|||
|
: setAlarmRtc[setAlarmRtc_index] + 1;
|
|||
|
else
|
|||
|
// <20>ķ<DEB8><C4B7><EFBFBD>
|
|||
|
setAlarmRtc[setUcRtc_index] = (setAlarmRtc[setUcRtc_index] >= 60) ? 60
|
|||
|
: setAlarmRtc[setAlarmRtc_index] + 1;
|
|||
|
}
|
|||
|
else if (Key_Down == 4)
|
|||
|
// <20><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
setAlarmRtc[setUcRtc_index] = (setAlarmRtc[setAlarmRtc_index] == 0) ? 0
|
|||
|
: setAlarmRtc[setAlarmRtc_index] - 1;
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
if (Key_Up == 4)
|
|||
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʾ
|
|||
|
Seg_show_mode = 0;
|
|||
|
break;
|
|||
|
}
|
|||
|
if (ring_flag && (Key_Down != 0))
|
|||
|
ring_flag = 0;
|
|||
|
}
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Seg_Proc()
|
|||
|
{
|
|||
|
if (time_all_1s % 20)
|
|||
|
return;
|
|||
|
switch (Seg_show_mode)
|
|||
|
{
|
|||
|
case 0:
|
|||
|
/* ʱ<><CAB1><EFBFBD><EFBFBD>ʾ */
|
|||
|
Seg_Buf[0] = ucRtc[0] / 16;
|
|||
|
Seg_Buf[1] = ucRtc[0] % 16;
|
|||
|
Seg_Buf[2] = 11; //-
|
|||
|
Seg_Buf[3] = ucRtc[1] / 16;
|
|||
|
Seg_Buf[4] = ucRtc[1] % 16;
|
|||
|
Seg_Buf[5] = 11; //-
|
|||
|
Seg_Buf[6] = ucRtc[2] / 16;
|
|||
|
Seg_Buf[7] = ucRtc[2] % 16;
|
|||
|
break;
|
|||
|
|
|||
|
case 1:
|
|||
|
/* ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
Seg_Buf[0] = setUcRtc[0] / 10;
|
|||
|
Seg_Buf[1] = setUcRtc[0] % 10;
|
|||
|
Seg_Buf[2] = 11; //-
|
|||
|
Seg_Buf[3] = setUcRtc[1] / 10;
|
|||
|
Seg_Buf[4] = setUcRtc[1] % 10;
|
|||
|
Seg_Buf[5] = 11; //-
|
|||
|
Seg_Buf[6] = setUcRtc[2] / 10;
|
|||
|
Seg_Buf[7] = setUcRtc[2] % 10;
|
|||
|
Seg_Buf[setUcRtc_index * 3] = Seg_blink_flag ? 10
|
|||
|
: Seg_Buf[setUcRtc_index * 3];
|
|||
|
Seg_Buf[setUcRtc_index * 3 + 1] = Seg_blink_flag ? 10
|
|||
|
: Seg_Buf[setUcRtc_index * 3 + 1];
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
Seg_Buf[0] = setAlarmRtc[0] / 10;
|
|||
|
Seg_Buf[1] = setAlarmRtc[0] % 10;
|
|||
|
Seg_Buf[2] = 11; //-
|
|||
|
Seg_Buf[3] = setAlarmRtc[1] / 10;
|
|||
|
Seg_Buf[4] = setAlarmRtc[1] % 10;
|
|||
|
Seg_Buf[5] = 11; //-
|
|||
|
Seg_Buf[6] = setAlarmRtc[2] / 10;
|
|||
|
Seg_Buf[7] = setAlarmRtc[2] % 10;
|
|||
|
Seg_Buf[setAlarmRtc_index * 3] = Seg_blink_flag ? 10
|
|||
|
: Seg_Buf[setAlarmRtc_index * 3];
|
|||
|
Seg_Buf[setAlarmRtc_index * 3 + 1] = Seg_blink_flag ? 10
|
|||
|
: Seg_Buf[setAlarmRtc_index * 3 + 1];
|
|||
|
break;
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
/* <20>¶<EFBFBD><C2B6><EFBFBD>ʾ */
|
|||
|
memset(Seg_Buf, 10, 5);
|
|||
|
Seg_Buf[5] = T_value / 10;
|
|||
|
Seg_Buf[6] = T_value % 10;
|
|||
|
Seg_Buf[7] = 12; // C
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/* LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Led_Proc()
|
|||
|
{
|
|||
|
ucLed[0] = Led_blink_flag;
|
|||
|
}
|
|||
|
|
|||
|
/* <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 (++time_all_1s == 1000)
|
|||
|
time_all_1s = 0;
|
|||
|
if (++Seg_Pos == 8)
|
|||
|
Seg_Pos = 0;
|
|||
|
if (Seg_show_mode == 1 || Seg_show_mode == 2)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>м<EFBFBD>ʱ
|
|||
|
if (++time_blink_1s == 1000)
|
|||
|
{
|
|||
|
// 1s<31><73>˸
|
|||
|
time_blink_1s = 0;
|
|||
|
Seg_blink_flag ^= 1;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD>м<EFBFBD>ʱ
|
|||
|
time_blink_1s = 0;
|
|||
|
Seg_blink_flag = 0;
|
|||
|
}
|
|||
|
if (ring_flag)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ʼ<EFBFBD><CABC>ʱ
|
|||
|
if (++time_200ms == 200)
|
|||
|
Led_blink_flag ^= 1;
|
|||
|
if (++time_5s == 5000)
|
|||
|
ring_flag = 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// <20><>ֹ<EFBFBD><D6B9>Ϊ<EFBFBD><CEAA><EFBFBD>°<EFBFBD><C2B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6>μ<EFBFBD>ʱ<EFBFBD><CAB1>bug
|
|||
|
Led_blink_flag = 0;
|
|||
|
time_5s = 0;
|
|||
|
time_200ms = 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);
|
|||
|
rd_temperature();
|
|||
|
Delay750ms();
|
|||
|
while (1)
|
|||
|
{
|
|||
|
Data_Proc();
|
|||
|
Key_Proc();
|
|||
|
Seg_Proc();
|
|||
|
Led_Proc();
|
|||
|
}
|
|||
|
}
|