Reloj Ds1307

Dependencies:   DS1307 DebouncedIn TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
mescobart22
Date:
Wed May 14 14:18:08 2014 +0000
Commit message:
Tarea Reloj Ds1307; activa y desactiva alarma, ademas se puede modificar y cuadrar la hora.; Mauricio Escobar Tobon- Breiner Choles

Changed in this revision

DS1307.lib Show annotated file Show diff for this revision Revisions of this file
DebouncedIn.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
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1307.lib	Wed May 14 14:18:08 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/harrypowers/code/DS1307/#c3e4da8feb10
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebouncedIn.lib	Wed May 14 14:18:08 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/cmorab/code/DebouncedIn/#dc1131de43e8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed May 14 14:18:08 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/lcorralesc1/code/TextLCD/#0e0132807662
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 14 14:18:08 2014 +0000
@@ -0,0 +1,350 @@
+#include "ds1307.h"
+ #include "TextLCD.h"
+ #include "mbed.h"
+#include "DebouncedIn.h"
+ //Mauricio Escobar Tobon    Breiner Choles
+ Serial pc(USBTX, USBRX); // tx, rx  for debug and usb pc comunications
+ //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD40x2); // rs, e, d4-d7
+ TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); 
+ DS1307 my1307(PTE0,PTE1); // start DS1307 class and give it pins for connections of the DS1307 device
+DebouncedIn p1(PTE20);
+DebouncedIn p2(PTE21);
+DebouncedIn p3(PTE22);
+int contador = 1;
+int contador2 = 0;
+ int horas1;
+ int min1=-1;
+ int sec1=0; 
+ int column;
+ int fila;
+ int C2=0x18; // desplaza izquierda
+ int C3=0x1A; // desplaza derecha
+ int C4=0x0C; // quito cursor bajo
+ int C1=0x0F;
+
+ DigitalOut sound(PTC5); //Salida de Audio Digital
+bool k=false;  //bandera que indica que la alarma esta o no activada
+bool on=false;  //Bandera que indica que la alarma esta o no sonando
+bool apagar=false;
+ int sec = 48;       // Values to set time with
+ int min = 59;
+ int horas = 06;
+ int dia = 2;
+ int date = 12;
+ int mes = 5;
+ int anio = 16;
+ int loop = 10;     // Non zero value for the while loop
+ 
+ 
+ void test_rw(int test) {
+    if (test == 0) pc.printf("Last R/W operation passed!\n\r");
+   else pc.printf("Last R/W operation failed!\n\r");
+ }
+ 
+ int main() {  
+ 
+ test_rw(my1307.settime( sec, min, horas, dia, date, mes, anio));    // Set the time on the DS1307
+ 
+ 
+        while (loop>0){        // Loop continously
+        test_rw(my1307.gettime( &sec, &min, &horas, &dia, &date, &mes, &anio));
+        lcd.locate(0,0);            // Print and refresh data on line 2 of the LCD display     
+        lcd.printf("%.2D",horas);
+        lcd.printf(":%.2D",min);
+        lcd.printf(":%.2D",sec);
+        lcd.locate(0,1);  
+        lcd.printf("%.2D",mes);
+        lcd.printf("/%.2D",date);
+        lcd.printf("/%.2D",anio);
+        
+        
+                    //Presionar Pulsador 1
+                    if(p1.falling()){  //Configurar Hora 
+                                         
+                                         if(k==true & apagar==false){ //Stop Alarm, recuerda agregar mensaje de pausa
+                                             k =false;
+                                                     wait(1);
+                                                     if(p1==0){
+                                                         apagar = true;
+                                                         lcd.locate(0,0);
+                                                         lcd.printf("Alarm Desact"); 
+                                                         wait(1);
+                                                         lcd.locate(0,0);
+                                                         lcd.printf("                  "); 
+                                                         lcd.locate(0,1);
+                                                         lcd.printf("Alarm Desact"); 
+                                                         wait(1);
+                                                         lcd.locate(0,1);
+                                                         lcd.printf("                  "); 
+                                                         horas1=0;
+                                                         min1=0;
+                                                         sec1=0;
+                                                      }//cierro p1==0
+                                                if(apagar==false){     
+                                                    sec1=sec+10;
+                                                    if(sec1>59){
+                                                        min1 = min1 +1;
+                                                        sec1 = sec1-60;
+                                                        lcd.locate(9,1); 
+                                                        lcd.printf("M.A: %.2d",min1); //actualiza, Minutos de Alarma En pantalla
+                                                     }//cierro if sec > 59
+                                             
+                                                 }//cierro Apagar == false
+                                             }//cierro k = true && apagar == false
+                                         
+                                         
+                                         if(contador ==2){
+                                        
+                                        //lcd.locate(9,0);
+                                        ++horas;
+                                        
+                                        if(horas>23){//ajuste de hora
+                                            horas = 0;
+                                            }//Fin if horas >23
+                                            
+                                        //lcd.printf("Hora: %.2D ", hours);
+                                        test_rw(my1307.settime( sec, min, horas, dia, date, mes, anio)); // Set the time on the DS1307
+                                        //wait(0.5);
+                                         
+                                         
+                                }//Cierro if contador ==2
+                                
+                                if(contador == 3){
+                                    ++min;
+                                    
+                                    if(min>59){ //Ajuste de minutos
+                                        min = 0;
+                                        } //cierro if min > 59
+                                    test_rw(my1307.settime( sec, min, horas, dia, date, mes, anio)); // Set the time on the DS1307
+                                    } //Cierro if contador ==3
+                        
+                                if(contador == 4){//configurar mes
+                                ++mes; 
+                                if(mes > 12){ //ajuste de meses
+                                    mes =1;
+                                    }//cierro mont > 12
+                                    
+                                 test_rw(my1307.settime( sec, min, horas, dia, date, mes, anio)); // Set the time on the DS1307
+                                }//cierro contador ==4
+                        
+                                
+                                if(contador ==5){
+                                        ++date;
+                                        if(mes==1 || mes ==3 || mes == 5 || mes == 7 || mes ==8 || mes ==10 || mes ==12 ){//ajuste de 31 dias 
+                                                if(date > 31){
+                                                    date=01;
+                                                }//Cierro dia >31
+                                        }//cierro condicion meses con 31 dias   
+                                    
+                                        if( mes ==4 || mes == 6 || mes == 9 || mes ==11){//ajuste de 30 dias 
+                                                if(date >30){
+                                                    date=01;
+                                                }//Cierro dia >30
+                                        }//Cierro condicion meses de 30 dias
+                                          
+                                        if(mes==2 ){//ajuste de 28 dias 
+                                                
+                                                        if((anio+2000) % 4 ==0){ //configuracion año viciesto
+                                                            if(date >29){
+                                                                date=1;
+                                                            }//cierro if date> 29        
+                                                                                               
+                                                        
+                                                        }//Cierro año viciesto
+                                                        
+                                                        if((anio+2000) % 4 != 0){ //configuracion año viciesto
+                                                            if(date >28){
+                                                                date=1;
+                                                            }//cierro if date> 28        
+                                                                                               
+                                                        
+                                                        }//Cierro año NO viciesto
+                                                    
+                                        
+                                         }//cierro if month ==2 
+                                    
+                                test_rw(my1307.settime( sec, min, horas, dia, date, mes, anio)); // Set the time on the DS1307
+                                }//cierro if contador ==5
+                                
+                                    if(contador == 6){ //Aumentar años
+                                        ++anio;
+                                     test_rw(my1307.settime( sec, min, horas, dia, date, mes, anio)); // Set the time on the DS1307   
+                                    }//cierro if contador ==6
+                 
+                    
+                                //Configuracin De Alarma
+                                if(contador2==1){
+                                    horas1++;
+                                    if(horas1>23){
+                                    horas1= 0;
+                                    }//Cierro hours1>23                                        
+                                    lcd.locate(9,0);
+                                    lcd.printf("H.A: %.2d",horas1);
+                                    }//Cierro if contador2==1
+                                
+                                if(contador2==2){
+                                    min1++;
+                                    if(min1>59){
+                                    min1= 0;
+                                    }//Cierro hours1>23                                        
+                                    lcd.locate(9,1);
+                                    lcd.printf("M.A: %.2d",min1);
+                                    
+                                    }//Cierro if contador2==1
+                                
+                    
+                    }//Fin p1.falling 
+                    
+                    //Presionar Pulsador 2
+                    if(p2.falling()){ //Reset
+                        contador = contador+1;
+                        
+                        
+                                if(contador>0){
+                                    contador2=0;
+                                    }
+                                    
+                                if(contador ==1){
+                                    lcd.locate(0,0);
+                                    lcd.printf("1-Reset");
+                                    wait(0.6);
+                                    lcd.printf("               ");
+                                    }//cierro if contador ==1
+                                    
+                                if(contador==2){ //configurar Hora
+                                    lcd.locate(0,0);
+                                    
+                                    lcd.printf("2-Conf. hora");
+                                    wait(0.6);
+                                    lcd.locate(0,0);
+                                    lcd.printf("                 ");
+                                    
+                                    }//Cierro if contador ==2
+                                    
+                                    if(contador==3){ //configurar minutos
+                                    lcd.locate(0,0);
+                                    
+                                    lcd.printf("3-Conf. Min");
+                                    wait(0.6);
+                                    lcd.locate(0,0);
+                                    lcd.printf("                   ");
+                                    
+                                    }//Cierro if contador ==3
+                                    
+                                    if(contador ==4){
+                                        lcd.locate(0,0);
+                                        lcd.printf("4-Conf. Mes");
+                                        
+                                        wait(0.6);
+                                        lcd.locate(0,0);
+                                        lcd.printf("                   ");
+                                        }//cierro if contador ==4
+                                        
+                                    if(contador == 5){
+                                        lcd.locate(0,0);
+                                        lcd.printf("5-Conf. Dia");
+                                        
+                                        wait(0.6);
+                                        lcd.locate(0,0);
+                                        lcd.printf("                   ");
+                                        
+                                        }//Cierro if contador == 5
+                            
+                                    if(contador ==6){
+                                        lcd.locate(0,0);
+                                        lcd.printf("5-Conf. año"); //Se aumentan años en p1 y se disminuyen con p3 (ver p3 debajo)
+                                        
+                                        wait(0.6);
+                                        lcd.locate(0,0);
+                                        lcd.printf("                   ");
+                                        }//Cierro if contador ==6
+                                        
+                                        if(contador>6){ //Reset Contador
+                                            contador =1;
+                                            lcd.locate(0,0);
+                                            lcd.printf("Config. Correct");
+                                            wait(0.6);
+                                            lcd.locate(0,0);
+                                            lcd.printf("                   ");
+                                            }//Cierro contador > 6
+                                        
+                        }//Cierro if p2.falling()
+                        
+                        //Presionar Pulsador 3
+                        if(p3.falling()){
+                            
+                            if(contador==6){
+                                --anio;
+                                test_rw(my1307.settime( sec, min, horas, dia, date, mes, anio)); // Set the time on the DS1307   
+                                contador2=0;    
+                                        
+                                }//Cierro if contador == 6
+                            
+                            if(contador != 6){
+                            
+                            contador=1; //Se asegura que no interceda a configurar la hora como loco cuando se configura la alarma
+                            contador2++; 
+                                  if(contador2==1){      
+                                  lcd.locate(0,0);
+                                  lcd.printf("Alarm Hour");
+                                  wait(0.6);
+                                  lcd.locate(0,0);
+                                  lcd.printf("                  ");                         
+                                  } //cierro contador2 ==1
+                                  
+                                  if(contador2==2){      
+                                  lcd.locate(0,1);
+                                  lcd.printf("Alarm Minutes");
+                                  wait(0.6);
+                                  lcd.locate(0,1);
+                                  lcd.printf("                  ");                         
+                                  } //cierro contador2 ==1
+                                  
+                                  if(contador2>2){
+                                    contador2=0;
+                                    lcd.locate(0,0);
+                                    lcd.printf("Activate");
+                                    wait(0.6);
+                                    k = true; //alarma activada
+                                    apagar=false;
+                                    }//cierro if contador2 >2
+                                    
+                            }//Cierro contador != 6
+                            
+                            }//cierro if p3.falling()
+                    
+                    //Activacion De Alarma
+                    if(horas == horas1 && k == true && apagar ==false){
+                        if(min == min1){
+                            if(sec>=sec1 && sec<=(sec1+10)){
+                                on = true;
+                                sound = 0;
+                                for(int i=1; i<= 1000; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                                sound = 0;
+                                wait(0.0001);  // Medio ciclo de dureza Arriba
+                                sound=1;
+                                wait(0.0001); // Medio ciclo Abajo
+                                
+                                    if(k==false){
+                                    break; 
+                                     }//cierro if on==false
+                              }//Cierro For
+                                
+                            }//Cierro Sec>=0 && sec <30
+                          }//Cierro min == min1
+                        
+                        }//cierro horas==hours1
+                   
+                    if(sec1>0 & k==false){ //alarma encendida, reactiva k para poder iniciar nuevamente cuando el tiempo se alcance otra vez
+                    k = true;
+                    }//Cierro if sec1>0
+                    
+        } //Cierro While loop >0
+        
+        
+        
+    }//Cierro Main()
+ 
+ 
+ 
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed May 14 14:18:08 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file