51_LanQiaoBei/题目/真题/11 第十一届国赛_左岚/第十一届国赛/User/main.c

280 lines
7.1 KiB
C
Raw Permalink 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>ʾ */ // <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] = {16, 59, 50}; // <20><>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>16:59:50
/* ʱ<><EFBFBD><E4B7BD> */
uint time_all_1s;
uint time_light_3s;
uint time_dark_3s;
/* <20><><EFBFBD><EFBFBD> */
uchar Seg_show_mode; // 0 <20><><EFBFBD><EFBFBD> 1 <20><><EFBFBD><EFBFBD>
uchar Data_show_mode; // 0 ʱ<><CAB1> 1 <20><EFBFBD> 2 <20>ⰵ״̬
uchar Para_show_mode; // 0 ʱ<><CAB1> 1 <20><EFBFBD> 2 ָʾ<D6B8><CABE>
/* <20><><EFBFBD><EFBFBD> */
uint T_value_10x; // <20>¶ȵ<C2B6>10<31><30>
uint V_value_100x; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ100<30><30>
uchar Para_hour = 17; // Сʱ<D0A1><CAB1><EFBFBD><EFBFBD>(0-23)
uchar Para_T = 25; // <20>¶Ȳ<C2B6><C8B2><EFBFBD>(0-99)
uchar Para_Led = 3; // ָʾ<D6B8>Ʋ<EFBFBD><C6B2><EFBFBD> ʵ<><CAB5>(3-7) -> <20><>ʾ (4-8)
uchar Para_hour_temp; // <20><><EFBFBD><EFBFBD>Сʱ<D0A1><CAB1><EFBFBD><EFBFBD>(0-23)
uchar Para_T_temp; // <20><><EFBFBD><EFBFBD><EFBFBD>¶Ȳ<C2B6><C8B2><EFBFBD>(0-99)
uchar Para_Led_temp; // <20><><EFBFBD><EFBFBD>ָʾ<D6B8>Ʋ<EFBFBD><C6B2><EFBFBD> ʵ<><CAB5>(3-7) -> <20><>ʾ (4-8)
/* <20>ж<EFBFBD> */
bit dark_flag; // 0 <20><> 1 <20><>
bit cold_flag; // 0 <20><><EFBFBD><EFBFBD> 1 <20><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>
/* <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void Data_Proc() {
if (time_all_1s % 99 == 0) {
// ʱ<><CAB1><EFBFBD><EFBFBD>ȡ
Read_Rtc(ucRtc);
}
if (time_all_1s % 199 == 0) {
// AD<41><44>ȡ
V_value_100x = Ad_Read(0x01) * 100 / 51;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹС<D1B9><D0A1>1Vʱ<56><CAB1><EFBFBD>ж<EFBFBD>Ϊ<EFBFBD><CEAA>
dark_flag = (V_value_100x < 100);
}
if (time_all_1s % 499 == 0) {
// <20>¶ȶ<C2B6>ȡ
T_value_10x = rd_temperature() * 10;
cold_flag = (Para_T * 10 > T_value_10x);
}
}
/* <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) % 2;
Data_show_mode = 0;
Para_show_mode = 0;
// <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6A3AC>ȫ<EFBFBD><C8AB>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ȥ
if (Seg_show_mode == 1) {
Para_hour_temp = Para_hour;
Para_T_temp = Para_T;
Para_Led_temp = Para_Led;
}
// <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><E6A3AC>ȫ<EFBFBD><C8AB>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ȥ
else {
Para_hour = Para_hour_temp;
Para_T = Para_T_temp;
Para_Led = Para_Led_temp;
}
}
switch (Seg_show_mode) {
case 0:
/* <20><><EFBFBD><EFBFBD> */
if (Key_Down == 5) Data_show_mode = (++Data_show_mode) % 3;
break;
case 1:
/* <20><><EFBFBD><EFBFBD> */
if (Key_Down == 5) Para_show_mode = (++Para_show_mode) % 3;
switch (Para_show_mode) {
case 0:
/* ʱ<><CAB1> */
if (Key_Down == 8)
Para_hour_temp = (Para_hour_temp == 0) ? 23 : Para_hour_temp - 1;
else if (Key_Down == 9)
Para_hour_temp = (Para_hour_temp == 23) ? 0 : Para_hour_temp + 1;
break;
case 1:
/* <20><EFBFBD> */
if (Key_Down == 8)
Para_T_temp = (Para_T_temp == 0) ? 99 : Para_T_temp - 1;
else if (Key_Down == 9)
Para_T_temp = (Para_T_temp == 99) ? 0 : Para_T_temp + 1;
break;
case 2:
/* Ledָʾ<D6B8><CABE>*/
if (Key_Down == 8)
Para_Led_temp = (Para_Led_temp == 3) ? 7 : Para_Led_temp - 1;
else if (Key_Down == 9)
Para_Led_temp = (Para_Led_temp == 7) ? 3 : Para_Led_temp + 1;
break;
}
break;
}
}
/* <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:
/* <20><><EFBFBD><EFBFBD> */
switch (Data_show_mode) {
case 0:
/* ʱ<><CAB1> */
Seg_Point[2] = 0;
Seg_Point[6] = 0;
Seg_Buf[0] = ucRtc[0] / 10;
Seg_Buf[1] = ucRtc[0] % 10;
Seg_Buf[2] = 11; //-
Seg_Buf[3] = ucRtc[1] / 10;
Seg_Buf[4] = ucRtc[1] % 10;
Seg_Buf[5] = 11; //-
Seg_Buf[6] = ucRtc[2] / 10;
Seg_Buf[7] = ucRtc[2] % 10;
break;
case 1:
/* <20><EFBFBD> */
Seg_Point[2] = 0;
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;
Seg_Buf[6] = T_value_10x / 10 % 10;
Seg_Buf[7] = T_value_10x % 10;
break;
case 2:
/* <20>ⰵ״̬ */
Seg_Point[2] = 1;
Seg_Point[6] = 0;
Seg_Buf[0] = 13; // E
Seg_Buf[1] = 10;
Seg_Buf[2] = V_value_100x / 100 % 10;
Seg_Buf[3] = V_value_100x / 10 % 10;
Seg_Buf[4] = V_value_100x % 10;
Seg_Buf[5] = Seg_Buf[6] = 10;
Seg_Buf[7] = dark_flag;
break;
}
break;
case 1:
/* <20><><EFBFBD><EFBFBD> */
Seg_Point[2] = 0;
Seg_Point[6] = 0;
Seg_Buf[0] = 14; // P
Seg_Buf[1] = Para_show_mode + 1;
Seg_Buf[2] = Seg_Buf[3] = Seg_Buf[4] = Seg_Buf[5] = 10;
switch (Para_show_mode) {
case 0:
/* ʱ<><CAB1> */
Seg_Buf[6] = Para_hour_temp / 10;
Seg_Buf[7] = Para_hour_temp % 10;
break;
case 1:
/* <20><EFBFBD> */
Seg_Buf[6] = Para_T_temp / 10;
Seg_Buf[7] = Para_T_temp % 10;
break;
case 2:
/* ָʾ<D6B8><CABE> */
Seg_Buf[6] = 10;
Seg_Buf[7] = Para_Led_temp + 1;
break;
}
break;
}
}
/* LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void Led_Proc() {
uchar i;
if (Para_hour <= 8) {
// СʱС<CAB1><D0A1>8<EFBFBD><38><EFBFBD>Ҵ<EFBFBD><D2B4>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сʱ<D0A1><CAB1><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if ((ucRtc[0] < 8 && ucRtc[0] > Para_hour) ||
!(ucRtc[0] == Para_hour && ucRtc[1] == 0 && ucRtc[2] == 0))
ucLed[0] = 1;
else
ucLed[0] = 0;
} else {
// Сʱ<D0A1><CAB1><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СʱС<CAB1><D0A1>8<EFBFBD><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сʱ<D0A1><CAB1><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (ucRtc[0] < 8 || ucRtc[0] > Para_hour ||
!(ucRtc[0] == Para_hour && ucRtc[1] == 0 && ucRtc[2] == 0))
ucLed[0] = 1;
else
ucLed[0] = 0;
}
ucLed[1] = cold_flag;
ucLed[2] = (time_dark_3s >= 3000 || time_light_3s <= 3000);
for (i = 3; i < 8; i++) {
ucLed[i] = (dark_flag) ? (i == Para_Led) : 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 {
uchar i;
if (++time_all_1s == 1000) time_all_1s = 0;
Seg_Pos = (++Seg_Pos) % 8;
if (dark_flag) {
// <20><><EFBFBD>ںڰ<DABA>״̬<D7B4><CCAC>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><D2BD>ڰ<EFBFBD><DAB0><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
time_light_3s = 0;
if (++time_dark_3s >= 3000) {
time_dark_3s = 3001;
}
} else {
// <20><><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD>״̬<D7B4><CCAC>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>ֹͣ<CDA3>ڰ<EFBFBD><DAB0><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
time_dark_3s = 0;
if (++time_light_3s >= 3000) {
time_light_3s = 3001;
}
}
Seg_Disp(Seg_Pos, Seg_Buf[Seg_Pos], Seg_Point[Seg_Pos]);
for (i = 0; i < 8; i++) {
Led_Disp(i, ucLed[i]);
}
}
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();
}
}