/* tourelle.c*/ /* Detector on a ATmega128. {{{ * Copyright (C) 2005 Dalmais Romain * * Robot APB Team/Efrei 2005. * Web: http://assos.efrei.fr/robot/ * Email: robot AT efrei DOT fr * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * }}} */ #include "tourelle.h" #include "avr/signal.h" const uint8_t delayMax = 125; const uint8_t delayMin = 175; const uint8_t pin_sharp = 3 ; uint8_t delay = 0; //extern uint16_t SEUIL = 280; // 10 cm = 2.25Vnet 80 cm = 1.75 V const uint8_t MILIEU = 2; // const int8_t PROUT = 12; A VERIFIER !! //capteur sharp sur PA3 //servo sur PB /* etat mode: * 0 = inactif * 1 = continu */ uint16_t tableau_longueur[25]; extern uint8_t continu; extern uint8_t etat; extern uint8_t envoie; extern uint8_t sens; extern uint8_t mesure; uint8_t valeur_actuelle1 = 0; uint8_t valeur_actuelle2 = 0; uint8_t angle_actuel1 = 0; uint8_t angle_actuel2 = 0; uint8_t valeur_ancienne1 = 0; uint8_t valeur_ancienne2 = 0; uint8_t angle_ancien1 = 0; uint8_t angle_ancien2 = 0; uint8_t nombre_actuel = 0; uint8_t nombre_ancien = 0; void tourelle_init (uint16_t prescaler) { delay = 135; SFIOR |= 0x01; // prescaler autorisé rs232_putc('T'); crenaux(delay,PORTC,7); // on met le capteur à 0° delay_ms(20L); crenaux(delay,PORTC,7); delay_ms(20L); crenaux(delay,PORTC,7); // on met le capteur à 0° delay_ms(20L); DDRD = 0x80; crenaux(delay,PORTD,7); delay_ms(20L); crenaux(delay,PORTD,7); rs232_putc('C'); crenaux(delay,PORTC,7); // on met le capteur à 0° delay_ms(20L); crenaux(delay,PORTC,7); delay_ms(20L); rs232_putc('F'); switch(prescaler) { case 8 : { TCCR1B |= 0x02; TCCR1B &= 0xFA; }break; case 64 : { TCCR1B &= 0xFB; TCCR1B |= 0x03; }break; case 256 : { TCCR1B &= 0xFC; TCCR1B |= 0x04; }break; case 1024: { TCCR1B |= 0x05; TCCR1B &= 0xFD; }break; } } void crenaux(uint8_t temps, uint8_t port, uint8_t pin) { uint8_t delay_crenaux = 0; PORTD |= _BV (7); // en admettant que je sois sur le portb et la troisième pin for(delay_crenaux=0;delay_crenaux SEUIL ) { if(nombre_actuel == 0) { valeur_actuelle1 = tableau_longueur[MILIEU+1]; angle_actuel1 = 45 + (delay - 6)*90/50; } if(nombre_actuel == 1) { valeur_actuelle2 = tableau_longueur[MILIEU +1]; angle_actuel2 = 45 + (delay - 6)*90/50; } if(nombre_actuel > 1) { // ALARME // PROBLEME // ALLUMER LED } } */ TournerTourelle (); etat = 1; mesure = 1; }