#include // for the input/output register #include // For the serial port #define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz #define tempo 25 #define debit 9600 //débit liaison série en bauds #define ADC0 0 #define ADC1 1 #define debut_serial_tx 0x40 //pour détecter la transmission d'une trame pour le 16u2 void init_serial(int speed) { /* Set baud rate */ UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; /* Enable transmitter & receiver */ UCSR0B = (1<>2; boutons = boutons & 0b00111111; boutons = boutons | 0b00100000; return boutons; } /* Met en forme l'octet de l'axe pos du joystick */ unsigned char shape_joy(unsigned char pos){ pos = pos >>3; //On récupère les 5 bits de poids forts de l'ADCH (diminuer sensibilité) pos = pos & 0b00111111; pos = pos | 0b00100000; return pos; } /* Récupération de la valeur de l'axe du joystick sur la chaîne channel du CAN */ unsigned char get_joystick(int channel){ unsigned char axis; ad_init(channel); axis = ad_sample(); axis = shape_joy(axis); return axis; } /* Dummy main */ int main(void){ //INITIALISATIONS unsigned char boutons, boutons_anc; unsigned char joystick_x=0x10, joystick_x_anc=0x10; unsigned char joystick_y=0x10, joystick_y_anc=0x10; init_serial(debit); output_init(); input_init(); //Récupération des valeurs des boutons et joystick, et mise en forme boutons = get_buttons(); joystick_x = get_joystick(ADC0); joystick_y = get_joystick(ADC1); while(1){ boutons_anc = boutons; joystick_x_anc = joystick_x; joystick_y_anc = joystick_y; //Récupération des valeurs des boutons et joystick, et mise en forme boutons = get_buttons(); joystick_x = get_joystick(ADC0); _delay_ms(tempo); joystick_y = get_joystick(ADC1); //Port série libre if ((UCSR0A & (1<