205 lines
4.3 KiB
C
205 lines
4.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_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><DAB7><EFBFBD> */
|
|||
|
uchar Uart_Slow_Down;
|
|||
|
uchar Uart_Buf[3]; // <20><><EFBFBD>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
uchar Uart_Rx_Index; // <20><><EFBFBD>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
|
|||
|
/* ʱ<>䷽<EFBFBD><E4B7BD> */
|
|||
|
uint time_all_1s;
|
|||
|
uchar time_100ms;
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD> */
|
|||
|
uchar Seg_show_mode; // 0 <20>¶<EFBFBD><C2B6><EFBFBD>ʾ 1 <20><>ѹ<EFBFBD><D1B9>ʾ
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD> */
|
|||
|
uint T_value_10x; // 10<31><30><EFBFBD>¶<EFBFBD>ֵ
|
|||
|
uint V_value_100x; // 100<30><30><EFBFBD><EFBFBD>ѹֵ
|
|||
|
|
|||
|
/* <20>ж<EFBFBD> */
|
|||
|
bit Data_send_flag; // <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD>Ӧ<EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
bit Lock_uart_change; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD>湦<EFBFBD><E6B9A6><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
bit Led_blink_flag; // <20><>˸<EFBFBD><CBB8>־
|
|||
|
|
|||
|
/* <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Data_Proc()
|
|||
|
{
|
|||
|
if (time_all_1s % 100 == 0)
|
|||
|
{
|
|||
|
// AD<41><44>ȡ
|
|||
|
V_value_100x = (float)Ad_Read(0x03) / 51.0 * 100;
|
|||
|
}
|
|||
|
if (time_all_1s % 500 == 0)
|
|||
|
{
|
|||
|
// <20>¶ȶ<C2B6>ȡ
|
|||
|
T_value_10x = rd_temperature() * 10;
|
|||
|
}
|
|||
|
}
|
|||
|
/* <20><><EFBFBD>̴<EFBFBD><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Key_Proc()
|
|||
|
{
|
|||
|
static uchar Key_Val, Key_Down, Key_Up, Key_Old;
|
|||
|
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;
|
|||
|
if (Key_Down == 12)
|
|||
|
Data_send_flag = 1;
|
|||
|
if (Key_Down == 4)
|
|||
|
Lock_uart_change = 1;
|
|||
|
if (Lock_uart_change && Key_Down == 5)
|
|||
|
Lock_uart_change = 0;
|
|||
|
}
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Seg_Proc()
|
|||
|
{
|
|||
|
if (time_all_1s % 20)
|
|||
|
return;
|
|||
|
Seg_Buf[0] = 11; // U
|
|||
|
Seg_Buf[1] = Seg_show_mode + 1;
|
|||
|
Seg_Buf[2] = Seg_Buf[3] = Seg_Buf[4] = 10;
|
|||
|
if (Seg_show_mode == 0)
|
|||
|
{
|
|||
|
Seg_Point[5] = 0;
|
|||
|
Seg_Point[6] = 1;
|
|||
|
Seg_Buf[5] = T_value_10x / 100 % 10;
|
|||
|
Seg_Buf[6] = T_value_10x / 10 % 10;
|
|||
|
Seg_Buf[7] = T_value_10x % 10;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Seg_Point[5] = 1;
|
|||
|
Seg_Point[6] = 0;
|
|||
|
Seg_Buf[5] = V_value_100x / 100 % 10;
|
|||
|
Seg_Buf[6] = V_value_100x / 10 % 10;
|
|||
|
Seg_Buf[7] = V_value_100x % 10;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/* LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Led_Proc()
|
|||
|
{
|
|||
|
ucLed[0] = (Seg_show_mode == 0);
|
|||
|
ucLed[1] = (Seg_show_mode == 1);
|
|||
|
ucLed[2] = Led_blink_flag;
|
|||
|
Relay(T_value_10x >= 280);
|
|||
|
Beep(V_value_100x > 360);
|
|||
|
}
|
|||
|
|
|||
|
/* <20><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Uart_Proc()
|
|||
|
{
|
|||
|
if (time_all_1s % 200)
|
|||
|
return;
|
|||
|
if (Data_send_flag)
|
|||
|
{
|
|||
|
Data_send_flag = 0;
|
|||
|
if (Seg_show_mode == 0)
|
|||
|
printf("TEMP:%0.1f<EFBFBD><EFBFBD>", (float)T_value_10x / 10.0);
|
|||
|
else
|
|||
|
printf("Voltage:%0.2fV", (float)V_value_100x / 100.0);
|
|||
|
}
|
|||
|
if (Lock_uart_change == 0)
|
|||
|
{
|
|||
|
// δ<><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (Uart_Buf[0] == 'A')
|
|||
|
Seg_show_mode = 0;
|
|||
|
if (Uart_Buf[0] == 'B')
|
|||
|
Seg_show_mode = 1;
|
|||
|
memset(Uart_Buf, 0, 3);
|
|||
|
Uart_Rx_Index = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/* <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 (Lock_uart_change)
|
|||
|
{
|
|||
|
if (++time_100ms == 100)
|
|||
|
{
|
|||
|
time_100ms = 0;
|
|||
|
Led_blink_flag ^= 1;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
time_100ms = 0;
|
|||
|
Led_blink_flag = 0;
|
|||
|
}
|
|||
|
Seg_Disp(Seg_Pos, Seg_Buf[Seg_Pos], Seg_Point[Seg_Pos]);
|
|||
|
Led_Disp(Seg_Pos, ucLed[Seg_Pos]);
|
|||
|
}
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void Uart_ISR(void) interrupt 4
|
|||
|
{
|
|||
|
if (RI == 1) // <20><><EFBFBD>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
Uart_Buf[Uart_Rx_Index] = SBUF;
|
|||
|
Uart_Rx_Index++;
|
|||
|
RI = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
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();
|
|||
|
Uart1_Init();
|
|||
|
rd_temperature();
|
|||
|
Delay750ms();
|
|||
|
T_value_10x = rd_temperature() * 10;
|
|||
|
Delay750ms();
|
|||
|
while (1)
|
|||
|
{
|
|||
|
Key_Proc();
|
|||
|
Data_Proc();
|
|||
|
Seg_Proc();
|
|||
|
Uart_Proc();
|
|||
|
Led_Proc();
|
|||
|
}
|
|||
|
}
|