/********************************************************** Projet : tp_12.prj Fichier(s) : TP_12.c Objet : Introduction au C sur microcontroleur Gestion des entrees / sorties par scrutation de drapeau Auteurs : Hensinger Benoît / Cuenot Gaël Groupe : RLI 1 Date création : 09 - 11 - 2001 **********************************************************/ // 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 rot_gauche(void); // Fonction rotation gauche void rot_droite(void); // Fonction rotation droite // Definitions particulières (zone SFR ou RAM externe) : at 0x90 sbit bp_rotgauche; // BP 1.0 pour une rotation gauche at 0x94 sbit bp_rotdroite; // BP 1.4 pour une rotation droite // Variables Globales : bit etat_rotgauche, etat_rotdroite; 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 1.2 <---\n"); printf(" ---> OFF <---"); P4=0; P5=0; I3FR=1; // front montant sur P1.0 IEX3=0; // reset flag I2FR=0; // front descendant sur P1.4 IEX2=0; // reset flag etat_rotgauche=0; // initialisation des 2 variables etat_rotdroite=0; while(1) // boucle infinie { if(IEX3 == 1) // Test si BP1.0 est appuye (rot_gauche) { rot_gauche(); } if(IEX2 == 1) // Test si BP1.4 est appuye (rot_droite) { rot_droite(); } } } // end main /******************************************************** Nom : rot_gauche Objet : Realisation d'une rotation à gauche sur le port P5 Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void rot_gauche(void) { 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"); etat_rotgauche=1; etat_rotdroite=0; } } /******************************************************** Nom : rot_droite Objet : Realisation d'une rotation à droite sur le port P5 Paramètres : - d'appel : aucun - de retour : aucun *********************************************************/ void rot_droite(void) { 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; } } /******************************************************** 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