#include #include #include #include #include extern uint32_t tickms; float d; uint32_t last2 = 0; void MyBatterie_Init(void){ MyGPIO_Init(GPIOC,4,In_Analog); // Init PORT pour recevoir tension MyADC_Init(ADC1,14); // Init ADC channel 14 pour convertir valeur MyADC_ActiveIT(ADC1,15,&handler_ADC); // Init interruption quand conversion finie My_USART_Init(USART1); // Init USART pour envoyer batterie start_conversion(ADC1); // Premiere conversion } void handler_ADC (void){ //last2++; if (tickms - last2 >= 2000) { last2 = tickms; d = ADC1->DR &~ (0xF << 12); // Retourne valeur numérique d = d*3.3/4096; d = d*13*100/12; send_USART_String(USART1,"Batterie : "); send_USART(USART1,((int)d/10) + '0'); // Envoie le chiffre des dizaines send_USART(USART1,((int)d%10) + '0'); // Envoie le chiffre des unités send_USART_String(USART1,"%\n"); } start_conversion(ADC1); // Recommence la conversion pour le prochain }