/**
******************************************************************************
* @file : main.c
* @author : Auto-generated by STM32CubeIDE
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 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>
#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
int main(void){
/* In GPIO_mode, it is possible to configure any pin of any PORT as INPUT or OUTPUT */
/* GPIO_mode(GPIO_name, pin_number, IN/OUT) */
GPIO_mode(GPIOA, 5, IN); // Make 5th bit of GPIOA as INPUT
GPIO_mode(GPIOA, 6, OUT); // Make 6th bit of GPIOA as OUTPUT
GPIO_mode(GPIOA, 7, OUT);
GPIO_mode(GPIOB, 7, IN);
GPIO_mode(GPIOB, 3, OUT);
GPIO_mode(GPIOB, 4, OUT);
GPIO_mode(GPIOC, 13, IN);
GPIO_mode(GPIOC, 14, OUT);
GPIO_mode(GPIOC, 15, OUT);
while(1){
/* In this method, we can read or write any particular pin of any PORT */
/* GPIO_read(GPIO_name, pin_number) */
/* GPIO_write(GPIO_name, pin_number, 1/0) */
if(GPIO_read(GPIOA, 5) == 0){ // Read the 5th pin of GPIOA and check whether the switch is pressed or not
GPIO_write(GPIOA, 6, 1); // Make the 6th bit HIGH of GPIOA
GPIO_write(GPIOA, 7, 1); // Make the 7th bit HIGH of GPIOA
delay1(1500);
}
else{
GPIO_write(GPIOA, 6, 0); // Make the 6th bit LOW of GPIOA
GPIO_write(GPIOA, 7, 0); // Make the 7th bit LOW of GPIOA
}
/* In this method, we can read or write the 16 bit data of any PORT */
if((GPIOB_IN & (1 << 7)) == 0){ // Read the 7th pin of GPIOB and check whether the switch is pressed or not
GPIOB_OUT |= (3 << 3); // Make the 3rd and 4th bit HIGH of GPIOB
delay1(1500);
}
else GPIOB_OUT &= ~(3 << 3); // Make the 3rd and 4th bit LOW of GPIOB
/* In this method, we can read or write any particular pin of any PORT */
/* GPIO_read(GPIO_name, pin_number) */
/* GPIO_write(GPIO_name, pin_number, 1/0) */
if(GPIO_read(GPIOC, 13) == 0){
GPIO_write(GPIOC, 14, 1);
GPIO_write(GPIOC, 15, 1);
delay1(1500);
}
else{
GPIO_write(GPIOC, 14, 0);
GPIO_write(GPIOC, 15, 0);
}
}
}
Loading
stm32-bluepill
stm32-bluepill