51_LanQiaoBei/模板/蓝桥杯全模块测试例程/DS1302时钟模块/User/main.c

118 lines
2.4 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>ʾ */
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] = {0x13, 0x59, 0x50}; // <20><>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>13:59:50
/* <20><><EFBFBD>̷<EFBFBD><CCB7><EFBFBD> */
uchar Key_Slow_Down;
bit Time_ring; // <20><><EFBFBD>㱨ʱ
uint time_1s;
/* <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;
}
/* <20><><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void Seg_Proc()
{
if (Seg_Slow_Down)
return;
Seg_Slow_Down = 1;
Read_Rtc(ucRtc);
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;
}
/* LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void Led_Proc()
{
if ((ucRtc[1]==0) && (ucRtc[2]== 0))
Time_ring = 1;
Relay(Time_ring);
Beep(Time_ring);
if (Time_ring)
{
memset(ucLed, 1, 4);
memset(ucLed + 4, 0, 4);
}
else
{
memset(ucLed, 0, 4);
memset(ucLed + 4, 1, 4);
}
}
/* <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;
if (Time_ring)
{
if (++time_1s == 1000)
{
time_1s = 0;
Time_ring = 0;
}
}
else
{
time_1s = 0;
}
Seg_Disp(Seg_Pos, Seg_Buf[Seg_Pos], Seg_Point[Seg_Pos]);
Led_Disp(Seg_Pos, ucLed[Seg_Pos]);
}
void main()
{
System_Init();
Timer0_Init();
Set_Rtc(ucRtc);
while (1)
{
Key_Proc();
Seg_Proc();
Led_Proc();
}
}