Révision 580
Ajouté par albest il y a presque 4 ans
branch/best/sp4a12/main.c | ||
---|---|---|
|
||
int decode_int(char c){ //Cette fonction renvoie la valeur decimale associ?e ? un caract?re donn? en param?tre compris entre '0' et '9' et renvoie -1 sinon.
|
||
int val = c - '0';
|
||
if (val<0 || val>9){
|
||
if (val<0 || val>9){ //**En premier faire le test pour ne pas faire op?ration pour rien
|
||
val = -1;
|
||
}
|
||
return val;
|
||
... | ... | |
}
|
||
|
||
float conv_lat(char * latitude){ //La fonction convertie la latitude en sexa en degr?.
|
||
float val = decode_nombre(latitude,4);
|
||
float val = decode_nombre(latitude,4); //* bof
|
||
float res = 0;
|
||
for (int i = 5; i < 9;i++){
|
||
val += (decode_int(latitude[i]))*pow(10,-i+4); //On replace chaque chiffre au bonne endroit (unit?, dizaine ...).
|
||
}
|
||
res = (int)(val/100);
|
||
res = (int)(val/100); //****
|
||
res += (val - res*100)/60;
|
||
return res;}
|
||
return res;
|
||
}
|
||
|
||
float conv_long(char * longitude){ //La fonction convertie la longitude en sexa en degr?.
|
||
float val = decode_nombre(longitude,5);
|
||
float val = decode_nombre(longitude,5); //**
|
||
float res = 0;
|
||
for (int i = 6; i < 10;i++){
|
||
val += (decode_int(longitude[i]))*pow(10,-i+5);
|
||
... | ... | |
|
||
float conversion(char * chaine){ //Cette fonction convertie soit une latitude soit une longitude en degr?.
|
||
int cpt = 0;
|
||
while (chaine[cpt]!='\0'){
|
||
while (chaine[cpt]!='\0'){ //***, .
|
||
cpt++;
|
||
}
|
||
if (cpt == 9){
|
||
... | ... | |
}
|
||
}
|
||
|
||
typedef struct {
|
||
typedef struct { //*
|
||
float latitude;
|
||
float longitude;
|
||
} Position;
|
||
|
||
int decode_trame(char * trame, Position *p){
|
||
char longi[10];
|
||
char longi[10]={'\0'}; //*** trame -> @ lati -> @
|
||
char lati[9];
|
||
int cpt = 0;
|
||
int i = 0;
|
||
... | ... | |
while (trame[i] != '\0'){
|
||
if (trame[i] == ','){ //On compte le nombre de virgule.
|
||
cpt += 1;
|
||
i ++;
|
||
i += 1;
|
||
}
|
||
if (cpt == 2) { //On regarde si le nombre de virgule correspond ? 2, ie la latitude
|
||
lati[j] = trame[i]; //On stocke caract?re par caract?re pour isoler la latitude afin de la convertir.
|
||
j ++;
|
||
}
|
||
if (cpt == 4) { //On regarde si le nombre de virgule correspond ? 4, ie la longitude
|
||
longi[y] = trame[i]; //On stocke caract?re par caract?re pour isoler la longitude afin de la convertir.
|
||
longi[y] = trame[i];
|
||
y ++;
|
||
}
|
||
i ++;
|
||
i += 1;
|
||
}
|
||
p->latitude = conv_lat(lati);
|
||
p->latitude = conv_lat(lati); //***************** vous avez de la chance &trame[15], trame+15
|
||
|
||
p->longitude = conv_long(longi); //On stocke la latitude et la longitude convertie dans structure position.
|
||
return 1;
|
||
}
|
||
... | ... | |
}
|
||
|
||
float calcule_vitesse(Position p_1, Position p_2){
|
||
return calcule_distance(p_1,p_2)*3600; //On calcul la vitesse avec la formule v=d/t avec t=1s.
|
||
return calcule_distance(p_1,p_2)*3600; //On calcul la vitesse (en km) avec la formule v=d/t avec t=1s.
|
||
}
|
||
|
||
typedef struct{
|
||
... | ... | |
|
||
int distance_a_la_plus_poche_zone(Position p, Zone r[], int nb_zones, float *d){
|
||
int index = 0;
|
||
float distance = calcule_distance(p, r[0].rpos); //On initialise une distance pour pouvoir ensuite la comparer et chercher le minimum.
|
||
*d = calcule_distance(p, r[0].rpos); //On initialise une distance pour pouvoir ensuite la comparer et chercher le minimum.
|
||
for (int i = 1; i<nb_zones; i++){ //On parcours la table de zone dangereuse.
|
||
if (calcule_distance(p,r[i].rpos) < distance){
|
||
if (calcule_distance(p,r[i].rpos) < *d){
|
||
index = i;
|
||
distance = calcule_distance(p,r[i].rpos);
|
||
*d = calcule_distance(p,r[i].rpos);
|
||
}
|
||
}
|
||
*d = distance;
|
||
return index;
|
||
}
|
||
|
||
Position pos_prec;
|
||
|
||
//Fonction ? modifier !!!!!
|
||
|
||
void traitement(char * trame){
|
||
Position pos;
|
||
int alarme;
|
branch/best/sp4b2/SPAb2/SPAb2/SPAb2.c | ||
---|---|---|
void lcd_str(unsigned char *str); // envoi d'une cha?ne de caract?re
|
||
void lcd_car(unsigned char car);// envoi d'une donn?e ? afficher
|
||
void clav_init(void); //initialisation du clavier
|
||
void clavier(void); // detection des touches du clavier
|
||
void affichage(unsigned char *str); // Affichage sur l'ecran
|
||
|
||
|
||
void main(void)
|
||
{
|
||
char t;
|
||
char touche = 0;
|
||
lcd_init();
|
||
clav_init();
|
||
while(1)
|
||
{
|
||
t = p10; //**
|
||
if(t !=0xf0)
|
||
{
|
||
p10 = 0xfe;
|
||
t = p10;
|
||
if (t==0xbe)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD //**********
|
||
tpo_ms(50); //**
|
||
touche = '1'; //**
|
||
lcd_str("50 Km/h");
|
||
}
|
||
if (t==0xde)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50); //******
|
||
touche = '2';
|
||
lcd_str("70 Km/h");
|
||
}
|
||
if (t==0x7e)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '3';
|
||
lcd_str("90 Km/h");
|
||
}
|
||
p10 = 0xfd;
|
||
t = p10;
|
||
if (t==0xbd)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '4';
|
||
lcd_str("110 Km/h");
|
||
}
|
||
if (t==0xdd)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '5';
|
||
lcd_str("130 Km/h");
|
||
}
|
||
if (t==0x7d)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '6';
|
||
lcd_str("...");
|
||
}
|
||
p10 = 0xfb;
|
||
t = p10;
|
||
if (t==0x7b)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '9';
|
||
lcd_str("...");
|
||
}
|
||
if (t==0xdb)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '8';
|
||
lcd_str("...");
|
||
}
|
||
if (t==0xeb)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '7';
|
||
lcd_str("Ajout Zone");
|
||
}
|
||
p10 = 0xf7;
|
||
t = p10;
|
||
if (t==0xd7)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '0';
|
||
lcd_str("Arret Alarme");
|
||
}
|
||
if (t==0x77)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '#';
|
||
lcd_str("#");
|
||
}
|
||
if (t==0xe7)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '*';
|
||
lcd_str("*");
|
||
}
|
||
p10 = 0xf;
|
||
t = p10;
|
||
if (t==0xbe)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '1';
|
||
lcd_str("50 Km/h");
|
||
}
|
||
if (t==0xde)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '2';
|
||
lcd_str("70 Km/h");
|
||
}
|
||
if (t==0x7e)
|
||
{
|
||
lcd_com(0x01,0); //Clear LCD
|
||
tpo_ms(50);
|
||
touche = '3';
|
||
lcd_str("90 Km/h");
|
||
}
|
||
t = p10;
|
||
|
||
if (t != 0xF0){
|
||
clavier();
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
void lcd_4b(unsigned char car){
|
||
... | ... | |
void lcd_init(void){
|
||
pd3 = 0xFF; //initialisation des ports en sorties
|
||
tpo_ms(15);
|
||
lcd_4b(0x30,0);
|
||
lcd_4b(0x30);
|
||
tpo_ms(5);
|
||
lcd_4b(0x30,0);
|
||
lcd_4b(0x30);
|
||
tpo_us(100);
|
||
lcd_4b(0x30,0);
|
||
lcd_4b(0x30);
|
||
tpo_us(100);
|
||
lcd_4b(0x20,0); //mode 4 bits activ?
|
||
lcd_com(0x28,0); //mode 4bits - 2 lignes 0x20 4 bits | 0x08 2 lignes
|
||
lcd_com(0x06,0); //Incremente vers la gauche
|
||
lcd_com(0x0E,0); //LCD ? on, curseur ? on
|
||
lcd_com(0x01,0); //Clear LCD
|
||
lcd_4b(0x20); //mode 4 bits activ?
|
||
lcd_com(0x28); //mode 4bits - 2 lignes 0x20 4 bits | 0x08 2 lignes
|
||
lcd_com(0x06); //Incremente vers la gauche
|
||
lcd_com(0x0E); //LCD ? on, curseur ? on
|
||
lcd_com(0x01); //Clear LCD
|
||
tpo_ms(5);
|
||
}
|
||
|
||
|
||
/*void _tp_prolog(){
|
||
}*/
|
||
void tpo_us(unsigned short duree){
|
||
tcspr = 0x8A;
|
||
ta0mr = 0x82;
|
||
... | ... | |
pu31 = 1;
|
||
p10 = 0;
|
||
}
|
||
|
||
void clavier(void){
|
||
unsigned char t;
|
||
|
||
p10 = 0x0E;
|
||
t = p10;
|
||
if (t == 0xBE){
|
||
affichage("50 Km/h");
|
||
}
|
||
|
||
if (t == 0xDE){
|
||
affichage("70 Km/h");
|
||
}
|
||
|
||
if (t == 0x7E){
|
||
affichage("90 Km/h");
|
||
}
|
||
|
||
p10 = 0x0D;
|
||
t = p10;
|
||
if (t == 0xBD){
|
||
affichage("110 Km/h");
|
||
}
|
||
|
||
if (t == 0xDD){
|
||
affichage("130 Km/h");
|
||
}
|
||
|
||
if (t == 0x7D){
|
||
affichage("...");
|
||
}
|
||
|
||
p10 = 0x0B;
|
||
t = p10;
|
||
if (t == 0xEB){
|
||
affichage("Ajout Zone");
|
||
}
|
||
|
||
if (t == 0xDB){
|
||
affichage("...");
|
||
}
|
||
|
||
if (t == 0x7B){
|
||
affichage("...");
|
||
}
|
||
|
||
p10 = 0x07;
|
||
t = p10;
|
||
if (t == 0xE7){
|
||
affichage("*");
|
||
}
|
||
|
||
if (t == 0xD7){
|
||
affichage("Arret Alarme");
|
||
}
|
||
|
||
if (t == 0x77){
|
||
affichage("#");
|
||
}
|
||
}
|
||
|
||
void affichage(unsigned char *str){
|
||
lcd_com(0x01);
|
||
tpo_ms(50);
|
||
lcd_str(str);
|
||
}
|
branch/best/sp4b3/SP4b3/SessionM32C_E8a_SYSTEM.ini | ||
---|---|---|
PROCESSOR_MODE=0
|
||
[COMMUNI]
|
||
COMSPEED=8
|
||
COMSPEED PROGRAM FLASH=8
|
||
COMSPEED DATA FLASH=8
|
||
[Driver Configuration]
|
||
Renesas Communications=USB interface,0,
|
||
[Target]
|
branch/best/sp4b3/SP4b3/SP4b3.c | ||
---|---|---|
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
|
||
/***********************************************************************/
|
||
|
||
|
||
void main(void)
|
||
{
|
||
|
Formats disponibles : Unified diff
Optimisation du code pour le clavier matricé et des fonctions des premières séances