Révision 487
Ajouté par hanzhang1 il y a plus de 6 ans
branch/zhang/Emb_App/SessionM32C_E8a_system.ini | ||
---|---|---|
[Target]
|
||
M32C E8a SYSTEM=Renesas Communications
|
||
[USER_DATA]
|
||
RESET=ff0186
|
||
RESET=ff018a
|
branch/zhang/Emb_App/programme_principal_etud.c | ||
---|---|---|
int feu; //feu tricolore
|
||
int a;
|
||
int b;
|
||
int temps;
|
||
|
||
void main()
|
||
{
|
||
ports_mcu();
|
||
lcd_init();
|
||
periph_init();
|
||
periph_nom("zhang");
|
||
periph_nom(" Zhang");
|
||
|
||
can_init();
|
||
clavier_init(1);
|
||
... | ... | |
|
||
// sta_cyc(ID_asserv);
|
||
|
||
sta_tsk(ID_capteur_couleur);
|
||
sta_tsk(ID_zone);
|
||
sta_tsk(ID_capteur_couleur);
|
||
sta_tsk(ID_piste);
|
||
sta_tsk(ID_comm_feu);
|
||
sta_tsk(ID_control_tourelle);
|
||
sta_tsk(ID_control_direct);
|
||
sta_tsk(ID_timez);
|
||
|
||
sta_tsk(ID_vitesse);
|
||
|
||
|
||
sta_cyc(ID_affiche);
|
||
|
||
|
||
... | ... | |
periph[ADDR('C')].ev=0x03; // event mise au 0x01
|
||
snd_dtq(CanTx, requete.msg); //send demendes
|
||
|
||
wai_flg (ev_periph,0x03,TWF_ANDW,&flag); //wait reponse
|
||
wai_flg (ev_periph,0x03,TWF_ANDW,&flag); //wait reponse*
|
||
|
||
touche_couleur = periph[ADDR('C')].val;
|
||
b = touche_couleur & 0xFF00;
|
||
|
||
dly_tsk(10);
|
||
dly_tsk(7);
|
||
}
|
||
}
|
||
|
||
... | ... | |
a = periph[ADDR('M')].val;
|
||
|
||
pist = a & 0x00FF; //1Vert 2Bleu 3Rouge 4Roir
|
||
feu = (a & 0x8000)>>15; //1:vert feu
|
||
feu = (a & 0x8000)>>15; //1: feu Vert
|
||
|
||
dly_tsk(10);
|
||
dly_tsk(7);
|
||
}
|
||
}
|
||
|
||
void comm_feu(){
|
||
|
||
CanFrame requete,comm;
|
||
FLGPTN flag;
|
||
|
||
a = a & 0x7fff; //set feu est rouge
|
||
comm.data.id = 'M'; // vitesse de tourelle
|
||
comm.data.rtr = 0;
|
||
comm.data.val = a; //command feu est vert
|
||
snd_dtq(CanTx, comm.msg); //send command
|
||
dly_tsk(300);
|
||
|
||
comm.data.id = 'M'; // vitesse de tourelle
|
||
comm.data.rtr = 0;
|
||
comm.data.val = a|0x8000; //command feu est vert
|
||
snd_dtq(CanTx, comm.msg); //send command
|
||
|
||
|
||
void timez(){
|
||
CanFrame requete;
|
||
FLGPTN flag;
|
||
while(1)
|
||
{
|
||
requete.data.id ='H';
|
||
requete.data.rtr = 1;
|
||
periph[ADDR('H')].ev=0x05;
|
||
snd_dtq(CanTx, requete.msg);
|
||
|
||
wai_flg (ev_periph,0x05,TWF_ANDW,&flag); //wait reponse
|
||
temps = periph[ADDR('H')].val; //ms
|
||
|
||
|
||
|
||
dly_tsk(7);
|
||
}
|
||
}
|
||
|
||
void zone(){ // lecture pist et feu
|
||
CanFrame requete;
|
||
FLGPTN flag;
|
||
|
||
while(1){
|
||
requete.data.id = 'C'; // angle de tourelle
|
||
requete.data.rtr = 1; //indique une requ?te(demende) de lecture
|
||
periph[ADDR('C')].ev=0x06; // event mise au 0x01
|
||
snd_dtq(CanTx, requete.msg); //send demendes
|
||
|
||
wai_flg (ev_periph,0x06,TWF_ANDW,&flag); //wait reponse
|
||
b = periph[ADDR('C')].val;
|
||
dly_tsk(10);
|
||
}
|
||
}
|
||
|
||
/******************************************************************************/
|
||
void control_direct(){
|
||
CanFrame requete, reponse, comm;
|
||
... | ... | |
c = distance - 900;
|
||
if(distance<670 || distance>1200) c = 0;
|
||
}
|
||
if( touche_couleur == 0x4203) {
|
||
if(distance<300|| distance>1200)
|
||
c = 0;
|
||
}
|
||
if( touche_couleur == 0x5602) {
|
||
if(distance<680|| distance>725) distance = 705;
|
||
c = 1*(distance - 705);
|
||
if(distance<680|| distance>730)
|
||
c = 0;
|
||
}
|
||
if( touche_couleur == 0x5603) {
|
||
c = kd *( distance - 705);
|
||
if(distance<700 || distance>730) c = 0;
|
||
c = distance - 705;
|
||
if(distance<680 || distance>720) c = 0;
|
||
}
|
||
}
|
||
|
||
... | ... | |
comm.data.val = c;
|
||
snd_dtq(CanTx, comm.msg);
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/****************************************************************************/
|
||
void affiche(){
|
||
char str1[20];
|
||
char str2[20];
|
||
char str3[20];
|
||
|
||
lcd_com(0xC0);
|
||
if(pist == 1)
|
||
lcd_str("piste vert ");
|
||
if(pist == 2)
|
||
lcd_str("piste bleu ");
|
||
if(pist == 3)
|
||
lcd_str("piste rouge ");
|
||
if(pist == 4)
|
||
lcd_str("piste noir ");
|
||
|
||
lcd_com(0x90);
|
||
if((b&0x0001) == 0x0001)
|
||
lcd_str("zone Vert");
|
||
if((b&0x0002) == 0x0002)
|
||
lcd_str("zone Jaune");
|
||
if((b&0x0004) == 0x0004)
|
||
lcd_str("zone Rouge");
|
||
if((b&0x0008) == 0x0008)
|
||
lcd_str("zone Bleu");
|
||
if((b&0x0010) == 0x0010)
|
||
lcd_str("zone Cyan");
|
||
|
||
lcd_com(0xD0);
|
||
sprintf(str3," %x ", touche_couleur);
|
||
lcd_str(str3);
|
||
char str1[20];
|
||
char str2[20];
|
||
char str3[20];
|
||
|
||
lcd_com(0xC0);
|
||
if(pist == 1)
|
||
lcd_str("piste vert ");
|
||
if(pist == 2)
|
||
lcd_str("piste bleu ");
|
||
if(pist == 3)
|
||
lcd_str("piste rouge ");
|
||
if(pist == 4)
|
||
lcd_str("piste noir ");
|
||
|
||
lcd_com(0x90);
|
||
switch(b){
|
||
case 0x5600:
|
||
lcd_str("zone vert");
|
||
break;
|
||
case 0x4200:
|
||
lcd_str("zone bleu");
|
||
break;
|
||
case 0x5200:
|
||
lcd_str("zone rouge");
|
||
break;
|
||
case 0x4a00:
|
||
lcd_str("zone jaune");
|
||
break;
|
||
case 0x4300:
|
||
lcd_str("zone cyan");
|
||
break;
|
||
}
|
||
lcd_com(0xD0);
|
||
sprintf(str3,"%d ms ", temps);
|
||
lcd_str(str3);
|
||
}
|
||
|
||
/*******************************************************************************/
|
||
void vitesse(){
|
||
CanFrame comm;
|
||
... | ... | |
|
||
if(feu==1){ // feu est vert,demarre normalement
|
||
|
||
if(Bp_G==1) v=0; // arret urgence
|
||
else{
|
||
if(Bp_G==1) {
|
||
v=0; // arret urgence
|
||
LED_R=1;
|
||
}
|
||
else{
|
||
LED_R = 0;
|
||
if ( distance<680 || distance>750) v = 20;
|
||
else v = 50;
|
||
else v = 30;
|
||
|
||
if(pist == 3){// rouge piste
|
||
if( touche_couleur == 0x5601) v = 20;
|
||
... | ... | |
}
|
||
if(pist == 4){//piste noir
|
||
if( touche_couleur == 0x4a01) v = 10;
|
||
if( touche_couleur == 0x4203) v = 17;
|
||
if( touche_couleur == 0x5202) v = 10;
|
||
if( touche_couleur == 0x4203) v = 13;
|
||
if( touche_couleur == 0x5601) v = 20;
|
||
if( touche_couleur == 0x5602) v = 12;
|
||
if( touche_couleur == 0x5602) v = 8;
|
||
if( touche_couleur == 0x5603) v = 43;
|
||
if( touche_couleur == 0x5604) v = 11;
|
||
if( touche_couleur == 0x5604) v = 9;
|
||
}
|
||
}
|
||
}
|
||
else v =0; // feu n'est pas vert, arret
|
||
|
||
else {
|
||
v =0; // feu n'est pas vert, arret
|
||
LED_R=1;
|
||
}
|
||
comm.data.id = 'V';
|
||
comm.data.rtr = 0;
|
||
comm.data.val = v;
|
||
... | ... | |
}
|
||
}
|
||
|
||
|
||
/*
|
||
void control_tourelle(){
|
||
// Q5 obtenir l'angle
|
||
// et commande la vitesse de tourelle(asservissement)
|
||
CanFrame requete, reponse, comm;
|
||
int a;
|
||
while(1){
|
||
requete.data.id = 'R'; // angle de tourelle
|
||
requete.data.rtr = 1; //indique une requ?te(demende) de lecture
|
||
snd_dtq(CanTx, requete.msg); //send demendes
|
||
|
||
rcv_dtq(CanRx, &reponse.msg); //mise a reponse.msg
|
||
alpha = reponse.data.val; //recu le val de angle de tourelle
|
||
|
||
|
||
if(alpha > 900 ) a = 0; // alpha >90? stop move
|
||
else a = ad00 - alpha; // vitesse = consigne - position
|
||
comm.data.id = 'T'; // vitesse de tourelle
|
||
comm.data.rtr = 0;
|
||
comm.data.val = a; //val de command est c-p
|
||
snd_dtq(CanTx, comm.msg); //send command
|
||
}
|
||
}
|
||
*/
|
||
|
||
/* Q 1 2 3
|
||
void vitesse_T(){
|
||
//la vitesse de tourelle par un moteur (T)
|
||
int a;
|
||
CanFrame comm;
|
||
while (1){
|
||
if(alpha > 900 ) a = 0;
|
||
a = 450 - alpha;
|
||
comm.data.id = 'T';
|
||
comm.data.rtr = 0;
|
||
comm.data.val = a;
|
||
snd_dtq(CanTx, comm.msg);
|
||
}
|
||
}
|
||
|
||
void angle_T(){
|
||
//l'angle de tourelle
|
||
|
||
|
||
CanFrame requete, reponse;
|
||
while(1){
|
||
requete.data.id = 'R';
|
||
requete.data.rtr = 1; //indique une requ?te de lecture
|
||
snd_dtq(CanTx, requete.msg);
|
||
|
||
rcv_dtq(CanRx, &reponse.msg);
|
||
alpha = reponse.data.val;
|
||
}
|
||
}
|
||
*/
|
||
|
branch/zhang/Emb_App/conf_noyau.cfg | ||
---|---|---|
exinf = 0x0;
|
||
};
|
||
task[]{
|
||
entry_address = comm_feu();
|
||
name = ID_comm_feu;
|
||
entry_address = timez();
|
||
name = ID_timez;
|
||
stack_size = 256;
|
||
stack_section = stack;
|
||
priority = 2;
|
||
initial_start = OFF;
|
||
exinf = 0x0;
|
||
};
|
||
task[]{
|
||
entry_address = zone();
|
||
name = ID_zone;
|
||
stack_size = 256;
|
||
stack_section = stack;
|
||
priority = 2;
|
||
initial_start = OFF;
|
||
exinf = 0x0;
|
||
};
|
||
|
||
|
||
|
||
flag[]{
|
||
name = ev_bus_fin_tr;
|
||
initial_pattern = 0x0000;
|
Formats disponibles : Unified diff