/********************************************************** Projet : tp2_2.prj Fichier(s) : TP2_2.c Objet : les Entrees/Sortie gestion des priorites entre interruptions Auteurs : Hensinger Benoît / Cuenot Gaël 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 MARCHE 1 #define ARRET 0 #define DROITE 0 #define GAUCHE 1 // Fonctions externes : // Fonctions locales (Prototypes) : void tempo(unsigned int); // Fonction temporisation (delai) void IRQ_P11(void) interrupt 11 using 1; void IRQ_P10(void) interrupt 10 using 1; void IRQ_P14(void) interrupt 9 using 1; void IRQ_P15(void) interrupt 5 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) // Variables Globales : bit etat; bit sens; code unsigned char Tab_Val[4]={0x10,0x20,0x40,0x80}; int i; // ================ ZONE PROGRAMME ============================== /******************************************************** Nom : main() Objet : allumage successive des leds off/clig/nuit... Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void main () { clrscr(); printf("--> TP 2.2 OFF<-\n"); //1ere ligne printf("ROTATION DROITE \n\n"); //2eme ligne P4=0; P5=0; i=3; P5=(P5 & 0x0F)|Tab_Val[i]; //Demarage en mode Off //Interruption sur P1.0 I3FR=1; // Front Montant sur P1.0 (rot_droite) IEX3=0; // Reset du drapeaux EX3=1; //autorisation IRQ //Interruption sur P1.1 (rot_gauche) IEX4=0; EX4=1; //Interruption sur P1.4 I2FR=0; //Front descendant sur P1.4 IEX2=0; // Reset flag EX2=1; //autorisation IRQ //Interruption sur P1.5 EXF2=0; EXEN2=1; ET2=1; IP0=(IP0 & 0xF1)|0x20; //Priorite 0 sur /INT3,/INT2 IP1=(IP1 & 0xF1)|0x20; EAL=1; //Autorisation globale //Boucle infinie while(1) { if(etat==MARCHE) { if(sens==GAUCHE) { i=i-1; if(i<0) i=3; } else { i=i+1; if(i>3) i=0; } P5=(P5&0x0F)|Tab_Val[i]; tempo(1000); } } } // end main /******************************************************** Nom : rot_gauche Objet : Rotation gauche Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P11(void) interrupt 11 using 1 { sens=GAUCHE; printf("ROTATION GAUCHE \n\n"); IEX4=0; } /******************************************************** Nom : rot_droite Objet : Rotation droite Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P10(void) interrupt 10 using 1 { sens=DROITE; printf("ROTATION DROITE \n\n"); IEX3=0; } /******************************************************** Nom : marche Objet : Mise en marche Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P14(void) interrupt 9 using 1 { etat=MARCHE; printf("\n--> TP 2.2 ON<-\n"); IEX2=0; } /******************************************************** Nom : arret Objet : Mise a l'arret Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P15(void) interrupt 5 using 1 { etat=ARRET; printf("\n--> TP 2.2 OFF<-\n"); EXF2=0; } /******************************************************** 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