STM32CubeMX-Keil_uVision5/exp8-Capture/Core/Src/SegLed.c
2024-12-15 20:39:48 +08:00

76 lines
1.3 KiB
C

#include "main.h"
#include "variable.h"
uint16_t display_tab[] = {
0x3f,
0x06,
0x5b,
0x4f,
0x66,
0x6d,
0x7d,
0x07,
0x7f,
0x6f,
0x77,
0x7c,
0x39,
0x5e,
0x79,
0x71,
0x40
};
uint8_t DispBuff[8];
uint16_t PosSel = 0;
static void DisplayOneLed(uint8_t dat, uint8_t pos, uint8_t dot) {
uint16_t temp;
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 DisplayToBuff(uint64_t dat) {
uint8_t i = 0;
for (i = 0; i < 8; i++) DispBuff[i] = 17; // 消隐
i = 7;
while (dat / 10) {
DispBuff[i] = dat % 10;
dat = dat / 10;
i--;
}
DispBuff[i] = dat;
}
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;
}