From d3d48cf1760d9ddc783e2e39935eb1818532661c Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 21 Mar 2023 16:28:46 +0100 Subject: [PATCH] Compteur Done --- ProjetsKEIL/Drivers/Driver_timers.c | 29 ++++++++++++++++++++++++++++ ProjetsKEIL/Drivers/Driver_timers.h | 25 ++++++++++++++++++++++++ ProjetsKEIL/Projet_1/Src/Principal.c | 28 ++++++++++++++++++--------- ProjetsKEIL/Projet_1/TP.uvoptx | 14 +++++++++++++- ProjetsKEIL/Projet_1/TP.uvprojx | 10 ++++++++++ 5 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 ProjetsKEIL/Drivers/Driver_timers.c create mode 100644 ProjetsKEIL/Drivers/Driver_timers.h diff --git a/ProjetsKEIL/Drivers/Driver_timers.c b/ProjetsKEIL/Drivers/Driver_timers.c new file mode 100644 index 0000000..fef84af --- /dev/null +++ b/ProjetsKEIL/Drivers/Driver_timers.c @@ -0,0 +1,29 @@ +#include "Driver_timers.h" + + + +void timer_init(MyTimer_Struct_TypeDef * Timer){ + if(Timer->Timer == TIM1){ + RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; + } + if(Timer->Timer == TIM2){ + RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; + } + if(Timer->Timer == TIM3){ + RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; + } + if(Timer->Timer == TIM4){ + RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; + } +} + + +void MyTimer_Start(MyTimer_Struct_TypeDef *Timer) +{ + Timer->Timer->CR1 |= TIM_CR1_CEN; // Démarre le Timer +} + +void MyTimer_Stop(MyTimer_Struct_TypeDef *Timer) +{ + Timer->Timer->CR1 &= ~TIM_CR1_CEN; // Arrête le Timer +} \ No newline at end of file diff --git a/ProjetsKEIL/Drivers/Driver_timers.h b/ProjetsKEIL/Drivers/Driver_timers.h new file mode 100644 index 0000000..4e69fbc --- /dev/null +++ b/ProjetsKEIL/Drivers/Driver_timers.h @@ -0,0 +1,25 @@ +#ifndef MYTIMER_H +#define MYTIMER_H + +#include "stm32f10x.h" + + +typedef struct +{ + TIM_TypeDef * Timer; + unsigned short ARR; + unsigned short PSC; +} MyTimer_Struct_TypeDef; + + +void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer); +void timer_init(MyTimer_Struct_TypeDef * Timer); +void MyTimer_Start(MyTimer_Struct_TypeDef *Timer); +void MyTimer_Stop(MyTimer_Struct_TypeDef *Timer); + + + +#define MyTimer_Base_Start(Timer) +#define MyTimer_Base_Stop(Timer) + +#endif \ No newline at end of file diff --git a/ProjetsKEIL/Projet_1/Src/Principal.c b/ProjetsKEIL/Projet_1/Src/Principal.c index 83f5588..18b8f3e 100644 --- a/ProjetsKEIL/Projet_1/Src/Principal.c +++ b/ProjetsKEIL/Projet_1/Src/Principal.c @@ -1,15 +1,17 @@ #include "stm32f10x.h" #include "Driver_GPIO.h" +#include "Driver_timers.h" + // PA5 LED // PC13 BP MyGPIO_Struct_TypeDef LED; +MyTimer_Struct_TypeDef Timer_500ms; int delay(){ - int i; - for(i=0;i<1000000;i++); + } @@ -30,17 +32,25 @@ int main ( void ) MyGPIO_Init(&LED); - - + + Timer_500ms.Timer = TIM2; + Timer_500ms.PSC = 7200; //(1/72Mhz)/7200=0.1ms + Timer_500ms.ARR = 5000; //0.1*5000 = 500ms + timer_init(&Timer_500ms); + MyTimer_Start(&Timer_500ms); + while(1) { - if(MyGPIO_Read(GPIOC, 13) == 0) - { - MyGPIO_Toggle(GPIOA, 5); - delay(); - } + //if(MyGPIO_Read(GPIOC, 13) == 0) + //{ + MyGPIO_Set(GPIOA, 5); + while(Timer_500ms.Timer->CNT != Timer_500ms.ARR -1); //CNT registre qui gère le retour à 0 + MyGPIO_Reset(GPIOA, 5); + while(Timer_500ms.Timer->CNT != Timer_500ms.ARR -1); + //} } + } diff --git a/ProjetsKEIL/Projet_1/TP.uvoptx b/ProjetsKEIL/Projet_1/TP.uvoptx index 53076ed..5faec1b 100644 --- a/ProjetsKEIL/Projet_1/TP.uvoptx +++ b/ProjetsKEIL/Projet_1/TP.uvoptx @@ -290,7 +290,7 @@ 0 DLGTARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=703,344,1124,749,0)(121=931,445,1352,850,0)(122=409,446,830,851,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=703,344,1124,749,0)(121=931,445,1352,850,0)(122=409,446,830,851,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=872,142,1466,836,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) 0 @@ -414,6 +414,18 @@ 0 0 + + 2 + 3 + 1 + 0 + 0 + 0 + ..\Drivers\Driver_timers.c + Driver_timers.c + 0 + 0 + diff --git a/ProjetsKEIL/Projet_1/TP.uvprojx b/ProjetsKEIL/Projet_1/TP.uvprojx index 50593f0..793c2a7 100644 --- a/ProjetsKEIL/Projet_1/TP.uvprojx +++ b/ProjetsKEIL/Projet_1/TP.uvprojx @@ -398,6 +398,11 @@ 1 ..\Drivers\Driver_GPIO.c + + Driver_timers.c + 1 + ..\Drivers\Driver_timers.c + @@ -800,6 +805,11 @@ 1 ..\Drivers\Driver_GPIO.c + + Driver_timers.c + 1 + ..\Drivers\Driver_timers.c +