root/branch/AMAR/sp4b3/SP4b3/SP4b3.c @ 791
529 | pdamar | /***********************************************************************/
|
|
/* */
|
|||
/* FILE :SP4b3.c */
|
|||
/* DATE :Wed, May 26, 2021 */
|
|||
/* DESCRIPTION :main program file. */
|
|||
/* CPU GROUP :87B */
|
|||
/* */
|
|||
/* This file is generated by Renesas Project Generator (Ver.4.18). */
|
|||
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
|
|||
/***********************************************************************/
|
|||
530 | pdamar | #include "sfr32c87.h"
|
|
537 | pdamar | #include <stdio.h>
|
|
#include <stdlib.h>
|
|||
#include <strings.h>
|
|||
#include "trame.h"
|
|||
#include <math.h>
|
|||
typedef struct // declaration du type position compos? de la latitude et la longitude
|
|||
{
|
|||
float latitude;
|
|||
float longitude;
|
|||
} position;
|
|||
typedef struct // declaration du type zone compos? de la position et la vitesse maximale
|
|||
{
|
|||
position rpos;
|
|||
float vitmax;
|
|||
} zone;
|
|||
#define Rayon 6378.1370
|
|||
//Trames de tests ? modifier si n?cessaire.
|
|||
char * trames[]= {"$GPGSV,3,2,10,15,03,077,,18,04,041,42,19,85,271,,20,08,214,*7C",
|
|||
"$GPGSV,3,3,10,22,39,053,50,28,15,320,*7E",
|
|||
"$GPRMC,141914.00,A,4545.6424,N,00306.6036,E,0.4,99.4,010206,,*0C",
|
|||
"$GPGLL,4545.6424,N,00306.6036,E,141914.00,A*0E",
|
|||
"$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",
|
|||
"$GPGGA,141925.00,4545.2410,N,00306.6046,E,1,05,3.4,501.4,M,,M,,*7D"
|
|||
"$GPGSA,A,3,,03,,22,14,,01,,18,,,,3.9,3.4,1.9*39",
|
|||
"$GPVTG,99.4,T,,M,0.4,N,0.7,K*57",
|
|||
"$GPZDA,141914.00,01,02,2006,00,00*69",
|
|||
0};
|
|||
zone zones[] = // declaration d'un tableau de zones
|
|||
{
|
|||
{{44.78887762, -3.012}, 50},
|
|||
{{44.7891220, -3.013}, 70},
|
|||
{{46.7501,3.1101},50}
|
|||
};
|
|||
530 | pdamar | void init_keyboard(void);
|
|
void tpo_50ms(void) ;
|
|||
unsigned char touche = 0;void main(void){
|
|||
char t;
|
|||
pu31=1;
|
|||
pd10=0x00;
|
|||
while (1){
|
|||
537 | pdamar | if (( t & 0xF0)!= 0xf0 ){
|
|
530 | pdamar | p10=0;
|
|
}
|
|||
537 | pdamar | if (( t & 0xF0)!= 0xf0 ){
|
|
530 | pdamar | t=p10 ;
|
|
p10=~0x0F;
|
|||
}
|
|||
537 | pdamar | if (( t & 0xF0)!= 0xf0 ){
|
|
530 | pdamar | p10=14;
|
|
t=p10;}
|
|||
537 | pdamar | if (( t & 0xF0)!= 0xf0 ){
|
|
530 | pdamar | ||
p10=0x0D;
|
|||
t=p10;
|
|||
}
|
|||
537 | pdamar | if (( t & 0xF0)!= 0xf0 ){
|
|
530 | pdamar | p10=0x07;
|
|
t=p10;
|
|||
}
|
|||
}
|
|||
}
|
|||
void lcd_4b (char c)
|
|||
{
|
|||
537 | pdamar | pd1=0xFF;
|
|
530 | pdamar | ||
c=0b10000000;
|
|||
if(c&0b10000000)
|
|||
p1_7=1;
|
|||
else
|
|||
p1_7=0;
|
|||
if(c&0b10000000)
|
|||
p1_6=1;
|
|||
else
|
|||
p1_6=0;
|
|||
if(c&0b10000000)
|
|||
p1_5=1;
|
|||
else
|
|||
p1_5=0;
|
|||
if(c&0b10000000)
|
|||
p1_4=1;
|
|||
else
|
|||
p1_4=0;
|
|||
if(c&0b10000000)
|
|||
p1_2=1;
|
|||
else
|
|||
p1_2=0;
|
|||
}
|
|||
537 | pdamar | ||
530 | pdamar | void main (void){
|
|
lcd_4b (0xF0);
|
|||
lcd_4b (0xFA);
|
|||
}
|
|||
void lcd_8b (char c)
|
|||
{
|
|||
lcd_4b(c<<4);
|
|||
}
|
|||
lcd_com(c)
|
|||
{
|
|||
p1_0=0;
|
|||
lcd_8b(c);
|
|||
}
|
|||
lcd_car(char c)
|
|||
{
|
|||
p1_0 = 0;
|
|||
lcd_8b(c);
|
|||
537 | pdamar | }
|
|
void test_decode_trame(void)
|
|||
{
|
|||
if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&test_position)!=1)
|
|||
{
|
|||
printf("Erreur Test decode trame \n");
|
|||
exit(-1);
|
|||
}
|
|||
}
|
|||
float calcul_vitesse(position pos1,position pos2) // fonction qui calcule la distance entre deux positions
|
|||
{
|
|||
float vitesse;
|
|||
vitesse=3600*(calcul_distance(pos1,pos2)*Rayon);
|
|||
return vitesse;
|
|||
}
|
|||
int distance_a_la_plus_proche_zone(position p,zone r[],int nb_zones,float *d) // fonction qui calcule la distance la plus proche
|
|||
{
|
|||
int index=0;
|
|||
int i;
|
|||
*d=fabs(calcul_distance(p,r[0].rpos)); // initialisation du minimum
|
|||
float t;
|
|||
if (nb_zones>0)
|
|||
{
|
|||
for (i=1;i<nb_zones;i++)
|
|||
{
|
|||
t=fabs(calcul_distance(p,r[i].rpos));
|
|||
if (t<*d)
|
|||
{
|
|||
*d=t;
|
|||
index=i;
|
|||
}
|
|||
}
|
|||
return index;
|
|||
}
|
|||
return -1;
|
|||
}
|
|||
void test_distance_plus_proche(void) //
|
|||
{
|
|||
position p;
|
|||
p.latitude =45.75;
|
|||
p.longitude=3.110060;
|
|||
int num_zone;
|
|||
float d ;
|
|||
num_zone=distance_a_la_plus_proche_zone(p,zones,sizeof(zones),&d);
|
|||
if (num_zone!=2 & fabs(d-44.85)>0.5)
|
|||
{
|
|||
printf(("erreur test distance la plus proche "));
|
|||
exit(-1);
|
|||
}
|
|||
}
|