| 
              【程序】#include <stm32f10x.h>
 
 #define _BV(n) (1 << (n))
 
 uint8_t n = 0;
 uint8_t segdisp[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90}; // 共阳数码管段码表,取反后就是共阴的段码
 
 void delay()
 {
 int i, j;
 for (i = 0; i < 1000; i++)
 for (j = 0; j < 1000; j++);
 }
 
 void init()
 {
 int i;
 RCC->APB2ENR |= _BV(3); // 打开GPIOB的时钟
 
 // 把PB8~15都设置为输出模式
 for (i = 0; i < 8; i++)
 {
 GPIOB->CRH &= ~_BV(4 * i + 1);
 GPIOB->CRH |= _BV(4 * i);
 }
 }
 
 int main()
 {
 init();
 
 while (1)
 {
 GPIOB->ODR = (~segdisp[n]) << 8;
 delay();
 n++;
 if (n > 9)
 n = 0;
 }
 }
 
 void SystemInit()
 {
 }
 
 
 |