/********************************************************** Projet : tp2_1.prj Fichier(s) : TP2_1.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 // Fonctions externes : // Fonctions locales (Prototypes) : void tempo(unsigned int); // Fonction temporisation (delai) void IRQ_P10(void) interrupt 10 using 1; //Interruption sur P1.0 void IRQ_P14(void) interrupt 9 using 1; //Interruptino sur P1.4 // 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_rotgauche; bit etat_rotdroite; code unsigned char Tab_Val[4]={0x10,0x20,0x40,0x80}; int 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 2.1 <---\n"); //1ere ligne printf(" ---> OFF <---"); //2eme ligne P4=0; P5=0; etat_rotgauche=0; etat_rotdroite=0; i=3; //Valeur 3 pour 0x80 ds le tableau led "off" P5=(P5 & 0x0F)|Tab_Val[i]; //Demarage en mode Off //Interruption sur P1.0 I3FR=1; // Front Montant sur P1.0 (rot_gauche) IEX3=0; // Reset du drapeaux EX3=1; //autorisation IRQ //Interruption sur P1.4 I2FR=0; //FRont descendant sur P1.4 IEX2=0; // Reset flag EX2=1; //autorisation IRQ IP0=(IP0 & 0xF9)|0x00; //Priorite 0 sur /INT3,/INT2 IP0=(IP1 & 0xF9)|0x00; EAL=1; //Autorisation globale //Boucle infinie while(1); } // end main /******************************************************** Nom : rot_gauche Objet : Rotation des leds a gauche Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P10(void) interrupt 10 using 1 { tempo(100); IEX3=0; // reset du flag i=i--; if(i < 0) i=3; P5=(P5&0x0F)|Tab_Val[i]; etat_rotgauche=1; if(etat_rotgauche == 1) { printf("\n\n ROTATION GAUCHE"); //Affichage Rotation Gauche Ligne 2 etat_rotgauche=1; etat_rotdroite=0; } tempo(50); IEX3=0; //reset du flag } /******************************************************** Nom : rot_droite Objet : Rotation des leds a droite Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void IRQ_P14(void) interrupt 9 using 1 { tempo(100); IEX2=0; // reset du flag i=i++; if(i > 3) i=0; P5=(P5 & 0x0F) | Tab_Val[i]; etat_rotdroite=1; if(etat_rotdroite == 1) { printf("\n\n ROTATION DROITE"); etat_rotgauche=0; etat_rotdroite=1; } tempo(50); IEX2=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