Despertador

Dependencies:   QEI RTC-DS1307 TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
SSJprocesa
Date:
Sat May 21 15:45:20 2016 +0000
Commit message:
Despertador con alarma programada (Luz y Buzzer), con una RTC programada con un encoder y mostrada en un LCD16x2

Changed in this revision

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Sat May 21 15:45:20 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC-DS1307.lib	Sat May 21 15:45:20 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/leihen/code/RTC-DS1307/#5627b407e097
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Sat May 21 15:45:20 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debug.h	Sat May 21 15:45:20 2016 +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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat May 21 15:45:20 2016 +0000
@@ -0,0 +1,274 @@
+#include "mbed.h"
+#include "Rtc_Ds1307.h"
+#include "TextLCD.h"
+#include "QEI.h"
+
+TextLCD lcd(PTD5, PTD7, PTD6, PTD4, PTD2, PTC9); // rs, e, d4-d7
+Rtc_Ds1307 rtc(PTE0, PTE1);//Dato,Reloj
+QEI encoder (PTC0, PTC4, NC, 624);//pines de etrada de comparación del encoder
+DigitalIn chan(PTD3);//botón del encoder
+DigitalIn rlo(PTC3);//pulsador de la freescale para configurar la RTC
+DigitalIn rl(PTC12);//pulsador de la freescale para configurar la Alarma
+DigitalOut ledr(PTE29);//Led indicador de la alarma
+DigitalOut buzz(PTA6);//Buzzer indiciador de la alarma
+char buffer[128];
+int readptr = 0,segundos =0,cambio=0,cont=0,pla=0,pla2=0,key=0;//variables del programa
+int di=0,me=0,an=0,fle=0,mi=0,se=0,jod=0;//varaibles para la alarma
+int main() 
+{
+Rtc_Ds1307::Time_rtc tm = {};
+ledr=1;//Led apagado
+while(1){
+sk:         if(pla==1)//Rutina para la configuración de los parametros en la RCT (día,mes,año,hora,minutos,segundos,día de la samana)
+            {
+            buzz=0;//Buzzer apagado
+            ledr=1;//Led apagado
+            jod=0;
+            key=0;
+            while(rlo==1){}//anti-rebotes
+            lcd.cls();
+            while(cont==0)
+            {
+            rtc.stopClock();//para el clock de la RTC
+            lcd.locate(0,0);
+            lcd.printf("(Day 1..31)");//muestra en el LCD el parametro a asignar
+            cambio=encoder.getPulses();//valor del encoder
+            if(cambio<=1){cambio=1;}//limite inferior para este parametro
+            if(cambio>=31){cambio=31;}//limite superior para este parametro
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);//valor acutal
+            while(chan==0){encoder.reset();cont=1;}//si presiona el botón del encoder salta al siguiente parametro
+            }
+            tm.date=cambio;//asignación del valor elegido al parametro que se desea asignar en la RTC
+            cambio=0;//limpia la variable
+            while(cont==1)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("(month 1..12)");
+            cambio=encoder.getPulses();
+            if(cambio<=1){cambio=1;}
+            if(cambio>=12){cambio=12;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=2;}                  
+            }
+            tm.mon=cambio;
+            cambio=0;            
+            while(cont==2)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("(year   0-99)");
+            cambio=encoder.getPulses();
+            if(cambio<=0){cambio=0;}
+            if(cambio>=99){cambio=99;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=3;}                  
+            }
+            tm.year=cambio+2000;
+            cambio=0;
+            while(cont==3)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("(hours 0..23)");
+            cambio=encoder.getPulses();
+            if(cambio<=0){cambio=0;}
+            if(cambio>=23){cambio=23;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=4;cambio=cambio;}                  
+            }
+            tm.hour=cambio;
+            cambio=0;
+            while(cont==4)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("(minutes 0..59)");
+            cambio=encoder.getPulses();
+            if(cambio<=0){cambio=0;}
+            if(cambio>=59){cambio=59;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=5;}                  
+            }
+            tm.min=cambio;
+            cambio=0;
+            while(cont==5)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("(seconds 0..59)");
+            cambio=encoder.getPulses();
+            if(cambio<=0){cambio=0;}
+            if(cambio>=59){cambio=59;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=6;lcd.locate(0,0);lcd.printf("(              ");}                  
+            }
+            tm.sec=cambio;
+            cambio=1;
+            while(cont==6)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("(sunday=1)");
+            cambio=encoder.getPulses();
+            if(cambio<=1){cambio=1;}
+            if(cambio>=7){cambio=7;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=7;}                  
+            }
+            tm.wday=cambio;
+            cambio=0;
+            rtc.setTime(tm, false, false);
+            rtc.startClock();//inicia el conteo en la RTC
+            pla=0;
+            }
+            cont=0;
+            
+sk2:         if(pla2==1)//Rutina para la configuración de los parametros en la Alarma (día,mes,año,hora,minutos,segundos)
+            {
+            buzz=0;
+            ledr=1;
+            jod=0;
+            key=0;   
+            while(rl==1){}
+            lcd.cls();
+            while(cont==0)
+            {
+            lcd.locate(0,0);
+            lcd.printf("alm(Day 1..31)");
+            cambio=encoder.getPulses();
+            if(cambio<=1){cambio=1;}
+            if(cambio>=31){cambio=31;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=1;}
+            }
+            di=cambio;
+            cambio=0;
+            while(cont==1)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("alm(month 1..12)");
+            cambio=encoder.getPulses();
+            if(cambio<=1){cambio=1;}
+            if(cambio>=12){cambio=12;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=2;}                  
+            }
+            me=cambio;
+            cambio=0;            
+            while(cont==2)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("alm(year  0..99)");
+            cambio=encoder.getPulses();
+            if(cambio<=0){cambio=0;}
+            if(cambio>=99){cambio=99;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=3;}                  
+            }
+            an=cambio+2000;
+            cambio=0;
+            while(cont==3)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("alm(hours 0..23)");
+            cambio=encoder.getPulses();
+            if(cambio<=0){cambio=0;}
+            if(cambio>=23){cambio=23;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=4;}                  
+            }
+            fle=cambio;
+            cambio=0;
+            while(cont==4)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("alm(minutes 0..59)");
+            cambio=encoder.getPulses();
+            if(cambio<=0){cambio=0;}
+            if(cambio>=59){cambio=59;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=5;}                  
+            }
+            mi=cambio;
+            cambio=0;
+            while(cont==5)
+            {            
+            lcd.locate(0,0);
+            lcd.printf("alm(seconds 0..59)");
+            cambio=encoder.getPulses();
+            if(cambio<=0){cambio=0;}
+            if(cambio>=59){cambio=59;}
+            lcd.locate(0,1);
+            lcd.printf("    ");
+            lcd.locate(0,1);
+            lcd.printf("%d",cambio);
+            while(chan==0){encoder.reset();cont=6;lcd.locate(0,0);lcd.printf("(              ");}                  
+            }
+            se=cambio;
+            cambio=0;
+            pla2=0;
+            }
+
+            cont=0;
+   cicl:        if (rtc.getTime(tm) ) {
+                if(rlo==0){pla=1;goto sk;}//si se presiona va a la configuración de la RTC
+                if(rl==0){pla2=1;goto sk2;}//si se presiona va a la configuración de la Alarma 
+                lcd.cls();
+                lcd.locate(0,0);//muestra el valor de todos los parametros actuales en la RTC
+                lcd.printf("%02d:%02d:%02d", tm.hour, tm.min, tm.sec);
+                lcd.locate(0,1);
+                lcd.printf("%s/%02d/%02d/%4d", rtc.weekdayToString(tm.wday), tm.date, tm.mon, tm.year);       
+                if((tm.date==di)&&(tm.mon==me)&&(tm.year==an)&&(tm.hour==fle)&&(tm.min==mi)&&(tm.sec==se)){key=1;}//comparación de la Alarma
+                while(key==1)
+                    {
+                        jod++;
+                        ledr=0;buzz=1;
+                        wait(0.5);
+                        ledr=1;buzz=0;
+                        wait(0.5);
+                        if(chan!=1){key=0;jod=0;goto cicl;}//botón que para la Alarma
+                        if(jod==7){key=0;mi=mi+1;if(mi==60){mi=0;fle=fle+1;if(fle==24){fle=0;di=di+1;if(di==31){di=1;me=me+1;if(me==12){me=1;an=an+1;}}}}jod=0;//condiciones de salto 
+    
+                        }
+                    }
+                wait(0.2);
+                goto cicl;//blucle infinito hasta que suceda una interrupción
+                }
+
+         }
+            
+
+
+}
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat May 21 15:45:20 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e
\ No newline at end of file