/**
******************************************************************************
* @file : main.c
* @author : Auto-generated by STM32CubeIDE
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include <stdint.h>
#include "stm32f103xb.h"
void display(int num);
void delay_ms(uint16_t t);
int main(void)
{
// Enable GPIOA clock
RCC->APB2ENR |= 1UL << 2;
// Set PA0-PA6 as 2MHz push-pull output
GPIOA->CRL &= (0xF0000000); // Clear fields
GPIOA->CRL |= 0x02222222; // MODEn = 10 (2MHz Output)
// PA<6:0> = 1
GPIOA->ODR |= 0x0000007F;
// Loop
int n = 0;
while ( 1 )
{
display(n++);
if(n > 9) n = 0;
delay_ms(1000);
}
}
void display(int num)
{
GPIOA->ODR &= ~0x0000007F;
switch(num)
{
case 0: GPIOA->ODR |= 0b1000000; break;
case 1: GPIOA->ODR |= 0b1111001; break;
case 2: GPIOA->ODR |= 0b0100100; break;
case 3: GPIOA->ODR |= 0b0110000; break;
case 4: GPIOA->ODR |= 0b0011001; break;
case 5: GPIOA->ODR |= 0b0010010; break;
case 6: GPIOA->ODR |= 0b0000010; break;
case 7: GPIOA->ODR |= 0b1111000; break;
case 8: GPIOA->ODR |= 0b0000000; break;
case 9: GPIOA->ODR |= 0b0010000; break;
default: GPIOA->ODR |= 0b1111111; break;
}
}
void delay_ms(uint16_t t) {
volatile unsigned long l = 0;
for(uint16_t i = 0; i < t; i++)
{
for(l = 0; l < 800; l++);
}
}
Loading
stm32-bluepill
stm32-bluepill