#include #include "serial.h" #include "hardware.h" #include "move.h" #include "tempo.h" // Variables liaison série extern char msg[MAX_MSG]; extern bit a,serial_error ; // Variables gestion servos extern volatile unsigned int direction,vitesse; extern const unsigned int per ; extern volatile unsigned int CCPR1,CCPR2; extern volatile signed char angle,speed ; extern volatile unsigned char move_state,turn_state; extern unsigned int tempo0_cpt; extern unsigned char tempo0_state; void interrupt isr (void) { // Variables liaison série static unsigned char i; char c; static unsigned int n ; // Partie gestion servos moteur et direction if ( CCP1IF ) { CCP1IF = 0 ; if ( RC2==0) { RC2=1; CCPR1 = CCPR1 + vitesse ; } else { RC2=0; CCPR1 = CCPR1 + per - vitesse ; } } if ( CCP2IF ) { CCP2IF = 0 ; if ( RC1==0){ RC1=1; CCPR2 = CCPR2 + direction ; } else { RC1=0; CCPR2 = CCPR2 + per - direction ; } } else { // Partie réception caractère if ( RCIF ) { c=RCREG; if(c!=0x0D) // ce n'est pas CR { if(c!=0x08) // ni BS { if ( i < (MAX_MSG-1) ) // Max de caractère avant CR { msg[i++]=c; // caractère normal } else // Trop de caractères avant CR { serial_error=SERIAL_ERROR; i=0; a=1; // on déclenche l'analyse avec error ! } } else // pour BS il suffit de faire i-- { if (i>0) // sauf au premier coup ! { i=i-1; } } } else // reception CR avant max de caractères { msg[i]='\0'; // Forme une chaîne C i=0; // Pour la prochaine commande serial_error = SERIAL_NO_ERROR ; a=1; // Déclenche l'analyse } } // Partie Gestion du mouvement et tempo 0 if (T0IF) { T0IF=0; // automate tempo 0 switch (tempo0_state) { case TEMPO_STOP : break ; case TEMPO_START : case TEMPO_PENDING : if ( tempo0_cpt == 0 ) { tempo0_state=TEMPO_DONE; } else { tempo0_cpt--; } break; case TEMPO_DONE : break; } // gestion de mouvement if (angle == 0 ) { vitesse = 5*speed + 1500; direction = 1550 ; turn_state = TURN_STOP ; LeftLed=1; } else { signed char angleabs ; angleabs= (angle>0)?angle:-angle; #define ANGLE_DT 3 // à regler direction = (angle>0)?2000:1000; vitesse = (angle>0)?1600:1400; // à régler switch(turn_state) { case TURN_STOP : n=0; turn_state = TURN_IN_PROGRESS ; LeftLed =1 ; break ; case TURN_IN_PROGRESS: n++; if ( n > (angleabs/ANGLE_DT)) { turn_state=TURN_DONE; } LeftLed=0; break ; case TURN_DONE : vitesse = 1500 ; direction = 1550 ; LeftLed =1 ; break; } } } } }