1: #include 2: #include "serial.h" 3: #include "hardware.h" 4: #include "move.h" 5: #include "tempo.h" 6: // Variables liaison série 7: extern char msg[MAX_MSG]; 8: extern bit a,serial_error ; 9: // Variables gestion servos 10: extern volatile unsigned int direction,vitesse; 11: extern const unsigned int per ; 12: extern volatile unsigned int CCPR1,CCPR2; 13: extern volatile signed char angle,speed ; 14: extern volatile unsigned char move_state,turn_state; 15: extern unsigned int tempo0_cpt; 16: extern unsigned char tempo0_state; 17: void interrupt isr (void) { 18: // Variables liaison série 19: static unsigned char i; 20: char c; 21: static unsigned int n ; 22: // Partie gestion servos moteur et direction 23: if ( CCP1IF ) 24: { 25: CCP1IF = 0 ; 26: if ( RC2==0) 27: { 28: RC2=1; 29: CCPR1 = CCPR1 + vitesse ; 30: } 31: else 32: { 33: RC2=0; 34: CCPR1 = CCPR1 + per - vitesse ; 35: } 36: } 37: if ( CCP2IF ) 38: { 39: CCP2IF = 0 ; 40: if ( RC1==0){ 41: RC1=1; 42: CCPR2 = CCPR2 + direction ; 43: } 44: else { 45: RC1=0; 46: CCPR2 = CCPR2 + per - direction ; 47: } 48: } 49: 50: else 51: { 52: 53: // Partie réception caractère 54: if ( RCIF ) 55: { 56: c=RCREG; 57: if(c!=0x0D) // ce n'est pas CR 58: { 59: if(c!=0x08) // ni BS 60: { 61: if ( i < (MAX_MSG-1) ) // Max de caractère avant CR 62: { 63: msg[i++]=c; // caractère normal 64: } 65: else // Trop de caractères avant CR 66: { 67: serial_error=SERIAL_ERROR; 68: i=0; 69: a=1; // on déclenche l'analyse avec error ! 70: } 71: } 72: else // pour BS il suffit de faire i-- 73: { 74: if (i>0) // sauf au premier coup ! 75: { 76: i=i-1; 77: } 78: } 79: } 80: else // reception CR avant max de caractères 81: { 82: msg[i]='\0'; // Forme une chaîne C 83: i=0; // Pour la prochaine commande 84: serial_error = SERIAL_NO_ERROR ; 85: a=1; // Déclenche l'analyse 86: } 87: } 88: 89: // Partie Gestion du mouvement et tempo 0 90: if (T0IF) 91: { 92: T0IF=0; 93: // automate tempo 0 94: switch (tempo0_state) 95: { 96: case TEMPO_STOP : 97: break ; 98: case TEMPO_START : 99: case TEMPO_PENDING : 100: 101: if ( tempo0_cpt == 0 ) 102: { 103: tempo0_state=TEMPO_DONE; 104: } 105: else 106: { 107: tempo0_cpt--; 108: } 109: break; 110: case TEMPO_DONE : 111: break; 112: } 113: // gestion de mouvement 114: 115: if (angle == 0 ) 116: { 117: vitesse = 5*speed + 1500; 118: direction = 1550 ; 119: turn_state = TURN_STOP ; 120: LeftLed=1; 121: 122: } 123: else 124: { 125: signed char angleabs ; 126: angleabs= (angle>0)?angle:-angle; 127: #define ANGLE_DT 3 // à regler 128: direction = (angle>0)?2000:1000; 129: vitesse = (angle>0)?1600:1400; // à régler 130: switch(turn_state) 131: { 132: case TURN_STOP : n=0; 133: turn_state = TURN_IN_PROGRESS ; 134: LeftLed =1 ; 135: break ; 136: case TURN_IN_PROGRESS: 137: n++; 138: if ( n > (angleabs/ANGLE_DT)) 139: { 140: turn_state=TURN_DONE; 141: } 142: LeftLed=0; 143: break ; 144: case TURN_DONE : 145: vitesse = 1500 ; 146: direction = 1550 ; 147: LeftLed =1 ; 148: break; 149: } 150: } 151: } 152: } 153: }