128 lines
2.9 KiB
C
128 lines
2.9 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>
|
|||
|
|
|||
|
/* <20><><EFBFBD>̷<EFBFBD><CCB7><EFBFBD> */
|
|||
|
uchar Key_Slow_Down;
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD> */
|
|||
|
uint temperature_value_10x; // <20>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
bit C_F_flag; // <20><><EFBFBD>϶<EFBFBD>ת<EFBFBD><D7AA><EFBFBD>϶<EFBFBD>
|
|||
|
|
|||
|
#define N 10
|
|||
|
uint data_array[N]; // <20><><EFBFBD>ڴ<EFBFBD>С
|
|||
|
uint sum_temp; // <20>ܺ<EFBFBD>
|
|||
|
uchar index_temp; // <20><><EFBFBD><EFBFBD>
|
|||
|
uchar arr_count; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
uint filter(uint new_data)
|
|||
|
{
|
|||
|
sum_temp -= data_array[index_temp];
|
|||
|
data_array[index_temp] = new_data;
|
|||
|
sum_temp += data_array[index_temp];
|
|||
|
index_temp = (++index_temp) % N; // <20><>֤index_temp<6D><70>0~N-1֮<31><D6AE><EFBFBD><EFBFBD>ת
|
|||
|
arr_count = (++arr_count == N + 1) ? N : arr_count; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>Ԫ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>
|
|||
|
return sum_temp / arr_count;
|
|||
|
}
|
|||
|
|
|||
|
/* <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 == 4)
|
|||
|
C_F_flag ^= 1;
|
|||
|
}
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Seg_Proc()
|
|||
|
{
|
|||
|
if (Seg_Slow_Down)
|
|||
|
return;
|
|||
|
Seg_Slow_Down = 1;
|
|||
|
temperature_value_10x = filter(rd_temperature() * 10);
|
|||
|
if (C_F_flag)
|
|||
|
temperature_value_10x = temperature_value_10x * 1.8 + 320; // <20><><EFBFBD>϶<EFBFBD>
|
|||
|
Seg_Buf[0] = temperature_value_10x / 1000 % 10;
|
|||
|
Seg_Buf[1] = temperature_value_10x / 100 % 10;
|
|||
|
Seg_Buf[2] = temperature_value_10x / 10 % 10;
|
|||
|
Seg_Buf[3] = temperature_value_10x % 10;
|
|||
|
Seg_Buf[4] = (C_F_flag) ? 12 : 11;
|
|||
|
Seg_Point[2] = 1;
|
|||
|
}
|
|||
|
|
|||
|
/* LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Led_Proc()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
/* <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;
|
|||
|
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();
|
|||
|
rd_temperature();
|
|||
|
Delay750ms();
|
|||
|
while (1)
|
|||
|
{
|
|||
|
Key_Proc();
|
|||
|
Seg_Proc();
|
|||
|
Led_Proc();
|
|||
|
}
|
|||
|
}
|