summaryrefslogtreecommitdiff
path: root/2004/n/asserv/src/main.c
blob: 7f3732c52a99f83ac9aeb1fe262306d8df540e80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* 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 <stdlib.h>		// 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,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);
    // 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);
}

void
main (void)
{
    delay_ms (20);
    motor_init ();
    serial_init ();
    main_init ();
    while (1)
      {
      }
}