57 lines
1.1 KiB
C
57 lines
1.1 KiB
C
#include "stm32f10x.h"
|
|
#include "Driver_GPIO.h"
|
|
|
|
|
|
//mise en place des bits d'accès
|
|
#define ACCESS_BTN_BLUE (1 << 13)
|
|
#define ACCESS_LED_GREEN (1 << 5)
|
|
|
|
//configuration du pin de la led
|
|
//GPIOA->PIN PA.5 = 4*5 (où 4 = nb bit par pin)
|
|
#define DECALAGE_PA5 (5 * 4)
|
|
|
|
/*
|
|
typedef struct {
|
|
GPIO_TypeDef * GPIO ;
|
|
char GPIO_Pin ;
|
|
char GPIO_Conf ;
|
|
} MyGPIO_Struct_TypeDef ;
|
|
*/
|
|
|
|
int main(void){
|
|
|
|
//la LED
|
|
MyGPIO_Struct_TypeDef greenLed ;
|
|
MyGPIO_Struct_TypeDef blueButton ;
|
|
|
|
|
|
greenLed.GPIO = GPIOA;
|
|
greenLed.GPIO_Pin = 5 ;
|
|
greenLed.GPIO_Conf = Out_Ppull ;
|
|
|
|
//le bouton
|
|
blueButton.GPIO = GPIOC;
|
|
blueButton.GPIO_Pin = 13 ;
|
|
blueButton.GPIO_Conf = In_Floating ;
|
|
|
|
//activation des clocks
|
|
MyGPIO_Activate(1); //GPIOA
|
|
MyGPIO_Activate(3); //GPIOC
|
|
|
|
MyGPIO_Init(&greenLed);
|
|
MyGPIO_Init(&blueButton);
|
|
|
|
while(1){
|
|
|
|
if(MyGPIO_Read(blueButton.GPIO, blueButton.GPIO_Pin)){
|
|
//bouton non pressé, il faut éteindre la led
|
|
MyGPIO_Reset(greenLed.GPIO, greenLed.GPIO_Pin);
|
|
}
|
|
else {
|
|
//bouton pressé, il faut allumer la led
|
|
MyGPIO_Set(greenLed.GPIO, greenLed.GPIO_Pin);
|
|
}
|
|
|
|
}
|
|
|
|
}
|