TP_microcontroleur/timer_act2/Source/principal.c
2021-10-04 17:29:07 +02:00

55 lines
1.2 KiB
C

#include "stm32f10x.h"
#include "Driver_GPIO.h"
#include "Driver_TIMER.h"
MyTimer_Struct_TypeDef MonTimer ;
MyGPIO_Struct_TypeDef greenLed ;
MyGPIO_Struct_TypeDef sortiePWM ;
void callback_TIM2(void) {
MyGPIO_Toggle(greenLed.GPIO, greenLed.GPIO_Pin);
}
int main(void) {
//activation du timer 2 et du GPIO A
Activate_TIM(1);
MyGPIO_Activate(1);
//Configuration du timer 2
MonTimer.Timer = TIM1 ;
//méthode PGCD
//MonTimer.ARR = 65454;
//MonTimer.PSC = 550 ;
//MonTimer.ARR = 18000;
//MonTimer.PSC = 2000 ;
//Pour une fréquence de 100kHz
MonTimer.ARR = 719 ;
MonTimer.PSC = 0 ;
MyTimer_Base_Init(&MonTimer);
//Configuration de la sortie PWM timer 2 channel 4 sur pin PA2
sortiePWM.GPIO = GPIOA;
sortiePWM.GPIO_Pin = 8 ;
sortiePWM.GPIO_Conf = AltOut_Ppull ;
MyGPIO_Init(&sortiePWM);
MyGPIO_Set(GPIOA, 8) ;
//Configuration de la diode
greenLed.GPIO = GPIOA;
greenLed.GPIO_Pin = 5 ;
greenLed.GPIO_Conf = Out_Ppull ;
MyGPIO_Init(&greenLed);
/*MyGPIO_Set(greenLed.GPIO,greenLed.GPIO_Pin);
MyTimer_Active_IT(TIM2, 1, callback_TIM2);*/
MyTimer_Base_Start(MonTimer.Timer);
MyTimer_PWM(MonTimer.Timer, 1);
MyTimer_PWM_set_cycle(MonTimer.Timer, 0.2, 1);
while(1) {}
}