Template automate NUCLEO 446RE

Dependencies:   C12832-font

Committer:
gr91
Date:
Mon Nov 16 17:48:01 2020 +0000
Revision:
2:51380e17562c
Parent:
1:fb8116164c8f
Template automate NUCLEO 446RE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gr91 0:219cbcb4f747 1 //Université Paris-Saclay - IUT de Cachan
gr91 2:51380e17562c 2 //SNE S2 Prime GR DP nov 2020
gr91 0:219cbcb4f747 3 //***********************************************//
gr91 2:51380e17562c 4 #include "mbed.h"
gr91 2:51380e17562c 5 #include "C12832.h"
gr91 2:51380e17562c 6 C12832 lcd(D11, D13, D12, D7, D10);
gr91 2:51380e17562c 7 Ticker horloge_automate;
gr91 2:51380e17562c 8 //
gr91 2:51380e17562c 9 DigitalIn BPC (D4) ; // bouton centre
gr91 2:51380e17562c 10 DigitalOut LG (D9) ; // led verte
gr91 2:51380e17562c 11 DigitalOut LR (D5) ; // led rouge
gr91 0:219cbcb4f747 12
gr91 0:219cbcb4f747 13 // prototype et variables globales et constantes
gr91 0:219cbcb4f747 14 void automate(void);
gr91 2:51380e17562c 15 int horloge_automate_flag=0;
gr91 2:51380e17562c 16
gr91 2:51380e17562c 17 void horloge_automate_isr(void)
gr91 2:51380e17562c 18 {
gr91 2:51380e17562c 19 horloge_automate_flag=1;
gr91 2:51380e17562c 20 }
gr91 0:219cbcb4f747 21 //
gr91 0:219cbcb4f747 22 int main()
gr91 0:219cbcb4f747 23 {
gr91 2:51380e17562c 24 horloge_automate.attach(&horloge_automate_isr,0.1);
gr91 2:51380e17562c 25 lcd.cls();
gr91 2:51380e17562c 26 lcd.locate(0,3);
gr91 2:51380e17562c 27 lcd.printf("Automate");
gr91 0:219cbcb4f747 28 while(1) {
gr91 2:51380e17562c 29 if(horloge_automate_flag) {
gr91 2:51380e17562c 30 automate();
gr91 2:51380e17562c 31 horloge_automate_flag=0;
gr91 2:51380e17562c 32 }
gr91 0:219cbcb4f747 33 }
gr91 0:219cbcb4f747 34 }
gr91 0:219cbcb4f747 35 void automate(void)
gr91 0:219cbcb4f747 36 {
gr91 0:219cbcb4f747 37 // définition d'un type énuméré permettant de manipuler l'état de l'automate
gr91 0:219cbcb4f747 38 // par son nom
gr91 0:219cbcb4f747 39 typedef enum {etat0=0, etat1=1, etat2=2} type_etat;
gr91 0:219cbcb4f747 40 type_etat etat_actuel = etat0 ; // déclaration état actuel init. à etat0
gr91 0:219cbcb4f747 41 static type_etat etat_futur = etat0; // déclaration état futur
gr91 0:219cbcb4f747 42 int entree;
gr91 0:219cbcb4f747 43 // gestion des entrees
gr91 0:219cbcb4f747 44 entree = BPC; // c'est le bouton centre
gr91 0:219cbcb4f747 45 // gestion du diagramme de transition
gr91 0:219cbcb4f747 46 etat_actuel = etat_futur; // mise à jour de l'état
gr91 0:219cbcb4f747 47 // calul de l'éat futur en fonction de l'état actuel et des entrées
gr91 0:219cbcb4f747 48 switch(etat_actuel) {
gr91 0:219cbcb4f747 49 case etat0 :
gr91 0:219cbcb4f747 50 if (entree) etat_futur = etat1;
gr91 0:219cbcb4f747 51 break;
gr91 0:219cbcb4f747 52 case etat1 :
gr91 0:219cbcb4f747 53 etat_futur = etat2;
gr91 0:219cbcb4f747 54 break;
gr91 0:219cbcb4f747 55 case etat2 :
gr91 0:219cbcb4f747 56 etat_futur = etat0;
gr91 0:219cbcb4f747 57 break;
gr91 0:219cbcb4f747 58 }
gr91 0:219cbcb4f747 59 // valeurs des sorties en fonction de l'état actuel
gr91 0:219cbcb4f747 60 switch(etat_actuel) {
gr91 0:219cbcb4f747 61 case etat0 :
gr91 2:51380e17562c 62 lcd.locate(0,12);
gr91 2:51380e17562c 63 lcd.printf("Etat 0");
gr91 0:219cbcb4f747 64 LG=1;
gr91 0:219cbcb4f747 65 LR=1;
gr91 0:219cbcb4f747 66 break;
gr91 0:219cbcb4f747 67 case etat1 :
gr91 2:51380e17562c 68 lcd.locate(0,12);
gr91 2:51380e17562c 69 lcd.printf("Etat 1");
gr91 0:219cbcb4f747 70 LG=0;
gr91 0:219cbcb4f747 71 LR=1;
gr91 0:219cbcb4f747 72 break;
gr91 0:219cbcb4f747 73 case etat2 :
gr91 2:51380e17562c 74 lcd.locate(0,12);
gr91 2:51380e17562c 75 lcd.printf("Etat 2");
gr91 0:219cbcb4f747 76 LG=1;
gr91 0:219cbcb4f747 77 LR=0;
gr91 0:219cbcb4f747 78 break;
gr91 0:219cbcb4f747 79 }
gr91 0:219cbcb4f747 80 }