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

Files at this revision

API Documentation at this revision

Comitter:
Jesse
Date:
Thu May 08 22:38:48 2014 +0000
Commit message:
Tarea 5_Alarma DS1307

Changed in this revision

Debounced.lib Show annotated file Show diff for this revision Revisions of this file
FPointer.lib Show annotated file Show diff for this revision Revisions of this file
RTC-DS1307.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
debug.h Show annotated file Show diff for this revision Revisions of this file
keypad.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 8471537b0784 Debounced.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Thu May 08 22:38:48 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
diff -r 000000000000 -r 8471537b0784 FPointer.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FPointer.lib	Thu May 08 22:38:48 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/FPointer/#56e309e76c19
diff -r 000000000000 -r 8471537b0784 RTC-DS1307.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC-DS1307.lib	Thu May 08 22:38:48 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/leihen/code/RTC-DS1307/#5627b407e097
diff -r 000000000000 -r 8471537b0784 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Thu May 08 22:38:48 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/lcorralesc1/code/TextLCD/#0e0132807662
diff -r 000000000000 -r 8471537b0784 debug.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debug.h	Thu May 08 22:38:48 2014 +0000
@@ -0,0 +1,16 @@
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+
+#ifdef DEBUG
+#define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#define ERR(x, ...) std::printf("[ERR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#else
+#define INFO(x, ...)
+#define WARN(x, ...)
+#define ERR(x, ...)
+#endif
+
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 8471537b0784 keypad.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keypad.lib	Thu May 08 22:38:48 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/leorestrepo93/code/keypad/#e48ba5b4c497
diff -r 000000000000 -r 8471537b0784 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 08 22:38:48 2014 +0000
@@ -0,0 +1,588 @@
+//el Puerto Serial
+//Jesse Mauricio Beltran
+//Michelle Maceas Henao
+
+#include "mbed.h"
+#include "Rtc_Ds1307.h"
+#include "TextLCD.h"
+#include "DebouncedIn.h"
+#include "keypad.h"
+
+PwmOut Pwm(PTA5);
+DebouncedIn Aumen(PTC10);
+DebouncedIn Panta(PTC11);
+DebouncedIn Decre(PTC6);
+DebouncedIn Ensayo(PTC7);
+
+
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7#include "TextLCD.h"
+Rtc_Ds1307 rtc(PTE0,PTE1);
+Serial pc(USBTX, USBRX);
+
+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;
+float ppp=0.001;
+float Dd=0.1;
+int p=0,c=0,d=0,e=0,flag=0,ff=0,hh=0;
+int key;
+
+
+int PWMmodule(float ppp,float Dd)
+{
+        Pwm.period(ppp);
+        Pwm.write(Dd);
+        wait(0.2);
+        Pwm.write(0); 
+        return 0;
+}
+
+
+char Keytable[] = { '1', '2', '3', 'A',
+                     '4', '5', '6', 'B',
+                      '7', '8', '9', 'C',
+                      '*', '0', '#', 'D'
+                    };
+
+uint32_t cbAfterInput(uint32_t Key)
+{
+        
+        key=Key;
+        if(Keytable[key]=='B')
+        {
+            PWMmodule(ppp,Dd); 
+            Write=0;
+            Read=1;
+            lcd.cls();
+            lcd.printf("Configuacion de");
+            lcd.locate(0,1);
+            lcd.printf("     Alarma");
+            wait(2);
+            lcd.cls();
+            lcd.printf("Presione D");
+        }
+        if(Keytable[key]=='A')
+        {
+            PWMmodule(ppp,Dd); 
+            Write=1;
+            Read=0;
+            lcd.cls();
+            lcd.printf("Configuacion del");
+            lcd.locate(0,1);
+            lcd.printf("      Reloj");
+            wait(2);
+            lcd.cls();
+            lcd.printf("Presione D");
+        }
+        
+        if(Keytable[key]=='D')
+        {
+            Menu=Menu+1;
+        }
+        if(Keytable[key]=='*')
+        {
+            Aumen2=1;
+        }
+        if(Keytable[key]=='#')
+        {
+            Decre2=1;
+        }
+        
+        return 0;
+}
+
+int main()
+{
+    Keypad keypad(PTA2,PTD4,PTD3,PTD1,PTD2,PTD0,PTD5,PTA13);
+    keypad.CallAfterInput(&cbAfterInput);
+    keypad.Start();  // energiza las columnas C0-C3 Del Keypad
+    Rtc_Ds1307::Time_rtc tm = {};
+    
+    lcd.printf("   Bienvenido  ");
+    wait(1);
+    lcd.locate(0,1);
+    lcd.printf("  Presione:");
+    wait(2);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("A.Config Reloj");
+    lcd.locate(0,1);
+    lcd.printf("B.Config Alarma");
+    wait(2);
+    
+    
+    while(1)
+    {   
+        
+        if(Read==1)
+        {
+            flag2=0;
+            if(Menu==1)
+            {      
+                lcd.cls();
+                lcd.printf("Ingrese el Dia");  
+                wait(0.1);             
+            }
+            if(Menu==2)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese la Hora");
+                wait(0.1);
+            }
+            if(Menu==3)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Minutos");
+                wait(0.1);   
+            }
+            if(Menu==4)
+            {
+                    lcd.cls();
+                    lcd.printf("   Guardados !");
+                    wait(0.1);
+                    wait(1);
+                    lcd.cls();
+                    lcd.printf(".....En breve..... ");
+                    lcd.locate(0,1);
+                    lcd.printf(".....La Hora!....");
+                    wait(2);
+                    lcd.cls();
+                    Menu=0;
+                    flag2=1;
+                    Read=0;
+            }
+               
+            if(Aumen2==1)
+            {
+                flag2=0;
+                Aumen2=0;
+                if(Menu==3)
+                {
+                    if(c<59)
+                    {
+                        lcd.cls();
+                        c=c+1;
+                        lcd.locate(0,1);
+                        lcd.printf("Minutos: %d",c);
+                        wait(0.1);
+                    }
+                    else
+                    {
+                        c=0;
+                    }
+                }
+                if(Menu==2)
+                {
+                    if(d<23)
+                    {
+                        lcd.cls();
+                        d=d+1;
+                        lcd.locate(0,1);
+                        lcd.printf("Horas %d",d);
+                        wait(0.1);
+                    }
+                    else
+                    {
+                        d=0;
+                    }
+                }    
+                if(Menu==1)
+                {
+                   if(e<7)
+                    {
+                        lcd.cls();
+                        e=e+1;
+                        lcd.locate(0,1);
+                        lcd.printf("Dia: %d",e);  
+                        wait(0.1);  
+                    }
+                    else
+                    {
+                        e=0;    
+                    } 
+                }  
+            }  
+            
+             if(Decre2==1)
+            {
+                flag2=0;
+                Decre2=0;
+                if(Menu==3)
+                {
+                    if(c>0)
+                    {
+                        lcd.cls();
+                        c=c-1;    
+                        lcd.locate(0,1);
+                        lcd.printf("Minutos: %d",c);
+                        wait(0.1);
+                    }
+                    else
+                    {
+                        c=0;
+                    }
+                }
+                if(Menu==2)
+                {   
+                    if(d>0)
+                    {
+                        lcd.cls();
+                        d=d-1;    
+                        lcd.locate(0,1);
+                        lcd.printf("Hora: %d",d);
+                        wait(0.1);
+                    }
+                    else
+                    {
+                        d=0;
+                    }                        
+                }
+                if(Menu==1)
+                {
+                    if(e>0)
+                    {
+                        lcd.cls();
+                        e=e-1;    
+                        lcd.locate(0,1);
+                        lcd.printf("Dia: %d",e);
+                        wait(0.1);
+                    }
+                    else
+                    {
+                        e=0;
+                    }      
+                }
+                 
+            }
+            
+        }
+        if(Write==1)
+        {
+            if(Menu==1)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Hora");
+                wait(0.1);
+            }
+            if(Menu==2)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Min");
+                wait(0.1);
+            }
+            if(Menu==3)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Seg)");
+                wait(0.1);
+            }
+            if(Menu==4)
+            {
+                lcd.cls();
+                lcd.printf("Dia semana(1-7)");
+                wait(0.1);
+            }
+            if(Menu==5)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Dia");
+                wait(0.1);
+            }
+            if(Menu==6)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Mes");
+                wait(0.1);
+            }
+            if(Menu==7)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Ano");
+                wait(0.1);
+            }
+            if(Menu==8)
+            {
+                lcd.cls();
+                lcd.printf(" Datos Guardados!");
+                wait(1);   
+                Menu=0; 
+                lcd.cls();
+                rtc.setTime(tm, false, false);
+                rtc.startClock();
+                wait(0.2);
+                flag2=1;
+                lcd.cls();
+                lcd.printf(".....En breve....");
+                lcd.locate(0,1);
+                lcd.printf(".....La Hora!....");
+                wait(2);
+                lcd.cls();
+                Write=0;
+            }
+        }
+            
+        if(Aumen2==1)
+        {
+            Aumen2=0;
+            if(Menu==1)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Hora");
+                if(tm.hour<23)
+                {
+                tm.hour=tm.hour+1;
+                lcd.locate(0,1);
+                lcd.printf("Hora:%d",tm.hour);
+                wait(0.2);
+                }
+                else
+                {
+                Hora=0;
+                }
+            }   
+            if(Menu==2)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Min");
+                if(tm.min<59)
+                {
+                tm.min=tm.min+1;
+                lcd.locate(0,1);
+                lcd.printf("Minutos:%d",tm.min);
+                wait(0.2);
+                }
+                else
+                {
+                Minuto=0;
+                }
+            }
+            if(Menu==3)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Seg");
+                if(tm.sec<59)
+                {
+                tm.sec=tm.sec+1;
+                lcd.locate(0,1);
+                lcd.printf("Segundos:%d",tm.sec);
+                wait(0.2);
+                }
+                else
+                {
+                Segundo=0;
+                }
+            }
+            if(Menu==4)
+            {
+                if(tm.wday<7)
+                {
+                tm.wday=tm.wday+1;
+                lcd.locate(0,1);
+                lcd.printf("Dia:%d",tm.wday);
+                wait(0.2);
+                }
+                else
+                {
+                Dia=0;
+                }
+            }
+            if(Menu==5)
+            { 
+                lcd.cls();
+                lcd.printf("Ingrese Dia");
+                if(Dya<31)
+                {
+                tm.date=tm.date+1;
+                lcd.locate(0,1);
+                lcd.printf("Dia:%d",tm.date);
+                wait(0.2);
+                }
+                else
+                {
+                Dya=0;
+                }
+            }
+            if(Menu==6)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Mes");
+                if(tm.mon<12)
+                {
+                tm.mon=tm.mon+1;
+                lcd.locate(0,1);
+                lcd.printf("Mes:%d",tm.mon);
+                wait(0.2);
+                }
+                else
+                {
+                Mes=0;
+                }
+            }
+            if(Menu==7)
+            {
+                lcd.cls();
+                lcd.printf("Ingrese Ano");
+                Anno=Anno+1;
+                lcd.locate(0,1);
+                lcd.printf("Ano:%d",Anno);
+                wait(0.2);
+                tm.year=Anno;
+            }
+            
+        }
+        if(Decre2==1)
+        {
+            Decre2=0;
+            
+            if(Menu==1)
+            {
+                if(tm.hour>0)
+                {
+                tm.hour=tm.hour-1;
+                lcd.locate(0,1);
+                lcd.printf("Hora:%d",tm.hour);
+                wait(0.1);
+                }
+            }   
+            if(Menu==2)
+            {
+                if(tm.min>0)
+                {
+                tm.min=tm.min-1;
+                lcd.locate(0,1);
+                lcd.printf("Minutos:%d",tm.min);
+                wait(0.1);
+                }
+            }
+            if(Menu==3)
+            {
+                if(tm.sec>0)
+                {
+                tm.sec=tm.sec-1;
+                lcd.locate(0,1);
+                lcd.printf("Segundos:%d",tm.sec);
+                wait(0.1);
+                }
+            }
+            if(Menu==4)
+            {
+                if(tm.wday>0)
+                {
+                tm.wday=tm.wday-1;
+                lcd.locate(0,1);
+                lcd.printf("Dia:%d",tm.wday);
+                wait(0.1);
+                }
+            }
+            if(Menu==5)
+            {
+                if(tm.date>0)
+                {
+                tm.date=tm.date-1;
+                lcd.locate(0,1);
+                lcd.printf("Dia:%d",tm.date);
+                wait(0.1);
+                }
+            }
+            if(Menu==6)
+            {
+                if(tm.mon>0)
+                {
+                tm.mon=tm.mon-1;
+                lcd.locate(0,1);
+                lcd.printf("Mes:%d",tm.mon);
+                wait(0.1);
+                }
+            }
+            if(Menu==7)
+            {
+                if(Anno>0)
+                {
+                Anno=Anno-1;
+                lcd.locate(0,1);
+                lcd.printf("Ano:%d",Anno);
+                wait(0.1);
+                tm.year=Anno;
+                }
+            }
+            
+        }
+        
+        if((flag2==1)&&(Write==0)&&(Read==0)&&(Menu==0))
+        {
+            rtc.getTime(tm);
+                lcd.cls();
+                lcd.locate(0,1);            // Print and refresh data on line 2 of the LCD display     
+                lcd.printf("%.2D",tm.hour);
+                lcd.printf(":%.2D",tm.min);
+                lcd.printf(":%.2D",tm.sec);
+                lcd.locate(0,0);
+                lcd.printf("%.2D",tm.mon);
+                lcd.printf("/%.2D",tm.date);
+                lcd.printf("/%.2D",Anno);
+                
+        
+                if (tm.wday == 6){
+                    lcd.printf(" Frid\n");
+                    wait(0.2);}
+                if (tm.wday == 7){
+                    lcd.printf("  Sat\n");
+                    wait(0.2);}   
+                if (tm.wday == 1){
+                    lcd.printf(" Sun\n");
+                    wait(0.2);}
+                if (tm.wday == 2){
+                    lcd.printf("  Mon\n");
+                    wait(0.2);}
+                if (tm.wday == 3){
+                    lcd.printf(" Tues\n");
+                    wait(0.2);}
+                if (tm.wday == 4){
+                    lcd.printf("  Wed\n");
+                    wait(0.2);}
+                if (tm.wday == 5){
+                    lcd.printf(" Thur\n");
+                    wait(0.2);}
+                wait(0.1);
+        }
+                    
+        //Momento para la Alarma
+        if((tm.hour==d)&(tm.min==c)&(tm.wday==e)&&(tm.hour!=0)&&(Write==0)&&(Read==0)&&(Menu==0))
+        {
+            flag=1;
+        }
+        if(flag==1)
+        {
+            PWMmodule(ppp,Dd);
+            flag2=0;
+            lcd.cls();
+            lcd.printf("   Alarma!!");
+            lcd.locate(0,1);
+            lcd.printf("*.Pos  #.Desact");
+            if(Aumen2==1)
+            {
+                Aumen2=0;
+                lcd.cls();
+                lcd.printf("Se pospone 1min");
+                wait(1);
+                c=c+2;   
+                flag=0; 
+                flag2=1;
+            }
+            
+            if(Decre2==1)
+            {
+                
+                lcd.cls();
+                lcd.printf("Se ha desactivado");
+                lcd.locate(0,1);
+                lcd.printf("  la Alarma");
+                wait(1);
+                flag=0;
+                flag2=1;
+                d=0;
+                c=0;
+                e=0;  
+                Decre2=0; 
+            }
+        }            
+    }      
+}
diff -r 000000000000 -r 8471537b0784 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 08 22:38:48 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file