STM32CubeMX-Keil_uVision5/FinalHomework/Core/Src/SegLed.c
423A35C7 2fb33e955c 期末大作业-增加了显示时间、设置时间的功能,已基本完成功能。
设置时间的功能使用Cursor生成。

为了减少误差,专门调整了时钟周期。
2025-01-07 21:01:38 +08:00

92 lines
1.7 KiB
C

#include "main.h"
#include "variable.h"
extern uint8_t is_setting_time;
extern TIME_STATE set_time_state;
extern uint8_t show_digit;
uint16_t display_tab[] = {
0x3f,
0x06,
0x5b,
0x4f,
0x66,
0x6d,
0x7d,
0x07,
0x7f,
0x6f,
0x77,
0x7c,
0x39,
0x5e,
0x79,
0x71,
0x40,
0x00
};
uint8_t DispBuff[8];
uint16_t PosSel = 0;
static void DisplayOneLed(uint8_t dat, uint8_t pos, uint8_t dot) {
uint16_t temp;
if (is_setting_time && !show_digit) {
switch (set_time_state) {
case SET_HOUR_TENS:
if (pos == 0) dat = 17;
break;
case SET_HOUR_ONES:
if (pos == 1) dat = 17;
break;
case SET_MIN_TENS:
if (pos == 3) dat = 17;
break;
case SET_MIN_ONES:
if (pos == 4) dat = 17;
break;
case SET_SEC_TENS:
if (pos == 6) dat = 17;
break;
case SET_SEC_ONES:
if (pos == 7) dat = 17;
break;
default:
break;
}
}
temp = display_tab[dat];
if (dot)
temp |= 0x80;
SegLedData_GPIO_Port->ODR &= 0xFF00;
SegLedData_GPIO_Port->ODR |= temp; // 段码
AddrA_GPIO_Port->ODR &= 0xFFF0;
AddrA_GPIO_Port->ODR |= pos; // 位码
}
void Display(void) {
static uint8_t mPos = 0;
DisplayOneLed(DispBuff[mPos], mPos, 0);
if (++mPos >= 8) mPos = 0;
}
void TimeToBuff(structTime *nstTime) {
DispBuff[0] = nstTime->mHour / 10;
DispBuff[1] = nstTime->mHour % 10;
DispBuff[2] = 16;
DispBuff[3] = nstTime->mMinute / 10;
DispBuff[4] = nstTime->mMinute % 10;
DispBuff[5] = 16;
DispBuff[6] = nstTime->mSecond / 10;
DispBuff[7] = nstTime->mSecond % 10;
}
void DispToBuff(uint8_t val) {
uint8_t i;
for (int i = 0; i < 7; i++) {
DispBuff[i] = DispBuff[i + 1];
}
DispBuff[7] = val;
}