【程序】 #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() { }
|