/* 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" #define port_tourelle PORTB #define pin_tourelle 4 const uint8_t delayMax = 100; const uint8_t delayMin = 200; const uint8_t pin_sharp = 3 ; extern uint8_t delay; //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 action_tourelle; extern uint8_t pont; extern uint8_t clk; extern uint8_t ascenseur; 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é crenaux(delay,port_tourelle,pin_tourelle); // on met le capteur à 0° delay_ms(20L); crenaux(delay,port_tourelle,pin_tourelle); // on met le capteur à 0° delay_ms(20L); crenaux(delay,port_tourelle,pin_tourelle); // on met le capteur à 0° delay_ms(20L); crenaux(delay,port_tourelle,pin_tourelle); // on met le capteur à 0° delay_ms(20L); crenaux(delay,port_tourelle,pin_tourelle); // on met le capteur à 0° crenaux(delay,port_tourelle,pin_tourelle); // on met le capteur à 0° delay_ms(20L); crenaux(delay,port_tourelle,pin_tourelle); // on met le capteur à 0° delay_ms(20L); pont = 1; ascenseur = 1; 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