/********************************************************** Projet : tp3_s.prj Fichier(s) : TP_3s.c Objet : Introduction au C sur microcontroleur Gestion des entrees / sorties 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 #define STOP 0 // 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); void mode_fodep(void); void mode_chrono(void); void IRQ_P10(void) interrupt 10 using 1; void IRQ_P15_T2(void) interrupt 5 using 1; void IRQ_P14(void) interrupt 9 using 1; void IRQ_P11(void) interrupt 11 using 1; // Definitions particulières (zone SFR ou RAM externe) : at 0x90 sbit in_bpmode; // in_bpmode est le nom donné à la ligne P1.0 (adr. 0x90) at 0xFC sbit out_led; // out_led est le nom donné à la led P5.4 (jour) 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 : gestion de la led on/off P5.4 par le bouton mode P1.0 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; THL2=CRCHL; T2PS=0; T2R0=0; T2R1=1; T2I0=1; T2I1=0; TF2=0; ET2=1; //Interruption sur P1.0 (depart compte a rebour) I3FR=0; // Front Descendant sur P1.0 IEX3=0; // Reset du drapeaux EX3=1; //autorisation IRQ //Inhibition de l interruption P1.1 IEX4=0; EX4=0; //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; EXEN2=0; //Inhibiton de P1.5 ET2=1; IP0=(IP0 & 0xCC)|0x20; //Priorite 0 sur /INT3,/INT2 IP1=(IP1 & 0xCC)|0x20; EAL=1; 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 : Objet : Lancement 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; stop=0; mode=0; printf("\n\nmode = %d",mode); ET2=1; mode_car(); IEX3=0; // Reset flag } /******************************************************** Nom : timer Objet : Mise a l'arret 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 { //printf("-->Faux depart<-"); mode=2; stop=1; EXF2=0; } } /******************************************************** Nom : mod_car() Objet : Arret Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P14(void) interrupt 9 using 1 { //chrono=STOP; tempo(100); EX4=1; //Autorisation de P1.1 pour reset IEX2=0; } /******************************************************** Nom : reset() Objet : Reset du chrono 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; EX3=1; //Autorisation de P1.0 ET2=0; //Inhibition des interruptions sur T2 printf("\n\n %d\" %d ",sec,ms); //mode=0; } /******************************************************** Nom : mod_car() Objet : Compte a rebours Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void mode_car(void) { // CRCHL=-10000/1; // THL2=CRCHL; feux=0; EX2=0; //Inhibition de P1.4 dans la phase de cpt a rebours while(feux<4) { P4=(P4 & 0xC0) | tab_feu[feux]; feux++; printf("\n\nDepart dans: %d ",feux); tempo_hard(100); } mode=1; EXEN2=1; //Autorisation de P1.5 EX2=1; //Autoriation de P1.4 } /******************************************************** Nom : Chronometre Objet : Mise a l'arret 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; //free_cpt+1; ms=ms+1; printf("\n\n %d\" %d ",sec,ms); 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<-"); P4=0; P5=0; 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 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