/**
******************************************************************************
* @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"
#if !defined(__SOFT_FP__) && defined(__ARM_FP)
#warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif
//----------Ejercicio 2----------
int main(void) {
// Habilitar Reloj Puerto A (bit 2) y Puerto C (bit 4)
RCC->APB2ENR |= (1 << 2) | (1 << 4);
// Configurar PC13 como Salida Push-Pull 2MHz
GPIOC->CRH &= ~(0xF << 20); // Limpiar bits 20-23
GPIOC->CRH |= (1 << 21); // MODE13 = 10 (2MHz)
// Configurar PA0 como Entrada con Pull-down
// Bits 0-1 (MODE), 2-3 (CNF)
GPIOA->CRL &= ~(0xF << 0); // Limpiar bits 0-3
GPIOA->CRL |= (1 << 3); // CNF0 = 10 (Input with pull-up/down)
GPIOA->ODR &= ~(1 << 0); // ODR0 = 0 (Selecciona Pull-down)
while(1) {
if(!(GPIOA->IDR & (1 << 0))) { // Si PA0 es nivel bajo (0)
GPIOC->ODR |= (1 << 13); // PC13 = 1 (Encender)
} else {
GPIOC->ODR &= ~(1 << 13); // PC13 = 0 (Apagar)
}
}
}