Ejemplo RTC

Dependencies:   Debounced FPointer RTC-DS1307 TextLCD keypad mbed

Revision:
0:7eff3c322f61
Child:
1:8f03434fc55b
diff -r 000000000000 -r 7eff3c322f61 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Apr 30 23:44:19 2014 +0000
@@ -0,0 +1,538 @@
+//lectura del 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=2000,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;
+char buffer[128];
+int readptr=0;
+int key;
+
+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]=='A')//
+        {
+            Write=0;
+            Read=1;
+        }
+        if(Keytable[key]=='B')
+        {
+            Write=1;
+            Read=0;
+            //Read=0;
+            lcd.cls();
+            lcd.printf("Configuacion del");
+            lcd.locate(0,1);
+            lcd.printf("      Reloj");
+            wait(1);
+        }
+        if(Keytable[key]=='2')
+        {
+            Start=1;
+        }
+        if(Keytable[key]=='D')
+        {
+            Menu=1;
+        }
+        if(Keytable[key]=='1')
+        {
+            Encendido=1;
+        }
+        if(Keytable[key]=='4')
+        {
+            Aumen2=1;
+        }
+        if(Keytable[key]=='5')
+        {
+            Decre2=1;
+        }
+        
+        return 0;
+}
+
+//PPWM
+int PWMmodule(float ppp,float Dd)
+{
+        Pwm.period(ppp);
+        Pwm.write(Dd);
+        wait(0.1);
+        Pwm.write(0); 
+        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 = {};
+    while(1)
+    {   
+        pc.printf("*************************************\n");
+        pc.printf("* Menu for RTC Test :               *\n");
+        pc.printf("* read  - reads the clock           *\n");
+        pc.printf("* start - start the clock           *\n");
+        pc.printf("* stop  - stop the clock            *\n");
+        pc.printf("* write - write the clock           *\n");
+        pc.printf("* ena   - enable Square wave output *\n");
+        pc.printf("* dis   - disable square wave outp. *\n");
+        pc.printf("*************************************\n");
+    
+        if(Read==1)
+        {
+            //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.printf("%d",tm.hour);
+        
+            lcd.locate(0,0);
+            lcd.printf("%.2D",tm.mon);
+            lcd.printf("/%.2D",tm.date);
+            lcd.printf("/%.2D",tm.year);
+            
+        }
+        if(Write==1)
+        {
+            //lcd.cls();
+            //lcd.printf("Ingrese Datos");
+            if(Panta.falling())
+            {
+                pp=pp+1;
+                //lcd.printf("");
+            }
+            if(pp==1)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Ingrese Hora");
+            }
+            if(pp==2)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Ingrese Minutos");
+            }
+            if(pp==3)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Ingrese Segundos");
+            }
+            if(pp==4)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Ingrese Dia(Sem)");
+            }
+            if(pp==5)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Ingrese dia");
+            }
+             if(pp==6)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Ingrese Mes");
+            }
+            if(pp==7)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Ingrese el Año");
+            }
+            if(pp==8)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Datos Guardados !");
+                wait(2);
+                lcd.cls();
+                pp=0;
+            }
+        }
+            
+        if(Aumen.falling())
+        {
+            
+            if(pp==1)
+            {
+                if(Hora<=23)
+                {
+                Hora=Hora+1;
+                lcd.locate(0,1);
+                lcd.printf("Hora[0-23]:%d",Hora);
+                }
+                else
+                {
+                Hora=0;
+                }
+            }   
+            if(pp==2)
+            {
+                if(Minuto<=59)
+                {
+                Minuto=Minuto+1;
+                lcd.locate(0,1);
+                lcd.printf("Minutos[0-59]:%d",Minuto);
+                }
+                else
+                {
+                Minuto=0;
+                }
+            }
+            if(pp==3)
+            {
+                if(Segundo<=59)
+                {
+                Segundo=Segundo+1;
+                lcd.locate(0,1);
+                lcd.printf("Seg[0-59]:%d",Segundo);
+                }
+                else
+                {
+                Segundo=0;
+                }
+            }
+            if(pp==4)
+            {
+                if(Dia<=7)
+                {
+                Dia=Dia+1;
+                lcd.locate(0,1);
+                lcd.printf("Dia[1-7]:%d",Dia);
+                }
+                else
+                {
+                Dia=0;
+                }
+            }
+            if(pp==5)
+            { //se toco por chimbiarlo , sera??, que gueva
+                if(Dya<=31)
+                {
+                Dya=Dya+1;
+                lcd.locate(0,1);
+                lcd.printf("Dia:%d",Dya);
+                }
+                else
+                {
+                Dya=0;
+                }
+            }
+            if(pp==6)
+            {
+                if(Mes<=12)
+                {
+                Mes=Mes+1;
+                lcd.locate(0,1);
+                lcd.printf("Mes:%d",Mes);
+                }
+                else
+                {
+                Mes=0;
+                }
+            }
+            if(pp==7)
+            {
+                Anno=Anno+1;
+                lcd.locate(0,1);
+                lcd.printf("Ano:%d",Anno);
+            }
+            
+        }
+        if(Decre.falling())
+        {
+            
+            if(pp==1)
+            {
+                if(Hora>0)
+                {
+                Hora=Hora-1;
+                lcd.locate(0,1);
+                lcd.printf("Hora[0-23]:%d",Hora);
+                }
+            }   
+            if(pp==2)
+            {
+                if(Minuto>0)
+                {
+                Minuto=Minuto-1;
+                lcd.locate(0,1);
+                lcd.printf("Min[0-59]:%d",Minuto);
+                }
+            }
+            if(pp==3)
+            {
+                if(Segundo>0)
+                {
+                Segundo=Segundo-1;
+                lcd.locate(0,1);
+                lcd.printf("Seg[0-59]:%d",Segundo);
+                }
+            }
+            if(pp==4)
+            {
+                if(Dia>0)
+                {
+                Dia=Dia-1;
+                lcd.locate(0,1);
+                lcd.printf("Dia[1-7]:%d",Dia);
+                }
+            }
+            if(pp==5)
+            {
+                if(Dya>0)
+                {
+                Dya=Dya-1;
+                lcd.locate(0,1);
+                lcd.printf("Dia:%d",Dya);
+                }
+            }
+            if(pp==6)
+            {
+                if(Mes>0)
+                {
+                Mes=Mes-1;
+                lcd.locate(0,1);
+                lcd.printf("Mes:%d",Mes);
+                }
+            }
+            if(pp==7)
+            {
+                if(Anno>0)
+                {
+                Anno=Anno-1;
+                lcd.locate(0,1);
+                lcd.printf("Ano:%d",Anno);
+                }
+            }
+            
+        }
+        if(Start==1)
+        { 
+            Write=0;
+            Read=0;
+            tm.mon=Mes;
+            tm.year=Anno;
+            tm.hour=Hora;
+            tm.min=Minuto;
+            tm.sec=Segundo;
+            tm.date=Dya;
+            rtc.setTime(tm, false, false);
+            wait(0.3);
+            Start=0;
+            myled=0;
+        }
+        if(Encendido==1)
+        {
+            myled1=0;
+            rtc.startClock();
+            wait(0.2);
+            flag2=1;
+            Encendido=0;
+        }
+        
+        if(flag2==1)
+        {
+            rtc.getTime(tm);
+            if(Panta.falling())
+            {      
+                p=p+1;
+                //flag=1;
+                if(p==1)
+                {
+                    lcd.cls();
+                    lcd.printf("Ingrese la Hora");               
+                }
+                if(p==2)
+                {
+                    lcd.cls();
+                    lcd.printf("Ingrese Minutos");   
+                }
+                if(p==3)
+                {
+                    lcd.cls();
+                    lcd.printf("Ingrese Dia(1-7)");
+                }
+                if(p==4)
+                {
+                    lcd.cls();
+                    lcd.printf("Guardados !");
+                    wait(1);
+                    p=0;
+                }
+            }
+            if(Aumen2==1)
+            {
+                if(p==1)
+                {
+                    if(c<=24)
+                    {
+                        lcd.cls();
+                        c=c+1;
+                        lcd.locate(0,0);
+                        lcd.printf("Ingrese la Hora");
+                        lcd.locate(0,1);
+                        lcd.printf("Hora: %d",c);
+                    }
+                    else
+                    {
+                        c=0;
+                    }
+                }
+                if(p==2)
+                {
+                    if(d<=60)
+                    {
+                        lcd.cls();
+                        d=d+1;
+                        lcd.locate(0,0);
+                        lcd.printf("Ingrese Minutos");
+                        lcd.locate(0,1);
+                        lcd.printf("Minutos: %d",d);
+                    }
+                    else
+                    {
+                        d=0;
+                    }
+                }    
+                if(p==3)
+                {
+                   if(e<=7)
+                    {
+                        lcd.cls();
+                        e=e+1;
+                        lcd.locate(0,0);
+                        lcd.printf("Ingrese Dia(1-7)");
+                        lcd.locate(0,1);
+                        lcd.printf("Dia: %d",e);    
+                    }
+                    else
+                    {
+                        e=0;    
+                    } 
+                }  
+                wait(0.1);
+                Aumen2=0;
+            }  
+            
+             if(Decre2==1)
+            {
+                if(p==1)
+                {
+                    if(c>0)
+                    {
+                        lcd.cls();
+                        c=c-1;    
+                        lcd.locate(0,0);
+                        lcd.printf("Ingrese la Hora");
+                        lcd.locate(0,1);
+                        lcd.printf("Hora: %d",c);
+                    }
+                    else
+                    {
+                        c=0;
+                    }
+                }
+                if(p==2)
+                {   
+                    if(d>0)
+                    {
+                        lcd.cls();
+                        d=d-1;    
+                        lcd.locate(0,0);
+                        lcd.printf("Ingrese Minutos");
+                        lcd.locate(0,1);
+                        lcd.printf("Minutos: %d",d);
+                    }
+                    else
+                    {
+                        d=0;
+                    }                        
+                }
+                if(p==3)
+                {
+                    if(e>0)
+                    {
+                        lcd.cls();
+                        e=e-1;    
+                        lcd.locate(0,0);
+                        lcd.printf("Ingrese Dia(1-7)");
+                        lcd.locate(0,1);
+                        lcd.printf("Dia: %d",e);
+                    }
+                    else
+                    {
+                        e=0;
+                    }      
+                }
+                wait(0.1);
+                Decre2=0;
+                
+            }
+            if((p==0))
+            {
+                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",tm.year);
+        
+                if (tm.wday == 6){
+                    lcd.printf("   Sun\n");}
+                if (tm.wday == 7){
+                    lcd.printf("   Mon\n");}   
+                if (tm.wday == 1){
+                    lcd.printf("  Tues\n");}
+                if (tm.wday == 2){
+                    lcd.printf("   Wed\n");}
+                if (tm.wday == 3){
+                    lcd.printf("  Thur\n");}
+                if (tm.wday == 4){
+                    lcd.printf("   Fri\n");}
+                if (tm.wday == 5){
+                    lcd.printf("   Sat\n");}
+            }
+        }
+    }      
+}
+
+    
+