RefKEIL/projet_1/src/main.c

57 lines
1.4 KiB
C

#include "stm32f10x.h"
#include "Driver_GPIO.h"
#include "Driver_Timer.h"
void delay() {
int i = 0;
for(i = 0; i < 1000000; i++);
}
int main(void) {
// Configure la broche PA5 en sortie
MyGPIO_Struct_TypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = 5;
GPIO_InitStructure.GPIO_Conf = Out_Ppull;
GPIO_InitStructure.GPIO = GPIOA;
MyGPIO_Init(&GPIO_InitStructure);
// Configure la broche PC13 en entrée avec une résistance de pull-up
GPIO_InitStructure.GPIO_Pin = 13;
GPIO_InitStructure.GPIO_Conf = In_PullUp;
GPIO_InitStructure.GPIO = GPIOC;
MyGPIO_Init(&GPIO_InitStructure);
MyTimer_Struct_TypeDef Timer;
Timer.Timer = TIM2;
Timer.PSC = 7200; // Prescaler = 7200, donc chaque tick d'horloge prend 0,1ms (10 MHz)
Timer.ARR = 5000; // Autoreload = 5000, donc le timer compte jusqu'à 5000, ce qui prend 500ms (0,1ms * 5000)
MyTimer_Base_Init(&Timer); // Initialise le Timer 2
while(1) {
/*
// Vérifie si le bouton est pressé
if(MyGPIO_Read(GPIOC, 13) == 0) {
// Toggle la LED
MyGPIO_Toggle(GPIOA, 5);
// Delay pour éviter les rebonds du au ressort du bouton
delay();
}
*/
MyTimer_Base_Start(&Timer); // Démarre le Timer 2
while (Timer.Timer->CNT != Timer.ARR - 1); // Attend que le compteur atteigne la valeur d'autoreload
MyGPIO_Toggle(GPIOA, 5);
MyTimer_Base_Stop(&Timer); // Arrête le Timer 2
}
}