From ea695ca13b725b6f2037986ef26fa1fea06b8faf Mon Sep 17 00:00:00 2001 From: schodet Date: Tue, 30 Sep 2003 22:17:01 +0000 Subject: Initial revision --- 2004/n/asserv/src/main.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 2004/n/asserv/src/main.c (limited to '2004/n/asserv/src/main.c') diff --git a/2004/n/asserv/src/main.c b/2004/n/asserv/src/main.c new file mode 100644 index 0000000..1dd817e --- /dev/null +++ b/2004/n/asserv/src/main.c @@ -0,0 +1,115 @@ +/* main.c */ +/* APBTasserv - asservissement Robot 2004 {{{ + * + * Copyright (C) 2003 Nicolas Schodet + * + * 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. + * + * }}} */ +#include <18f442.h> // Définition des registres du PIC18 +#include // Définition de la librairie standard + +// Pattes libres. +/* +40 rb7 (coupee) +39 rb6 : D3 +38 rb5 : D2 +37 rb4 : D1 +36 rb3 : D0 +35 rb2 : Clk busp +30 rd7 +29 rd6 : Capteur sharp +28 rd5 : Capteur doigts +27 rd4 : Capteur couleur +24 rc5 +23 rc4 +22 rd3 : Jack +21 rd2 +18 rc3 +10 re2 +9 re1 +8 re0 +7 ra5 +5 ra3 +4 ra2 +3 ra1 + +A1-5 B2-7 C4-5 D2-6 E0-2 +*/ + +// General configuration +#fuses HS,WDT,WDT128,PUT,NOBROWNOUT,NOLVP +#use delay(clock=20000000) +#use rs232(baud=115200,xmit=PIN_C6,parity=N,rcv=PIN_C7,bits=8) +#priority EXT,EXT1,RDA,TIMER2 + +#include "motor.c" +#include "serial.c" + +/* Initialise le PIC. */ +void +main_init (void) +{ + /* Configuration de la liaison série. */ + setup_psp (PSP_DISABLED); + /* Configuration de l'interface SPI : non utilisée. */ + setup_spi (FALSE); + // Configuration du chien de garde + //setup_wdt (WDT_OFF); + // Configuration du TIMER 0 pour lire le nombre de pas faits en reculant + setup_timer_0 (RTCC_EXT_L_TO_H | RTCC_8_BIT | RTCC_DIV_1); + // Confguration du TIMER 1 pour lire le nombre de pas faits en avançant + setup_timer_1 (T1_DISABLED); + // Configuration du TIMER 2. + // Tpwm = (PR2 + 1) * 4 * Tosc * TMR2_prescale + // Fpwm = 20kHz + // Tint2 = TMR2_postscale * Tpwm + // Tint2 = 0,5ms + setup_timer_2 (T2_DIV_BY_1, 249, 10); + // Configuration du TIMER 3 : non utilisé + setup_timer_3 (T3_EXTERNAL | T3_DIV_BY_1); + // Configuration de l'ADC + setup_adc_ports (NO_ANALOGS); + setup_adc (ADC_CLOCK_DIV_2); + // Configuration des registres pour un fonctionnement en PWM + setup_ccp1 (CCP_PWM); + setup_ccp2 (CCP_PWM); + set_pwm1_duty (0); + set_pwm2_duty (0); + // Configuration pour l'autorisation des interruptions. + enable_interrupts (INT_EXT); + enable_interrupts (INT_EXT1); + enable_interrupts (INT_TIMER2); + enable_interrupts (INT_RDA); + enable_interrupts (GLOBAL); + // Heu, on s'en servait pour le bus... + //output_low (PIN_B2); +} + +void +main (void) +{ + delay_ms (20); + motor_init (); + serial_init (); + main_init (); + while (1) + { + } +} -- cgit v1.2.3