void GPIO_Init() {
// GPIOA = LEDs
GPIOA->MODER &= ~(0xFFFF); // löscht alles-->default
GPIOA->MODER |= 0x5555; // macht alles ausgänge
// GPIOA = switch
// 2. Pins PB0 bis PB7 als Eingänge konfigurieren
GPIOB->MODER &= ~(0xFFFF); // löscht alle MODER bits bei GPIOB
// 3. Pull-Down für DIP-Switch konfigurieren
GPIOB->PUPDR &= ~(0xFFFF); // löscht alles bei GPIOB
GPIOB->PUPDR |= 0xAAAA; // macht alles pull down
}
void LED_Control() {
while (1) {
// 4. Zustände des DIP-Switches abfragen
uint8_t dipSwitchState = GPIOB->IDR & 0xFF; // Lesen der unteren 8 Bits von PB0-PB7
// 5. LEDs entsprechend dem DIP-Switch-Zustand steuern
GPIOA->ODR = (GPIOA->ODR & ~0xFF) | dipSwitchState; // Setzen der LEDs entsprechend dem DIP-Switch
}
}
void setup() {
GPIO_Init(); // Initialisiere GPIOs
}
void loop() {
LED_Control(); // Starte LED-Steuerung
}Loading
st-nucleo-c031c6
st-nucleo-c031c6