#include <stm32f10x.h>
#define _BV(n) (1 << (n))
uint8_t segdisp[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
uint16_t nNumber = 1970;
void delay()
{
uint32_t i;
for (i = 0; i < 20000; i++);
}
int main(void)
{
GPIO_InitTypeDef init;
uint8_t i;
uint8_t nCounter = 0;
uint16_t nTemp;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
init.GPIO_Pin = GPIO_Pin_All;
init.GPIO_Speed = GPIO_Speed_50MHz;
init.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &init);
GPIO_Init(GPIOB, &init);
while (1)
{
nTemp = nNumber;
for (i = 7; i >= 4; i--) // i表示要显示的数码管
{
GPIO_Write(GPIOA, ~_BV(i));
GPIO_Write(GPIOB, ~segdisp[nTemp % 10] << 8);
delay();
nTemp /= 10;
}
nCounter++;
if (nCounter > 100)
{
nCounter = 0;
nNumber++;
if (nNumber > 2038)
nNumber = 1970;
}
}
}