51_LanQiaoBei/题目/模拟题/4T15届模拟4_左岚82.5/4T15届模拟4/User/main.c

217 lines
4.9 KiB
C
Raw Normal View History

2025-04-13 01:02:19 +08:00
#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>
/* ʱ<><EFBFBD><E4B7BD> */
uchar ucRtc[3] = {0x13, 0x11, 0x11}; // <20><>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>13:11:11
/* ʱ<><EFBFBD><E4B7BD> */
uint time_all_1s;
uchar time_100ms;
/* <20><>ʾ */
uchar Seg_show_mode; // 0 <20>ź<EFBFBD> 1 <20><EFBFBD> 2 <20><><EFBFBD><EFBFBD>
/* <20><><EFBFBD><EFBFBD> */
uint freq;
uint T_value_10x;
uchar T_para = 25;
uchar V_out_amp;
/* <20>ж<EFBFBD> */
bit Wring_flag;
bit Hot_flag;
bit Led_blink_show;
/* <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void Data_Proc()
{
if (time_all_1s % 500 == 0)
{
// <20>¶ȶ<C2B6>ȡ
T_value_10x = rd_temperature() * 10;
Wring_flag = (T_value_10x > T_para * 10);
Hot_flag = (T_value_10x > 300);
}
}
/* <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 == 4)
Seg_show_mode = (++Seg_show_mode) % 3;
if (Seg_show_mode == 2)
{
if (Key_Down == 9)
T_para = (T_para == 35) ? 20 : T_para + 1;
else if (Key_Down == 8)
T_para = (T_para == 20) ? 35 : T_para - 1;
}
}
/* <20><><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void Seg_Proc()
{
uchar i;
if (time_all_1s % 20)
return;
switch (Seg_show_mode)
{
case 0:
/* <20>źŽ<C5BA><C5BD><EFBFBD> */
Seg_Point[6] = 0;
Seg_Buf[0] = 11; // P
Seg_Buf[1] = 10;
Seg_Buf[2] = freq / 100000 % 10;
Seg_Buf[3] = freq / 10000 % 10;
Seg_Buf[4] = freq / 1000 % 10;
Seg_Buf[5] = freq / 100 % 10;
Seg_Buf[6] = freq / 10 % 10;
Seg_Buf[7] = freq % 10;
i = 2;
while (i < 7)
{
if (Seg_Buf[i - 1] == 10 && Seg_Buf[i] == 0)
Seg_Buf[i] = 10;
else
break;
}
break;
case 1:
/* <20>¶Ƚ<C2B6><C8BD><EFBFBD> */
Seg_Point[6] = 1;
Seg_Buf[0] = 12; // C
Seg_Buf[1] = Seg_Buf[2] = Seg_Buf[3] = Seg_Buf[4] = 10;
Seg_Buf[5] = (T_value_10x / 100 % 10 == 0) ? 10
: T_value_10x / 100 % 10;
Seg_Buf[6] = T_value_10x / 10 % 10;
Seg_Buf[7] = T_value_10x % 10;
break;
case 2:
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
Seg_Point[6] = 0;
Seg_Buf[0] = 13; // U
Seg_Buf[1] = Seg_Buf[2] = Seg_Buf[3] = Seg_Buf[4] = 10;
Seg_Buf[5] = T_para / 100 % 10;
Seg_Buf[6] = T_para / 10 % 10;
Seg_Buf[7] = T_para % 10;
i = 5;
while (i < 7)
{
if (Seg_Buf[i - 1] == 10 && Seg_Buf[i] == 0)
Seg_Buf[i] = 10;
else
break;
}
break;
}
}
/* LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void Led_Proc()
{
Da_Write(V_out_amp);
Relay(Wring_flag);
ucLed[0] = (Seg_show_mode == 0);
ucLed[1] = (Seg_show_mode == 1);
ucLed[7] = Led_blink_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>ģʽ
TMOD |= 0x05;
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>ʱ
}
void Timer1_Init(void) // 1<><31><EFBFBD><EFBFBD>@12.000MHz
{
AUXR &= 0xBF; // <20><>ʱ<EFBFBD><CAB1>ʱ<EFBFBD><CAB1>12Tģʽ
TMOD &= 0x0F; // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1>ģʽ
TL1 = 0x18; // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1>ʼֵ
TH1 = 0xFC; // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1>ʼֵ
TF1 = 0; // <20><><EFBFBD><EFBFBD>TF1<46><31>־
TR1 = 1; // <20><>ʱ<EFBFBD><CAB1>1<EFBFBD><31>ʼ<EFBFBD><CABC>ʱ
ET1 = 1; // ʹ<>ܶ<EFBFBD>ʱ<EFBFBD><CAB1>1<EFBFBD>ж<EFBFBD>
EA = 1;
}
void Timer1_Isr(void) interrupt 3
{
if (++time_all_1s == 1000)
{
time_all_1s = 0;
freq = TH0 << 8 | TL0;
if (freq > 2000)
V_out_amp = 4.5f * 51;
else if (freq < 200)
V_out_amp = 0.5f * 51;
else
V_out_amp = ((float)(freq - 200) / 450.0f + 0.5f) * 51;
TH0 = TL0 = 0;
}
if (++Seg_Pos == 8)
Seg_Pos = 0;
if (Hot_flag)
{
if (++time_100ms == 100)
{
Led_blink_show ^= 1;
time_100ms = 0;
}
}
else
{
time_100ms = 0;
Led_blink_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();
Timer1_Init();
Timer0_Init();
T_value_10x = rd_temperature() * 10;
Delay750ms();
while (1)
{
Data_Proc();
Key_Proc();
Seg_Proc();
Led_Proc();
}
}