summaryrefslogtreecommitdiff
path: root/n/es/src
diff options
context:
space:
mode:
authordalmais2005-04-16 23:51:00 +0000
committerdalmais2005-04-16 23:51:00 +0000
commit2fc0d8c1ecafdb65d579a69ad1bbb00d8fc10302 (patch)
treefd7f94c6b1ee62bd1f42b97b33f5cfefd9d83d15 /n/es/src
parent21af4d885eff12ebe6c6d0472ec4b3897bcbaeae (diff)
Version de test à débugger. Mais qui compile
Diffstat (limited to 'n/es/src')
-rw-r--r--n/es/src/Makefile8
-rw-r--r--n/es/src/avrconfig.h6
-rw-r--r--n/es/src/carte_capteurs.c78
-rw-r--r--n/es/src/carte_capteurs.h32
-rw-r--r--n/es/src/main.c52
-rw-r--r--n/es/src/tourelle.c133
-rw-r--r--n/es/src/tourelle.h18
7 files changed, 139 insertions, 188 deletions
diff --git a/n/es/src/Makefile b/n/es/src/Makefile
index b09dd9e..dadafda 100644
--- a/n/es/src/Makefile
+++ b/n/es/src/Makefile
@@ -1,8 +1,8 @@
-PROGS = Carte_capteur
-Carte_capteur_OBJECTS = main.o rs232.o Tourelle.o adc.o
+PROGS = es
+es_OBJECTS = main.o rs232.o tourelle.o adc.o twi_slave.o
DOC =
EXTRACTDOC =
-MODULES = n/avr/rs232 n/avr/carte_capteur n/avr/utils n/avr/adc
+MODULES = n/avr/rs232 n/avr/carte_capteur n/avr/utils n/avr/adc n/avr/proto n/avr/twi-slave
CONFIGFILE = avrconfig.h
# atmega8, atmega8535, atmega128...
MCU_TARGET = atmega8535
@@ -15,5 +15,5 @@ LDLIBS =
include Makefile.avr
-Carte_capteur.elf: $(Carte_capteur_OBJECTS)
+es.elf: $(es_OBJECTS)
diff --git a/n/es/src/avrconfig.h b/n/es/src/avrconfig.h
index a96d7ef..3fd9eb1 100644
--- a/n/es/src/avrconfig.h
+++ b/n/es/src/avrconfig.h
@@ -63,4 +63,10 @@
/** Support for quote parameter. */
#define AC_PROTO_QUOTE 1
+/** number max reception I2C*/
+#define SIZE_BUF_RCPT 1
+/** number max send I2C*/
+#define SIZE_BUF_SEND 10
+
+
#endif /* avrconfig_h */
diff --git a/n/es/src/carte_capteurs.c b/n/es/src/carte_capteurs.c
deleted file mode 100644
index 81d2870..0000000
--- a/n/es/src/carte_capteurs.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* main.c */
-/* n.avr.carte_capteurs - AVR Carte_capteur Principal Module. {{{
- *
- * Copyright (C) 2005 Dalmais Romain
- *
- * 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.
- *
- * Contact :
- * Web: http://perso.efrei.fr/~dalmais/
- * Email: <dalmais@gmail.com>
- * }}} */
-
-//#include "rs232.h"
-//#include "I2C.h"
-#include "carte_capteur.h"
-
-/* +AutoDec */
-/* -AutoDec */
-
-int
-main (void)
-{
- int clock;
- int timer;
- /// intialisation
- renvoyer(A1,A2,A3,...);
-m:!;<F10>
- rs232_init ();
- I2C_init (0x01); // A CHANGER ou vérifier adresse 1
- Tourelle_init(); // verifier
- clock=0;
-
- /// programme principal
-
- while(1)
- {
- tourner_servo();
- mesurer();
- switch(buffer[0])
- {
- case 'z':{reset();}break;
- case 'p':{clock=(int)buffer[1];}break;
-
- };
-
- if(timer==clock)
- renvoyer(A1,A2,A3,...);
-
- }
-
-}
-
-void
-proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
-{
-#define c(cmd, size) (cmd << 8 | size)
- switch (c (cmd, size))
- {
- case c ('z', 0):
- reset ();
- break;
- /* Commands. */
- case c ('p', 0):
- /// inclure le rencoi et la gestion du temps.
- }
-
diff --git a/n/es/src/carte_capteurs.h b/n/es/src/carte_capteurs.h
deleted file mode 100644
index 2f9b993..0000000
--- a/n/es/src/carte_capteurs.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef main_h
-#define main_h
-/* main.h */
-/* n.avr.carte_capteurs - AVR Carte Capteur Module. {{{
- *
- * Copyright (C) 2005 Dalmais Romain
- *
- * 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.
- *
- * Contact :
- * Web: http://perso.efrei.fr/~dalmais/
- * Email: <dalmais@gmail.com>
- * }}} */
-
-#include "n/avr/rs232/rs232.h"
-#include "n/avr/twi-slave/twi_slave.h" // A CHANGER
-#include "n/avr/tourelle/tourelle.h"
-#include "n/avr/utils/utils.h"
-
-
diff --git a/n/es/src/main.c b/n/es/src/main.c
index a9d0299..6b1f5ce 100644
--- a/n/es/src/main.c
+++ b/n/es/src/main.c
@@ -22,43 +22,61 @@
* Email: <contact@ni.fr.eu.org>
* }}} */
-//#include "rs232.h"
-//#include "I2C.h"
-#include "carte_capteur.h"
+#include "tourelle.h"
+#include "n/avr/proto/proto.h"
+#include "n/avr/utils/byte.h"
+#include "avr/interrupt.h"
+#include "avr/io.h"
+#include <stdint.h>
/* +AutoDec */
/* -AutoDec */
-uint8_t valeur[25];
-main (void)
+static uint8_t etat = 1; // etat de fonctionnement du module
+static uint8_t sens = 1; // sens du scan
+static uint8_t continu = 0; // demande fait d'un envoi en continu sur le RS232
+static uint8_t envoie = 0; // demande fait par I2C d'un envoi
+static char buffer_serie ; // buffer RS232
+const uint16_t prescaler = 1024;// prescaler
+static uint16_t tableau_longueur[25];
+
+int main (void)
{
+ uint8_t temp_sens = 1;
+ uint8_t compteur = 0;
+ uint16_t tableau_sharp[3];
+
/// intialisation
rs232_init ();
- I2C_init (); /// A CHANGER
- toutelle_init ();
-
+ twi_init (0x02); /// A CHANGER
+ tourelle_init (prescaler);
+ adc_init ();
+ sei ();
+
/// programme principal
while(1)
{
if(etat == 1)
{
- etat = 0;
- TCNT0 = 65535 - ((20*14745600)/(1024*1000));
+ etat = 0; // a 0 normalement=> TEST
+ TCNT1 = (65535L - ((20L*14745600L)/(1024L*1000L)));
if(temp_sens != sens)
{
temp_sens = sens;
- if(continu == 1) renvoi_RS232();
+// if(continu == 1) renvoi_RS232(); // nom de la fonction qui renvoie la valeur
}
- if(buffer_serie != 0) callback_RS232();
+// if(buffer_serie != 0) callback_RS232();
}
- if(etat == 1 && envoie == 1)
+
+ for(compteur=0;compteur<3;compteur++)
{
- traitement(); //traiter les valeurs du tableau
- renvoyer(A1,A2,A3,...); // mettre me renvoie des valeurs
+ adc_start (compteur); // pin selectionnee
+ while(!adc_checkf()){}
+ tableau_sharp[0]=adc_read();
}
-
+ twi_update (tableau_sharp,6);
+
}
}
-
diff --git a/n/es/src/tourelle.c b/n/es/src/tourelle.c
index b186cef..54e69a0 100644
--- a/n/es/src/tourelle.c
+++ b/n/es/src/tourelle.c
@@ -1,4 +1,4 @@
-/*Tourelle.c*/
+/* tourelle.c*/
/* Detector on a ATmega128. {{{
* Copyright (C) 2005 Dalmais Romain
*
@@ -21,68 +21,99 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* }}} */
-#include "Tourelle.h"
+#include "tourelle.h"
+#include "avr/signal.h"
-const int8_t delayMax = 125;
-const int8_t delayMin = 175;
-const int8_t SEUIL = 180; // 10 cm = 2.25V et 80 cm = 1.75 V
-
-//capteur sharp sur PA0
+const uint8_t delayMax = 125;
+const uint8_t delayMin = 175;
+const uint8_t pin_sharp = 3 ;
+uint8_t delay = 0;
+const uint8_t SEUIL = 180; // 10 cm = 2.25V et 80 cm = 1.75 V
+const uint8_t MILIEU = 2;
+// const int8_t PROUT = 12; A VERIFIER !!
+//capteur sharp sur PA3
+//servo sur PB
/* etat mode:
* 0 = inactif
* 1 = continu */
-int8_t etat=0;
-int8_t tableau_longueur[25];
-tourelle_init(int8_t prescaler)
+uint16_t tableau_longueur[25];
+/*
+extern uint8_t continu;
+extern uint8_t etat;
+extern uint8_t envoie;
+extern uint8_t sens;
+*/
+uint8_t valeur_actuelle1 = 0;
+uint8_t valeur_actuelle2 = 0;
+uint8_t angle_actuel1 = 0;
+uint8_t angle_actuel2 = 0;
+uint8_t valeur_ancienne1 = 0;
+uint8_t valeur_ancienne2 = 0;
+uint8_t angle_ancien1 = 0;
+uint8_t angle_ancien2 = 0;
+uint8_t nombre_actuel = 0;
+uint8_t nombre_ancien = 0;
+
+void tourelle_init (uint16_t prescaler)
{
- continu = 0;
delay = 0;
+ DDRB = 0xFF;
SFIOR |= 0x01; // prescaler autorisé
- crenaux(delay); // on met le capteur à 0°
- wait_1ms(20);
+ crenaux(delay,PORTB,7); // on met le capteur à 0°
+// wait_1ms(20);
- crenaux(delay);
- wait_1ms(20);
+ crenaux(delay,PORTB,7);
+// wait_1ms(20);
- crenaux(delay);
+ crenaux(delay,PORTB,7);
switch(prescaler)
{
- case 81: registre_prescal |= 0x03;break;
+ case 8 :
+ {
+ TCCR1B |= 0x02;
+ TCCR1B &= 0xFA;
+
+
+ }break;
case 64 :
{
- registre_prescaler &= 0xFD;
- registre_prescaler |= 0x01;
+ TCCR1B &= 0xFB;
+ TCCR1B |= 0x03;
}break;
case 256 :
{
- registre_prescaler &= 0xFD;
- registre_prescaler |= 0x01;
+ TCCR1B &= 0xFC;
+ TCCR1B |= 0x04;
}break;
- case 1024: registre_prescal |= 0x03;break;
+ case 1024:
+ {
+ TCCR1B |= 0x05;
+ TCCR1B &= 0xFD;
+ }break;
}
}
-crenaux(int8_t temps, int8_t port, int8_t pin)
+void crenaux(uint8_t temps, uint8_t port, uint8_t pin)
{
port |= pin; // en admettant que je sois sur le portb et la troisième pin
- wait_10us(temp);
+// wait_10us(temp); // TROUVER LA FONCTION !!!!!!!!
port &= 0xFF - pin; // on remet l'impulsion à 0
}
-proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
+void rs232_callback (uint8_t cmd, uint8_t size, uint8_t *args, uint8_t *etat,uint8_t *envoie)
{
#define c(cmd, size) (cmd << 8 | size)
switch (c (cmd, size))
@@ -92,27 +123,28 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
/* Commands. */
case c ('c', 0):{ // continu
- etat = 1;
- envoie = 1;
- if(c(0,1)) sendValeur(); /// mettre la bonne fonction
+ (*etat) = 1;
+ (*envoie) = 1;
+// if(c(0,1)) sendValeur(); /// METTRE LA BONNE FONCTION
}break;
case c ('u',0):{ // unique
- envoie = 0;
- sendValeur();
+ (*envoie) = 0;
+// sendValeur(); /// METTRE LA BONNE FONCTION
etat = 0;
}break;
case c ('s',0): { // stop
- etat = 0;
- envoie = 0;
+ (*etat) = 0;
+ (*envoie) = 0;
}break;
+ }
}
-TournerTourelle()
+void TournerTourelle(uint8_t sens)
{
- if(delay=delayMax||delay=delayMin)
+ if( delay==delayMax || delay==delayMin)
{
sens *= -1;
@@ -128,21 +160,19 @@ TournerTourelle()
}
delay += 2 * sens;
- crenaux(delay,portc,0x07);
+ crenaux(delay,PORTB,0x07);
}
-int8_t mesurer()
+int16_t mesurer(void)
{
-
-adc_init();
-adc_start();
-while(!adc_checkf)
-{wait_1us(1)}
-return adc_read();
+ adc_init();
+ adc_start(pin_sharp);
+ while(!adc_checkf()){}
+ return adc_read();
}
-void Timer_tourelle()
+SIGNAL (SIG_INTERRUPT1)
{
// on fait la mesure
uint8_t i = 0;
@@ -154,29 +184,26 @@ void Timer_tourelle()
}
tableau_longueur[0] = mesurer();
- if(temp == tableau_longueur[MILIEU+1])
+ if(temp == tableau_longueur[MILIEU+1] && temp > SEUIL )
{
- if(nombre_valeur == 0)
+ if(nombre_actuel == 0)
{
- valeur_actuelle1 = (PROUT - distance);
+ valeur_actuelle1 = tableau_longueur[MILIEU+1];
angle_actuel1 = 45 + (delay - 6)*90/50;
}
- if(nombre_valeur == 1)
+ if(nombre_actuel == 1)
{
- valeur_actuelle2 = (PROUT - distance);
+ valeur_actuelle2 = tableau_longueur[MILIEU +1];
angle_actuel2 = 45 + (delay - 6)*90/50;
}
- if(nombre_valeur > 1)
+ if(nombre_actuel > 1)
{
-// ALARME // PROBLEME
+// ALARME // PROBLEME // ALLUMER LED
}
}
-cycle();
}
-
-
diff --git a/n/es/src/tourelle.h b/n/es/src/tourelle.h
index 95cb3dc..edf851c 100644
--- a/n/es/src/tourelle.h
+++ b/n/es/src/tourelle.h
@@ -1,4 +1,4 @@
-/* Tourelle.h */
+/* tourelle.h */
/* Detector on a ATmega128. {{{
*
* Copyright (C) 2005 Dalmais Romain
@@ -19,12 +19,22 @@
*
* }}} */
+#ifndef tourelle_h
+#define tourelle_h
/* inclusion */
-#include <n/avr/rs232/rs232.h>
-#include <n/avr/utils/utils.h>
-#include "n/avr/twi-slave/twi_slave.h" // A CHANGER
+#include "n/avr/rs232/rs232.h"
+#include "n/avr/utils/utils.h"
+#include "n/avr/twi-slave/twi_slave.h"
+#include "n/avr/adc/adc.h"
/* proto */
+void tourelle_init (uint16_t prescaler);
+void crenaux(uint8_t temps, uint8_t port, uint8_t pin);
+void rs232_callback (uint8_t cmd, uint8_t size, uint8_t *args, uint8_t *etat,uint8_t *envoie);
+void TournerTourelle(uint8_t sens);
+int16_t mesurer(void);
+void Timer_tourelle(void);
+#endif