Configuracion de Alarma y Hora, mediante LCD y Teclado, Navego por el menu con las teclas A, B, D, *, #.

Dependencies:   Debounced FPointer RTC-DS1307 TextLCD keypad mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //el Puerto Serial
00002 //Jesse Mauricio Beltran
00003 //Michelle Maceas Henao
00004 
00005 #include "mbed.h"
00006 #include "Rtc_Ds1307.h"
00007 #include "TextLCD.h"
00008 #include "DebouncedIn.h"
00009 #include "keypad.h"
00010 
00011 PwmOut Pwm(PTA5);
00012 DebouncedIn Aumen(PTC10);
00013 DebouncedIn Panta(PTC11);
00014 DebouncedIn Decre(PTC6);
00015 DebouncedIn Ensayo(PTC7);
00016 
00017 
00018 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7#include "TextLCD.h"
00019 Rtc_Ds1307 rtc(PTE0,PTE1);
00020 Serial pc(USBTX, USBRX);
00021 
00022 int Start=0,Read=0,Write=0,Menu=0,Menu2=0,Hora=0,Minuto=0,Segundo=0,pp=0,Dia=0,Dya=0,Mes=0,Anno=2014,Encendido=0,Aumen2=0,Decre2=0,flag2=0;
00023 float ppp=0.001;
00024 float Dd=0.1;
00025 int p=0,c=0,d=0,e=0,flag=0,ff=0,hh=0;
00026 int key;
00027 
00028 
00029 int PWMmodule(float ppp,float Dd)
00030 {
00031         Pwm.period(ppp);
00032         Pwm.write(Dd);
00033         wait(0.2);
00034         Pwm.write(0); 
00035         return 0;
00036 }
00037 
00038 
00039 char Keytable[] = { '1', '2', '3', 'A',
00040                      '4', '5', '6', 'B',
00041                       '7', '8', '9', 'C',
00042                       '*', '0', '#', 'D'
00043                     };
00044 
00045 uint32_t cbAfterInput(uint32_t Key)
00046 {
00047         
00048         key=Key;
00049         if(Keytable[key]=='B')
00050         {
00051             PWMmodule(ppp,Dd); 
00052             Write=0;
00053             Read=1;
00054             lcd.cls();
00055             lcd.printf("Configuacion de");
00056             lcd.locate(0,1);
00057             lcd.printf("     Alarma");
00058             wait(2);
00059             lcd.cls();
00060             lcd.printf("Presione D");
00061         }
00062         if(Keytable[key]=='A')
00063         {
00064             PWMmodule(ppp,Dd); 
00065             Write=1;
00066             Read=0;
00067             lcd.cls();
00068             lcd.printf("Configuacion del");
00069             lcd.locate(0,1);
00070             lcd.printf("      Reloj");
00071             wait(2);
00072             lcd.cls();
00073             lcd.printf("Presione D");
00074         }
00075         
00076         if(Keytable[key]=='D')
00077         {
00078             Menu=Menu+1;
00079         }
00080         if(Keytable[key]=='*')
00081         {
00082             Aumen2=1;
00083         }
00084         if(Keytable[key]=='#')
00085         {
00086             Decre2=1;
00087         }
00088         
00089         return 0;
00090 }
00091 
00092 int main()
00093 {
00094     Keypad keypad(PTA2,PTD4,PTD3,PTD1,PTD2,PTD0,PTD5,PTA13);
00095     keypad.CallAfterInput(&cbAfterInput);
00096     keypad.Start();  // energiza las columnas C0-C3 Del Keypad
00097     Rtc_Ds1307::Time_rtc tm = {};
00098     
00099     lcd.printf("   Bienvenido  ");
00100     wait(1);
00101     lcd.locate(0,1);
00102     lcd.printf("  Presione:");
00103     wait(2);
00104     lcd.cls();
00105     lcd.locate(0,0);
00106     lcd.printf("A.Config Reloj");
00107     lcd.locate(0,1);
00108     lcd.printf("B.Config Alarma");
00109     wait(2);
00110     
00111     
00112     while(1)
00113     {   
00114         
00115         if(Read==1)
00116         {
00117             flag2=0;
00118             if(Menu==1)
00119             {      
00120                 lcd.cls();
00121                 lcd.printf("Ingrese el Dia");  
00122                 wait(0.1);             
00123             }
00124             if(Menu==2)
00125             {
00126                 lcd.cls();
00127                 lcd.printf("Ingrese la Hora");
00128                 wait(0.1);
00129             }
00130             if(Menu==3)
00131             {
00132                 lcd.cls();
00133                 lcd.printf("Ingrese Minutos");
00134                 wait(0.1);   
00135             }
00136             if(Menu==4)
00137             {
00138                     lcd.cls();
00139                     lcd.printf("   Guardados !");
00140                     wait(0.1);
00141                     wait(1);
00142                     lcd.cls();
00143                     lcd.printf(".....En breve..... ");
00144                     lcd.locate(0,1);
00145                     lcd.printf(".....La Hora!....");
00146                     wait(2);
00147                     lcd.cls();
00148                     Menu=0;
00149                     flag2=1;
00150                     Read=0;
00151             }
00152                
00153             if(Aumen2==1)
00154             {
00155                 flag2=0;
00156                 Aumen2=0;
00157                 if(Menu==3)
00158                 {
00159                     if(c<59)
00160                     {
00161                         lcd.cls();
00162                         c=c+1;
00163                         lcd.locate(0,1);
00164                         lcd.printf("Minutos: %d",c);
00165                         wait(0.1);
00166                     }
00167                     else
00168                     {
00169                         c=0;
00170                     }
00171                 }
00172                 if(Menu==2)
00173                 {
00174                     if(d<23)
00175                     {
00176                         lcd.cls();
00177                         d=d+1;
00178                         lcd.locate(0,1);
00179                         lcd.printf("Horas %d",d);
00180                         wait(0.1);
00181                     }
00182                     else
00183                     {
00184                         d=0;
00185                     }
00186                 }    
00187                 if(Menu==1)
00188                 {
00189                    if(e<7)
00190                     {
00191                         lcd.cls();
00192                         e=e+1;
00193                         lcd.locate(0,1);
00194                         lcd.printf("Dia: %d",e);  
00195                         wait(0.1);  
00196                     }
00197                     else
00198                     {
00199                         e=0;    
00200                     } 
00201                 }  
00202             }  
00203             
00204              if(Decre2==1)
00205             {
00206                 flag2=0;
00207                 Decre2=0;
00208                 if(Menu==3)
00209                 {
00210                     if(c>0)
00211                     {
00212                         lcd.cls();
00213                         c=c-1;    
00214                         lcd.locate(0,1);
00215                         lcd.printf("Minutos: %d",c);
00216                         wait(0.1);
00217                     }
00218                     else
00219                     {
00220                         c=0;
00221                     }
00222                 }
00223                 if(Menu==2)
00224                 {   
00225                     if(d>0)
00226                     {
00227                         lcd.cls();
00228                         d=d-1;    
00229                         lcd.locate(0,1);
00230                         lcd.printf("Hora: %d",d);
00231                         wait(0.1);
00232                     }
00233                     else
00234                     {
00235                         d=0;
00236                     }                        
00237                 }
00238                 if(Menu==1)
00239                 {
00240                     if(e>0)
00241                     {
00242                         lcd.cls();
00243                         e=e-1;    
00244                         lcd.locate(0,1);
00245                         lcd.printf("Dia: %d",e);
00246                         wait(0.1);
00247                     }
00248                     else
00249                     {
00250                         e=0;
00251                     }      
00252                 }
00253                  
00254             }
00255             
00256         }
00257         if(Write==1)
00258         {
00259             if(Menu==1)
00260             {
00261                 lcd.cls();
00262                 lcd.printf("Ingrese Hora");
00263                 wait(0.1);
00264             }
00265             if(Menu==2)
00266             {
00267                 lcd.cls();
00268                 lcd.printf("Ingrese Min");
00269                 wait(0.1);
00270             }
00271             if(Menu==3)
00272             {
00273                 lcd.cls();
00274                 lcd.printf("Ingrese Seg)");
00275                 wait(0.1);
00276             }
00277             if(Menu==4)
00278             {
00279                 lcd.cls();
00280                 lcd.printf("Dia semana(1-7)");
00281                 wait(0.1);
00282             }
00283             if(Menu==5)
00284             {
00285                 lcd.cls();
00286                 lcd.printf("Ingrese Dia");
00287                 wait(0.1);
00288             }
00289             if(Menu==6)
00290             {
00291                 lcd.cls();
00292                 lcd.printf("Ingrese Mes");
00293                 wait(0.1);
00294             }
00295             if(Menu==7)
00296             {
00297                 lcd.cls();
00298                 lcd.printf("Ingrese Ano");
00299                 wait(0.1);
00300             }
00301             if(Menu==8)
00302             {
00303                 lcd.cls();
00304                 lcd.printf(" Datos Guardados!");
00305                 wait(1);   
00306                 Menu=0; 
00307                 lcd.cls();
00308                 rtc.setTime(tm, false, false);
00309                 rtc.startClock();
00310                 wait(0.2);
00311                 flag2=1;
00312                 lcd.cls();
00313                 lcd.printf(".....En breve....");
00314                 lcd.locate(0,1);
00315                 lcd.printf(".....La Hora!....");
00316                 wait(2);
00317                 lcd.cls();
00318                 Write=0;
00319             }
00320         }
00321             
00322         if(Aumen2==1)
00323         {
00324             Aumen2=0;
00325             if(Menu==1)
00326             {
00327                 lcd.cls();
00328                 lcd.printf("Ingrese Hora");
00329                 if(tm.hour<23)
00330                 {
00331                 tm.hour=tm.hour+1;
00332                 lcd.locate(0,1);
00333                 lcd.printf("Hora:%d",tm.hour);
00334                 wait(0.2);
00335                 }
00336                 else
00337                 {
00338                 Hora=0;
00339                 }
00340             }   
00341             if(Menu==2)
00342             {
00343                 lcd.cls();
00344                 lcd.printf("Ingrese Min");
00345                 if(tm.min<59)
00346                 {
00347                 tm.min=tm.min+1;
00348                 lcd.locate(0,1);
00349                 lcd.printf("Minutos:%d",tm.min);
00350                 wait(0.2);
00351                 }
00352                 else
00353                 {
00354                 Minuto=0;
00355                 }
00356             }
00357             if(Menu==3)
00358             {
00359                 lcd.cls();
00360                 lcd.printf("Ingrese Seg");
00361                 if(tm.sec<59)
00362                 {
00363                 tm.sec=tm.sec+1;
00364                 lcd.locate(0,1);
00365                 lcd.printf("Segundos:%d",tm.sec);
00366                 wait(0.2);
00367                 }
00368                 else
00369                 {
00370                 Segundo=0;
00371                 }
00372             }
00373             if(Menu==4)
00374             {
00375                 if(tm.wday<7)
00376                 {
00377                 tm.wday=tm.wday+1;
00378                 lcd.locate(0,1);
00379                 lcd.printf("Dia:%d",tm.wday);
00380                 wait(0.2);
00381                 }
00382                 else
00383                 {
00384                 Dia=0;
00385                 }
00386             }
00387             if(Menu==5)
00388             { 
00389                 lcd.cls();
00390                 lcd.printf("Ingrese Dia");
00391                 if(Dya<31)
00392                 {
00393                 tm.date=tm.date+1;
00394                 lcd.locate(0,1);
00395                 lcd.printf("Dia:%d",tm.date);
00396                 wait(0.2);
00397                 }
00398                 else
00399                 {
00400                 Dya=0;
00401                 }
00402             }
00403             if(Menu==6)
00404             {
00405                 lcd.cls();
00406                 lcd.printf("Ingrese Mes");
00407                 if(tm.mon<12)
00408                 {
00409                 tm.mon=tm.mon+1;
00410                 lcd.locate(0,1);
00411                 lcd.printf("Mes:%d",tm.mon);
00412                 wait(0.2);
00413                 }
00414                 else
00415                 {
00416                 Mes=0;
00417                 }
00418             }
00419             if(Menu==7)
00420             {
00421                 lcd.cls();
00422                 lcd.printf("Ingrese Ano");
00423                 Anno=Anno+1;
00424                 lcd.locate(0,1);
00425                 lcd.printf("Ano:%d",Anno);
00426                 wait(0.2);
00427                 tm.year=Anno;
00428             }
00429             
00430         }
00431         if(Decre2==1)
00432         {
00433             Decre2=0;
00434             
00435             if(Menu==1)
00436             {
00437                 if(tm.hour>0)
00438                 {
00439                 tm.hour=tm.hour-1;
00440                 lcd.locate(0,1);
00441                 lcd.printf("Hora:%d",tm.hour);
00442                 wait(0.1);
00443                 }
00444             }   
00445             if(Menu==2)
00446             {
00447                 if(tm.min>0)
00448                 {
00449                 tm.min=tm.min-1;
00450                 lcd.locate(0,1);
00451                 lcd.printf("Minutos:%d",tm.min);
00452                 wait(0.1);
00453                 }
00454             }
00455             if(Menu==3)
00456             {
00457                 if(tm.sec>0)
00458                 {
00459                 tm.sec=tm.sec-1;
00460                 lcd.locate(0,1);
00461                 lcd.printf("Segundos:%d",tm.sec);
00462                 wait(0.1);
00463                 }
00464             }
00465             if(Menu==4)
00466             {
00467                 if(tm.wday>0)
00468                 {
00469                 tm.wday=tm.wday-1;
00470                 lcd.locate(0,1);
00471                 lcd.printf("Dia:%d",tm.wday);
00472                 wait(0.1);
00473                 }
00474             }
00475             if(Menu==5)
00476             {
00477                 if(tm.date>0)
00478                 {
00479                 tm.date=tm.date-1;
00480                 lcd.locate(0,1);
00481                 lcd.printf("Dia:%d",tm.date);
00482                 wait(0.1);
00483                 }
00484             }
00485             if(Menu==6)
00486             {
00487                 if(tm.mon>0)
00488                 {
00489                 tm.mon=tm.mon-1;
00490                 lcd.locate(0,1);
00491                 lcd.printf("Mes:%d",tm.mon);
00492                 wait(0.1);
00493                 }
00494             }
00495             if(Menu==7)
00496             {
00497                 if(Anno>0)
00498                 {
00499                 Anno=Anno-1;
00500                 lcd.locate(0,1);
00501                 lcd.printf("Ano:%d",Anno);
00502                 wait(0.1);
00503                 tm.year=Anno;
00504                 }
00505             }
00506             
00507         }
00508         
00509         if((flag2==1)&&(Write==0)&&(Read==0)&&(Menu==0))
00510         {
00511             rtc.getTime(tm);
00512                 lcd.cls();
00513                 lcd.locate(0,1);            // Print and refresh data on line 2 of the LCD display     
00514                 lcd.printf("%.2D",tm.hour);
00515                 lcd.printf(":%.2D",tm.min);
00516                 lcd.printf(":%.2D",tm.sec);
00517                 lcd.locate(0,0);
00518                 lcd.printf("%.2D",tm.mon);
00519                 lcd.printf("/%.2D",tm.date);
00520                 lcd.printf("/%.2D",Anno);
00521                 
00522         
00523                 if (tm.wday == 6){
00524                     lcd.printf(" Frid\n");
00525                     wait(0.2);}
00526                 if (tm.wday == 7){
00527                     lcd.printf("  Sat\n");
00528                     wait(0.2);}   
00529                 if (tm.wday == 1){
00530                     lcd.printf(" Sun\n");
00531                     wait(0.2);}
00532                 if (tm.wday == 2){
00533                     lcd.printf("  Mon\n");
00534                     wait(0.2);}
00535                 if (tm.wday == 3){
00536                     lcd.printf(" Tues\n");
00537                     wait(0.2);}
00538                 if (tm.wday == 4){
00539                     lcd.printf("  Wed\n");
00540                     wait(0.2);}
00541                 if (tm.wday == 5){
00542                     lcd.printf(" Thur\n");
00543                     wait(0.2);}
00544                 wait(0.1);
00545         }
00546                     
00547         //Momento para la Alarma
00548         if((tm.hour==d)&(tm.min==c)&(tm.wday==e)&&(tm.hour!=0)&&(Write==0)&&(Read==0)&&(Menu==0))
00549         {
00550             flag=1;
00551         }
00552         if(flag==1)
00553         {
00554             PWMmodule(ppp,Dd);
00555             flag2=0;
00556             lcd.cls();
00557             lcd.printf("   Alarma!!");
00558             lcd.locate(0,1);
00559             lcd.printf("*.Pos  #.Desact");
00560             if(Aumen2==1)
00561             {
00562                 Aumen2=0;
00563                 lcd.cls();
00564                 lcd.printf("Se pospone 1min");
00565                 wait(1);
00566                 c=c+2;   
00567                 flag=0; 
00568                 flag2=1;
00569             }
00570             
00571             if(Decre2==1)
00572             {
00573                 
00574                 lcd.cls();
00575                 lcd.printf("Se ha desactivado");
00576                 lcd.locate(0,1);
00577                 lcd.printf("  la Alarma");
00578                 wait(1);
00579                 flag=0;
00580                 flag2=1;
00581                 d=0;
00582                 c=0;
00583                 e=0;  
00584                 Decre2=0; 
00585             }
00586         }            
00587     }      
00588 }