From 5af26ff4016fdd2a14abd5d7e4540e87161822e4 Mon Sep 17 00:00:00 2001 From: beaufour Date: Tue, 18 May 2004 17:00:18 +0000 Subject: Initial revision --- 2004/n/mini/mini.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2004/n/mini/mini.h | 4 +++ 2 files changed, 107 insertions(+) create mode 100644 2004/n/mini/mini.c create mode 100644 2004/n/mini/mini.h diff --git a/2004/n/mini/mini.c b/2004/n/mini/mini.c new file mode 100644 index 0000000..0ed4a76 --- /dev/null +++ b/2004/n/mini/mini.c @@ -0,0 +1,103 @@ +/* mini.c */ +/* APBTeam - Programme du petit Robot 2004 {{{ + * + * Copyright (C) 2003 Pierre-André Galmes + * + * Robot APB Team/Efrei 2004. + * Web: http://assos.efrei.fr/robot/ + * Mail: 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. + * + * }}} */ + +/* Principe : + * + * Le mini robot est composé d'un servo utilisé comme moteur pour avancer + * et reculer. Il fait des allez-retours. Dès qu'il touche un bord, il appuie + * sur un interrupteur et repart dansl'autre sens ! + * +*/ + +/* TODO + 1 - penser à faire arrêter le petit robot au bout de 1m30. +*/ + +#include "mini.h" + + +/* Définitions. */ +#define S_CHANGE 1 +#define S_FORWARD 0 +#define S_BACKWARD 1 + + +/* Programme Principal. */ +void main() +{ + unsigned short sens = S_FORWARD; + unsigned short changed = FALSE; + + + setup_adc_ports(NO_ANALOGS); + setup_adc(ADC_CLOCK_DIV_2); + setup_spi(FALSE); + setup_counters(RTCC_INTERNAL,WDT_18MS); + setup_timer_1(T1_DISABLED); + setup_timer_2(T2_DISABLED,0,1); + + + while (1) + { + + /* Changer de sens. */ + if ((input (PIN_B4) == S_CHANGE) && (changed == FALSE)) + { + changed = TRUE; + + if (sens == S_FORWARD) + sens = S_BACKWARD; + else + sens = S_FORWARD; + } + /* Vérifier que l'on arrête d'appuyer sur le micro-switch. */ + else if (input (PIN_B4) != S_CHANGE) + { + changed = FALSE; + } + + + /* Aller en avant. */ + if (sens == S_FORWARD) + { + /* Faire un cycle */ + output_low(PIN_B7); + delay_ms (18); + + output_high (PIN_B7); + delay_ms (2); + } + /* Aller en arrière. */ + else + { + /* Faire un cycle */ + output_low (PIN_B7); + delay_us (19000); + + output_high (PIN_B7); + delay_us (1000); + } + } +} diff --git a/2004/n/mini/mini.h b/2004/n/mini/mini.h new file mode 100644 index 0000000..9cc642c --- /dev/null +++ b/2004/n/mini/mini.h @@ -0,0 +1,4 @@ +#include <16F876.h> +#use delay(clock=4000000) +#fuses XT,WDT + -- cgit v1.2.3