/* p2_4.c Display number 75 on a 2-digit 7-segment common cathode LED. * * The segments are driven by Port C0-C6. * The digit selects are driven by PB0 and PB1. * * This program was tested with Keil uVision v5.23 with DFP v2.0.0 */ #include "stm32f0xx.h" void delayMs(int n); int main(void) { RCC->AHBENR |= 0x00040000; /* enable GPIOB clock */ RCC->AHBENR |= 0x00080000; /* enable GPIOC clock */ GPIOC->MODER &= ~0x0000FFFF; /* clear pin mode */ GPIOC->MODER |= 0x00005555; /* set pins to output mode */ GPIOB->MODER &= ~0x0000000F; /* clear pin mode */ GPIOB->MODER |= 0x00000005; /* set pins to output mode */ for(;;) { GPIOB->BRR = 0x00000001; /* deselect ones digit */ GPIOC->ODR = 0x0007; /* display tens digit */ GPIOB->BSRR = 0x00000002; /* select tens digit */ delayMs(8); GPIOB->BRR = 0x00000002; /* deselect tens digit */ GPIOC->ODR = 0x006D; /* display ones digit */ GPIOB->BSRR = 0x00000001; /* select ones digit */ delayMs(8); } } /* 8 MHz SYSCLK */ void delayMs(int n) { int i; for (; n > 0; n--) for (i = 0; i < 1142; i++) ; }