/********************************************************** Projet : tp3_1.prj Fichier(s) : TP_31.c Objet : Introduction au C sur microcontroleur Gestion des entrees / sorties 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_T2(void) interrupt 5 using 1; // Definitions particulières (zone SFR ou RAM externe) : at 0xCC sfr16 THL2; at 0xCA sfr16 CRCHL; // Variables Globales : code unsigned char Tab_Val[4]={0x10,0x20,0x40,0x80}; bit etat; bit sens; int cpt,free_cpt,i; // ================ 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.1 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 // Initialisation du Timer T2 CRCHL=-2500/1; THL2=CRCHL; T2PS=0; T2R0=0; T2R1=1; T2I0=1; T2I1=0; TF2=0; ET2=1; //Interruption sur P1.0 (rot_droite) I3FR=1; // Front Montant sur P1.0 IEX3=0; // Reset du drapeaux EX3=1; //autorisation IRQ //Interruption sur P1.1 (rot_gauche) IEX4=0; EX4=1; //Interruption sur P1.4 (Marche) I2FR=0; //Front descendant sur P1.4 IEX2=0; // Reset flag EX2=1; //autorisation IRQ //Interruption sur P1.5 (Arret) EXF2=0; EXEN2=1; ET2=1; IP0=(IP0 & 0xDF)|0x20; //Priorite 0 sur /INT3,/INT2 IP1=(IP1 & 0xDF)|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]; cpt=free_cpt+1; while(free_cpt != cpt); } } } // 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 3.1 ON<--\n"); IEX2=0; } /******************************************************** Nom : arret 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 { EXF2=0; etat=ARRET; printf("\n--> TP 3.1 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