/* 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> #include /* 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 */ /* Configuration générale. */ #fuses H4,WDT,WDT128,PUT,NOBROWNOUT,NOLVP #use delay(clock=40000000) #use rs232(baud=115200,xmit=PIN_C6,parity=N,rcv=PIN_C7,bits=8) #priority RDA,TBE,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); /* Le timer0 est utilisé pour les pas du moteur gauche. */ setup_timer_0 (RTCC_EXT_L_TO_H | RTCC_8_BIT | RTCC_DIV_1); /* Le timer1 est inutilisé. */ 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_4, 124, 10); /* Le timer3 est utilisé pour les pas du moteur droit. */ setup_timer_3 (T3_EXTERNAL | T3_DIV_BY_1); /* Désactivation 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); } /* Initialise les interruptions. */ void irq_init (void) { /* Configuration des interruptions activées. */ enable_interrupts (INT_TIMER2); enable_interrupts (INT_RDA); disable_interrupts (INT_TBE); enable_interrupts (GLOBAL); } void main (void) { delay_ms (20); main_init (); motor_init (); serial_init (); irq_init (); serial_send_rezet (); motor_main (); }