/********************************************************** Projet : tp3_s.prj Fichier(s) : TP_3s.c Objet : Gestion d'un depart de rally et chronometrage Auteurs : Hensinger Benoît / Cuenot Gaël Binome : 3 Groupe : RLI 1 Date création : **********************************************************/ // Fichiers à inclure : #include // Commandes du moniteur de mise au point #include // déclaration des registres interne au µC 80C535(SFR) #include // Commandes de l'afficheur LCD #include // Equivalences : #define OFF 0 #define ON 1 // Fonctions externes : // Fonctions locales (Prototypes) : void tempo(unsigned int); // Fonction temporisation (delai) void tempo_hard(unsigned int t); //Fonction tempo materielle void mode_car(void); // Fonction compte a rebours void mode_fodep(void); // Fonction faux depart void mode_chrono(void); // Fonction chronometrage void IRQ_P10(void) interrupt 10 using 1; // Sous programme d'interruption sur P1.0 void IRQ_P15_T2(void) interrupt 5 using 1; // SOus programme d'interruption sur P1.5 et T2 void IRQ_P14(void) interrupt 9 using 1; // Sous programme d'inerruption sur P1.4 void IRQ_P11(void) interrupt 11 using 1; // Sous programme d'interruption sur P1.1 // Definitions particulières (zone SFR ou RAM externe) : at 0xCC sfr16 THL2; at 0xCA sfr16 CRCHL; // Variables Globales : char tab_feu[4]={0x04,0x04,0x02,0x01}; int mode,feux; int cpt,free_cpt,i,fo_dep; bit stop=0; unsigned char sec,ms; // ================ ZONE PROGRAMME ============================== /******************************************************** Nom : main() Objet : Initialisation et lancement des differents sous-programmes Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void main () { clrscr(); printf("--> TP 3.S OFF<-\n"); //1ere ligne printf(" Attente depart "); //2eme ligne P4=0; P5=0; // Initialisation du Timer T2 CRCHL=-10000/1; // Periode T2 = 10 ms THL2=CRCHL; // initialisation de T2 T2PS=0; // Ftimer = Fq/12 T2R0=0; // Mode 0 auto-reload T2R1=1; T2I0=1; // Mode timer T2I1=0; TF2=0; // Reset du flag de T2 ET2=1; // Autoriasation IRQ de T2 // Interruption sur P1.0 (depart compte a rebour) I3FR=0; // Front Descendant sur P1.0 IEX3=0; // Reset du drapeaux EX3=1; // Autorisation IRQ // Interruption sur P1.1 (Reset) IEX4=0; // Reset du flag EX4=0; // Inhibition IRQ //Interruption sur P1.4 (Arret) I2FR=0; // Front descendant sur P1.4 IEX2=0; // Reset flag EX2=0; //Inhibition IRQ //Interruption sur P1.5 (Faux depart) EXF2=0; // Reset du flag EXEN2=0; // Inhibiton IRQ individuelle de P1.5 ET2=1; // Autorisation IRQ pour T2 et P1.5 // Priorite max (3) sur P1.5/T2 et priorite 0 pour les autres (P1.0, P1.1 et P1.4) IP0=(IP0 & 0xCC)|0x20; IP1=(IP1 & 0xCC)|0x20; EAL=1; // Autorisation globale des IRQ mode=4; // Boucle infinie while(1) { switch(mode) { case 0: // Mode compte a rebour mode_car(); break; case 1: // Mode chrono mode_chrono(); break; case 2: // Mode faux depart mode_fodep(); break; default: break; } } } // end main /******************************************************** Nom : IRQ_P10 Objet : Sous programme d'interruption de P1.0 Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P10(void) interrupt 10 using 1 { tempo(100); // Anti rebonds logiciel EX4=0; // Inhibition de P1.5 IEX3=0; // Reset du flag de P1.0 stop=0; mode=0; printf("\n\nmode = %d",mode); // 2e ligne LCD ET2=1; // Autorisation IRQ du timer mode_car(); IEX3=0; // Reset flag de P1.0 } /******************************************************** Nom : IRQ_P15_T2 Objet : Sous programme d'interruption de P1.5 et T2 Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P15_T2(void) interrupt 5 using 1 { if(TF2 == 1) { TF2=0; free_cpt++; } else { mode=2; stop=1; EXF2=0; // Reset du flag de P1.5 } } /******************************************************** Nom : IRQ_P14 Objet : Sous programme d'interruption de P1.4 Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P14(void) interrupt 9 using 1 { tempo(100); EX4=1; // Autorisation de P1.1 pour reset IEX2=0; // Reset du flag de P1.4 } /******************************************************** Nom : IRQ_P11 Objet : Sous programme d'interruption de P1.1 Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P11(void) interrupt 11 using 1 { tempo(100); //Anti rebond IEX4=0; //Reset du flag sur P1.1 ms=0; sec=0; EX2=0; //Inhibition de P1.4 IEX3=0; // Reset du flag de P1.0 EX3=1; //Autorisation de P1.0 ET2=0; //Inhibition des interruptions sur T2 printf("\n\n %d\" %d ",sec,ms); // 2e ligne LCD } /******************************************************** Nom : mod_car Objet : Compte a rebours Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void mode_car(void) { feux=0; EX2=0; //Inhibition de P1.4 dans la phase de cpt a rebours while(feux<4) { P4=(P4 & 0xC0) | tab_feu[feux]; // Affichage des feux feux++; printf("\n\nDepart dans: %d ",feux); // 2e ligne LCD tempo_hard(100); // tempo materielle d'1 seconde } mode=1; EXEN2=1; //Autorisation de P1.5 EX2=1; //Autoriation de P1.4 } /******************************************************** Nom : mode_chrono Objet : Chronometre Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void mode_chrono(void) { EX3=0; //Inhibition de P1.0 EXEN2=0; //Inhibition de P1.5 (plus de faux depart) EX4=0; //Inhibition de P1.1 EX2=1; //Autorisation de P1.4 cpt=free_cpt+1; ms=ms+1; printf("\n\n %d\" %d ",sec,ms); // 2e ligne LCD if(ms==100) { sec++; ms=0; } while(free_cpt != cpt); } /******************************************************** Nom : mod_fodep Objet : Faux depart Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void mode_fodep(void) { printf("\n\n-->Faux depart<-"); // 2e ligne LCD P4=0; // Exctinction de toute les LED de P4 P5=0; // Exctinction de toute les LED de P5 fo_dep=1; mode=4; } /******************************************************** Nom : tempo_hard Objet : base de temps materielle de 1 ms Paramètres : - d'appel : durée de la tempo en dizaine de ms - de retour : aucun *********************************************************/ void tempo_hard(unsigned int t) { cpt=free_cpt+t; while(free_cpt != cpt); } // end tempo /******************************************************** Nom : tempo Objet : base de temps logicielle de 1 ms Paramètres : - d'appel : durée de la tempo en ms - de retour : aucun *********************************************************/ void tempo(unsigned int t) { int ttempo; while (t != 0) { for (ttempo = 1;ttempo < 493;ttempo++); t--; // décrémentation de la variable de contrôle } } // end tempo