Projet_voilier2/Projet_voile/Sources/Principal.c
2023-03-27 20:17:23 +02:00

80 lines
No EOL
1.4 KiB
C

#include "stm32f10x.h"
#include <stdio.h>
#include <string.h>
#include "GPIO.h"
#include "TIMER.h"
#include "ADC.h"
#include "UART.h"
int val_adc=0;
int cpt_buff_tx=0;
int cpt_buff_rx=0;
MyGPIO_Struct_TypeDef PA5; //PA5 LED
MyGPIO_Struct_TypeDef PC13; //PC13 Bouton
MyTimer_Struct_TypeDef timer2;
MyADC_Struct_TypeDef myADC;
char buffer_tx[100]={0};
char buffer_rx[100]={0};
void GPIO_led_IT (void);
void ADC_IT(void);
void UART_RX_IT(void);
void UART_TX_IT(void);
int main ( void )
{
myADC.ADC=ADC1;
myADC.channel=2;
MyADC_init(&myADC);
MyADC_ActiveIT(myADC.ADC,4,&ADC_IT);
MyADC_start_conversion(myADC.ADC);
MyUART_init();
MyUART_ActiveIT(1, &UART_RX_IT, 'r'); //mode permet d'activer soit l'interruption sur RX (mode=0) soit TX (mode=1)
MyUART_ActiveIT(3, &UART_TX_IT, 't'); //mode permet d'activer soit l'interruption sur RX (mode=0) soit TX (mode=1)
sprintf(buffer_tx,"Test");
while(1)
{
}
}
void GPIO_led_IT (void)
{
MyGPIO_Toggle(PA5.GPIO,5);
}
void ADC_IT (void)
{
val_adc=MyADC_result(myADC.ADC);
}
void UART_TX_IT (void)
{
if(buffer_tx[cpt_buff_tx]!=0)
{
UART_send(buffer_tx[cpt_buff_tx]);
cpt_buff_tx++;
}
else
{
cpt_buff_tx=0;
memset(buffer_tx, 0, sizeof buffer_tx);
}
}
void UART_RX_IT (void)
{
if((cpt_buff_rx!=-1)&&(cpt_buff_rx<100))
{
buffer_rx[cpt_buff_rx]=UART_receive();
}
else
{
cpt_buff_rx=0;
memset(buffer_rx, 0, sizeof buffer_rx);
}
}