por medio del modulo i2c se realizo un reloj con alarma al cual se el configura la hora actual y la alarma por medio de botones y un encoder.

Dependencies:   Debounced QEI RTC-DS1307 TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
lopjohn_26
Date:
Tue May 06 02:40:21 2014 +0000
Commit message:
reloj y alarma

Changed in this revision

Debounced.lib Show annotated file Show diff for this revision Revisions of this file
QEI.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
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 98d22ab8a13c Debounced.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Tue May 06 02:40:21 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
diff -r 000000000000 -r 98d22ab8a13c QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Tue May 06 02:40:21 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r 98d22ab8a13c RTC-DS1307.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC-DS1307.lib	Tue May 06 02:40:21 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/leihen/code/RTC-DS1307/#5627b407e097
diff -r 000000000000 -r 98d22ab8a13c TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Tue May 06 02:40:21 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/javiernegrette/code/TextLCD/#419979c1e228
diff -r 000000000000 -r 98d22ab8a13c debug.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debug.h	Tue May 06 02:40:21 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 98d22ab8a13c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 06 02:40:21 2014 +0000
@@ -0,0 +1,264 @@
+#include "mbed.h"
+#include "Rtc_Ds1307.h"
+#include "TextLCD.h"
+#include "DebouncedIn.h"
+#include "QEI.h"
+
+//RtcCls rtc(p28, p27, p29, true);
+Rtc_Ds1307 rtc(PTC9, PTC8);
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); //Puertos LCD rs, e, d4, d5, d6, d7
+PwmOut sound(PTA12);
+   
+   
+DigitalOut led1(LED1);      
+DigitalOut led2(LED2);      
+DigitalOut led3(LED3);      
+int a, kp, sp, kd, ki, valor;
+int hr, mn, se, di, me, an, ho;
+int loop = 10;
+
+int encod(int);
+
+int encod(){
+    sp=0;
+    QEI Encoder (PTA1, PTA2, NC, 624);
+    DebouncedIn bot1(PTC12);    //cambiar la posición (CONECTO ESTA ENTRADA A LA ULTIMA SALIDA DEL ENCONDER, ASI SE UTILIZARA EL BOTON DEL ENCODER)
+    DebouncedIn bot4(PTC17);
+    int C1=0x0E;
+    //int C4=0x0C;
+    
+
+    
+    led1=led2=1;
+    
+    lcd.writeCommand(C1);   //comando para mostrar el cursor en el LCD
+                       
+    lcd.locate(0,0);        // Ubica e imprime nombre de los parámetros en del PID en la pantalla LCD
+    lcd.printf("dato=");
+   
+    
+   
+     //Inicio del ciclo
+     
+while(1) {
+           if (bot1.falling()) {            //----------------- Aumenta de posición el cursor a la primera línea de menu
+               
+            sound=1.0f;
+            wait(0.1);
+            sound=0;
+               
+               break;
+               }
+         
+                        valor = Encoder.getPulses();    //------------- Asigna el valor de los pulsos del encoder a una variable llamada "valor"                                                
+                       
+                       
+                        sp = sp + valor;                //------------- Asigna el valor del encoder al parámetro sp y tiene en cuenta el valor anterior
+                        Encoder.reset();                //------------- Resetea el valor del encoder
+                        if (sp<0){
+                            sp=0;                       //------------- No se admite valores negativos
+                            }
+                        
+                        lcd.locate(4,0);                //------------- Ubica e imprime el parámetro "sp" en la pantalla LCD
+                        lcd.printf("=    ",sp);
+                        lcd.locate(5,0);
+                        lcd.printf("%i",sp);
+                        wait(0.15);
+                        
+                                                
+                                                
+         }
+       
+return sp;
+    }
+
+
+
+
+
+
+
+
+int main() {
+
+inicio:
+
+DebouncedIn bot1(PTC10);    
+DebouncedIn bot2(PTC11);
+DebouncedIn bot3(PTC16); 
+DebouncedIn bot4(PTC17); 
+
+    Rtc_Ds1307::Time_rtc tm = {};
+    
+    while(1) {
+        
+        lcd.printf("configuracion   reloj y alarma  \n");
+        wait(1.5);
+        lcd.cls();
+        lcd.printf("oprima uno de   los botones \n");
+        wait(1.5);
+        lcd.cls();
+        lcd.printf("a: configurar el reloj\n");
+        wait(2);
+        lcd.cls();
+        lcd.printf("b: configurar laalarma\n");
+        wait(2);
+        lcd.cls();
+        lcd.printf("c: iniciar  el reloj\n");
+        wait(2);
+        lcd.cls();
+        lcd.printf("d: salir de  configuracion \n");
+        wait(2);
+        lcd.cls();
+        lcd.printf("digite la opcion     elegida\n");
+        wait(5);
+        
+        lcd.cls();
+        
+
+            if (bot1.falling()) {
+            lcd.cls();
+            
+            lcd.printf("ingrese hora\n");
+            wait(1);
+            lcd.cls();
+            tm.hour = encod();
+            lcd.cls();
+            lcd.printf("ingrese minutos\n");
+            wait(1);
+            lcd.cls();
+            tm.min = encod();
+            lcd.cls();
+            lcd.printf("ingrese segundos\n");
+            wait(1);
+            lcd.cls();
+            tm.sec = encod();
+            lcd.cls();
+            lcd.printf("ingrese ano\n");
+            wait(1);
+            lcd.cls();
+            tm.year = encod();
+            lcd.cls();
+            lcd.printf("ingrese mes\n");
+            wait(1);
+            lcd.cls();
+            tm.mon = encod();
+            lcd.cls();
+            lcd.printf("ingrese dia\n");
+            wait(1);
+            lcd.cls();
+            tm.date = encod();
+            lcd.cls();
+            
+            rtc.setTime(tm, false, false);
+            }
+        
+            if (bot2.falling()) {
+            lcd.cls();
+
+            lcd.printf("ingrese hora\n");
+            wait(1);
+            lcd.cls();
+            hr = encod();
+            lcd.cls();
+            lcd.printf("ingrese minutos\n");
+            wait(1);
+            lcd.cls();
+            mn = encod();
+            lcd.cls();
+            lcd.printf("ingrese segundos\n");
+            wait(1);
+            lcd.cls();
+            se = encod();
+            lcd.cls();
+            lcd.printf("ingrese ano\n");
+            wait(1);
+            lcd.cls();
+            an = encod();
+            lcd.cls();
+            lcd.printf("ingrese mes\n");
+            wait(1);
+            lcd.cls();
+            me = encod();
+            lcd.cls();
+            lcd.printf("ingrese dia\n");
+            wait(1);
+            lcd.cls();
+            di= encod();
+            lcd.cls();
+            
+            } 
+        
+            if (bot3.falling()) {
+            //  start
+            lcd.printf("realizando      inicializacion\n");
+            wait(3);
+            lcd.cls();
+            rtc.startClock();
+            }
+        
+                if (bot4.falling()) {
+                //exit
+                led1=led2=led3=1;       //------------- Flash para salir del bucle
+                wait(0.25);
+                led1=led2=led3=0;
+                lcd.printf("saliendo del      menu\n");
+                wait(1.5);
+                lcd.cls();
+                break;
+           
+                }
+            
+         
+    }
+    
+    //------------------------------sonido alarma-----------------------------------------------------------------------------------------------
+    
+    while (loop>0){        // Loop continously  
+        
+        if (rtc.getTime(tm) ) {
+                lcd.locate(0,0);
+                lcd.printf("%02d:%02d:%02d\n", tm.hour, tm.min, tm.sec);
+                lcd.printf("%02d:%02d:%02d\n", hr, mn,se);
+                wait(0.1);
+                lcd.cls();
+            }
+      
+      if ((tm.hour==hr) && (tm.min==mn) && (tm.sec==se)){
+            
+            while (1){
+                
+                sound=1.0f;
+                wait(0.3);
+                sound=0;
+                wait(0.2);
+                
+                if(bot1.falling()){
+                    se= se+20;
+                       if(se>=60){
+                        mn++;
+                        se=se-60;
+                           }
+                       if(mn>=60){
+                        hr++;
+                        mn=mn-60;
+                           }          
+                    break;       
+                }
+                
+                if(bot2.falling()){
+                    break;
+                    }
+            }
+          
+        }
+     if(bot1.falling()){
+        lcd.printf("regresando a configuracion\n");
+        break;
+        }
+    }             
+   goto inicio;     
+}
+
+
+
diff -r 000000000000 -r 98d22ab8a13c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue May 06 02:40:21 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file