/* 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 40 b7 : sens compteur gauche 39 b6 : libre -> 38 b5 : libre -> 37 b4 : sens compteur droit 36 b3 : libre -> 35 b2 : libre -> 34 b1 : libre -> 33 b0 : debug 32 Vdd 31 Vss 30 d7 : libre <- 29 d6 : libre <- 28 d5 : libre <- 27 d4 : libre <- 26 c7 : rcv 25 c6 : xmit 24 c5 : libre 23 c4 : libre 22 d3 : libre <- 21 d2 : libre <- 20 d1 : sens moteur gauche 19 d0 : sens moteur droit 18 c3 : libre 17 c2 : pwm motor gauche 16 c1 : pwm motor droit 15 c0 : compteur droit 14 a6, osc2 13 osc1 12 Vss 11 Vdd 10 e2 : libre 9 e1 : libre (lcd e) 8 e0 : libre (lcd rs) 7 a5 : libre 6 a4 : compteur gauche 5 a3 : libre (lcd d7) 4 a2 : libre (lcd d6) 3 a1 : libre (lcd d5) 2 a0 : libre (lcd d4) 1 /MCLR, Vpp Libre: a b c d e ....-5- ....-..- ---345-- --...... ..2 ooooiii ioooiooi iooiiioi ooiiiiii ooi - : occupé par la carte d'asservissement. . : occupé par les bonus (debug, gpio, lcd). */ /* 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 EXT,RDA,TBE,TIMER2 #use fast_io(A) #use fast_io(B) #use fast_io(D) #use fast_io(E) #include "motor.c" #include "serial.c" /* Initialise le PIC. */ void main_init (void) { /* Comfiguration des GPIO. */ output_a (0x00); set_tris_a (0xf0); output_b (0x00); set_tris_b (0x91); //set_tris_c (0xb9); set_tris_d (0xfc); output_e (0x00); set_tris_e (0x04); /* 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); disable_interrupts (INT_EXT); } void main (void) { delay_ms (20); main_init (); motor_init (); serial_init (); irq_init (); serial_send_rezet (); motor_main (); } #int_EXT debug_isr () { int tosl, tosh, tosu; #asm movf 0xffd,w movwf tosl movf 0xffe,w movwf tosh movf 0xfff,w movf tosu #endasm putc ('!'); putc (tosl); putc (tosh); putc (tosu); putc (CRLF); }