manonarnaudo

Dependencies:   mbed TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 ///////////////////////////////////////////////////////////////////////////////////
00002 // Machine A Etats (MAE) - Gestion d'un chronometre
00003 // Cible : MBED LPC1768
00004 // Langage C
00005 //
00006 // PhC OK le 02-03-2020
00007 ///////////////////////////////////////////////////////////////////////////////////
00008 // INCLUDES
00009 #include "mbed.h"
00010 #include "TextLCD.h"
00011 
00012 // DEFINES
00013 // Definition des constantes etats
00014 #define STOP    0
00015 #define RUN    1
00016 #define LAP   2
00017 
00018 
00019 // Constantes generales
00020 #define LCD_SIZE    20      // la taille de l'afficheur LCD
00021 
00022 
00023 // PROTOTYPES
00024 void Init(void) ;
00025 void A01(),A02(),A03(),A04(),A05(),A06(),A08();
00026 void affiche ();
00027 void gestion();
00028 
00029 
00030 // OBJETS
00031 DigitalIn BPMS(p12);
00032 DigitalIn BPLR(p11);
00033 Timer T1;
00034 TextLCD MyLCD(p26,p25,p21,p22,p23,p24,TextLCD:: LCD20x4);
00035 
00036 
00037 // GLOBALS
00038 // Variable d'etat
00039 int iEtat, iMs_avant=0, iLr_avant=0,iLap=0;
00040 
00041 
00042 // Variables de gestion Heure, Minute, Seconde, Dixieme
00043 unsigned char byH, byM,byS, byD;
00044 
00045 
00046 // MAIN
00047 int main()
00048 {
00049    // printf("\n\rDemarrage du programme\n\r") ;
00050     int iMs=0, iLr=0;
00051     Init() ;
00052 
00053 
00054     while(true) {
00055         iMs=BPMS.read();
00056         iLr=BPLR.read();
00057         switch(iEtat) {
00058             case STOP:
00059                 if(iMs>iMs_avant) {
00060                    // printf("Evenement=MS\n\r");
00061                     A01();
00062                     //printf("Etat=RUN\n\r");
00063                     iEtat=RUN;
00064                    // wait(0.2);
00065                     break;
00066                 }
00067                 if(iLr>iLr_avant) {
00068                    // printf("Evenement=LR\n\r");
00069                     A08();
00070                    // printf("Etat=STOP\n\r");
00071                     iEtat=STOP;
00072                    // wait(0.2);
00073                     break;
00074                 }
00075                 break;
00076 
00077             case RUN:
00078                 if(iMs>iMs_avant) {
00079                     //printf("Evenement=MS\n\r");
00080                     A02();
00081                     //printf("Etat=STOP\n\r");
00082                     iEtat=STOP;
00083                     //wait(0.2);
00084                     break;
00085                 }
00086                 if(iLr>iLr_avant) {
00087                     //printf("Evenement=LR\n\r");
00088                     A04();
00089                     //printf("Etat=LAP\n\r");
00090                     iEtat=LAP;
00091                     //wait(0.2);
00092                     break;
00093                 }
00094                 if(T1.read_ms()>=10) {
00095                     //printf("Evenement=TIME\n\r");
00096                     A03();
00097                     //printf("Etat=RUN\n\r");
00098                     iEtat=RUN;
00099                     break;
00100                 }
00101                 break;
00102             case LAP:
00103                 if(iMs>iMs_avant) {
00104                     //printf("Evenement=MS\n\r");
00105                     A02();
00106                     //printf("Etat=STOP\n\r");
00107                     iEtat=STOP;
00108                     
00109                     break;
00110                 }
00111                 if(iLr>iLr_avant) {
00112                     //printf("Evenement=LR\n\r");
00113                     A05();
00114                     //printf("Etat=RUN\n\r");
00115                     iEtat=RUN;
00116                     break;
00117                 }
00118                 if(T1.read_ms()>=10) {
00119                     //printf("Evenement=TIME\n\r");
00120                     A06();
00121                     //printf("Etat=LAP\n\r");
00122                     iEtat=LAP;
00123                     break;
00124                 }
00125                 break;
00126         }
00127 
00128 
00129 
00130     } // end while
00131 } // end main
00132 
00133 
00134 
00135 
00136 ///////////////////////////
00137 // Les actions elementaires
00138 ///////////////////////////
00139 void Init(void)
00140 {
00141     BPMS.mode(PullDown);
00142     BPLR.mode(PullDown);
00143     // Etat initial
00144     iEtat = STOP ;
00145    // printf("Etat initial = STOP\n\r") ;
00146 
00147     MyLCD.cls();
00148     MyLCD.printf("Time=00.00.00.00.00\n\r");
00149     MyLCD.printf("Lap=0");
00150 }
00151 void A01()
00152 {
00153     //printf("Action=A01\n\r");
00154     T1.start();
00155     affiche();
00156 }
00157 
00158 void A02()
00159 {
00160     //printf("Action=A02\n\r");
00161     T1.stop();
00162     affiche();
00163 }
00164 
00165 void A03()
00166 {
00167     //printf("Action=A03\n\r");
00168     T1.reset();
00169     affiche();
00170     gestion();
00171 }
00172 
00173 void A04()
00174 {
00175     iLap++;
00176     wait(0.2);
00177     //printf("Action=A04\n\r");
00178 }
00179 
00180 void A05()
00181 {
00182     //printf("Action=A05\n\r");
00183     affiche();
00184 }
00185 
00186 void A06()
00187 {
00188     //printf("Action=A06\n\r");
00189     T1.reset();
00190     gestion();
00191 }
00192 
00193 void A08()
00194 {
00195     //printf("Action=A08\n\r");
00196     byD=byS=byM=byH=0;
00197     MyLCD.cls();
00198     affiche();
00199 }
00200 
00201 void affiche()
00202 {
00203     MyLCD.locate(0,0);
00204     //sprintf(,"TIME=%02d %02d %02d %02d",gbyH, gbyM, gbyS, gbyD);
00205     MyLCD.locate(0,0);
00206     MyLCD.printf("TIME=%02d:%02d:%02d:%02d:%02d\n\r",00,byH, byM, byS, byD);
00207     MyLCD.printf("LAP=%d",iLap);
00208 } 
00209 
00210 void gestion()
00211 {
00212     byD++;
00213     if(byD>99) {
00214         byD=0;
00215         byS++;
00216         if(byS>59) {
00217             byS=0;
00218             byM++;
00219             if(byM>59) {
00220                 byM=0;
00221                 byH++;
00222                 if(byH>23) byH=0;
00223             }
00224         }
00225     }
00226 }