Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Debounced QEI ds3231 TextLCD Pulse1
Revision 0:6c5518885385, committed 2019-08-30
- Comitter:
- dsuranr15
- Date:
- Fri Aug 30 14:05:20 2019 +0000
- Commit message:
- Tarea Reloj Ds3231
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Debounced.lib Fri Aug 30 14:05:20 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Pulse1.lib Fri Aug 30 14:05:20 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/tony63/code/Pulse1/#48651f86a80c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QEI1.lib Fri Aug 30 14:05:20 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Fri Aug 30 14:05:20 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/control.h Fri Aug 30 14:05:20 2019 +0000
@@ -0,0 +1,193 @@
+#include "mbed.h"
+#include <Pulse1.h>
+
+// esta libreria se usa para la comprobacion del numero que el control esta pulsando.
+
+PulseInOut irda(PTD0); // se leen los datos del irda
+Serial pc(USBTX, USBRX);
+
+// estas cadenas se identificaron previamente con ayuda del programa captura.irda se le realizo una modificacion para obtener los valores en binario
+int ok[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,1,0,1,0,0};
+int t1[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,1,1,1,1};
+int t2[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,1,1,1,1};
+int t3[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,1};
+int t4[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,1,0,1,1,1};
+int t5[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,1,0,1,1,1};
+int t6[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1};
+int t7[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,1};
+int t8[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,1,1,0,0,0,0,0,1,0,0,1,1,1};
+int t9[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,1,1,1};
+int t0[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,1,1,0,1,1};
+int po[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,1,1,1,1,1};
+int t77[33]= {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,1,0,1,0,0,1,1,1,0};
+int i=0;
+int numb=32;
+int numP[33];
+int a=0;
+int cont=0;
+int b=0;
+int si=0;
+int num=0;
+
+int control()
+{
+
+
+
+ fflush( stdin ); // se borra los datos de irda
+ num=0;
+
+ for(i=0; i<numb; ++i) { // vector que lee los datos de irda
+
+ numP[i] = irda.read_high_us(); //funcion para leer un pulso alto
+ wait_us(300);
+
+ }
+ for(i=0; i<numb; ++i) { // se transforman a binario
+ if(numP[i]<800) {
+ numP[i]=0;
+
+ } else {
+ numP[i]=1;
+ }
+
+
+ } //del for
+
+
+
+
+ a=0;
+
+ // se compara la cadena que llega con cada uno de los vectores identificados anteriormente, con el que tenga coincidencia, sera el numero.
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t1[i]) { // se compara uno a uno
+ a++; // si son iguales se suman
+ if(a==29) { // si la suma llega a 29 es porque son iguales.
+ num=1; // realiza la identificacion del numero
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t2[i]) {
+ a++;
+ if(a==29) {
+ a=0;
+ num=2;
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t3[i]) {
+ a++;
+
+ if(a==29) {
+ a=0;
+ num=3;
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t4[i]) {
+ a++;
+ if(a==29) {
+ num=4;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t5[i]) {
+ a++;
+ if(a==29) {
+ num=5;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t6[i]) {
+ a++;
+ if(a==29) {
+ num=6;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t7[i]) {
+ a++;
+ if(a==29) {
+ num=7;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t8[i]) {
+ a++;
+ if(a==29) {
+ num=8;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t9[i]) {
+ a++;
+ if(a==29) {
+ num=9;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==po[i]) {
+ a++;
+ if(a==29) {
+ num=88;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==ok[i]) {
+ a++;
+ if(a==29) {
+ num=99;
+
+
+ }
+ }
+ }
+
+ //Todos los casos se realizan igual que el primero, en este caso se hace el envio del numero
+ a=0;
+ pc.printf("\n%d",num);
+ return num; // se envia el numero
+
+
+
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/control1.h Fri Aug 30 14:05:20 2019 +0000
@@ -0,0 +1,244 @@
+#include "mbed.h"
+#include <Pulse1.h>
+#include "TextLCD.h"
+
+//PulseInOut irda(PTD0);
+//Serial pc(USBTX, USBRX);
+TextLCD lcd(PTB8,PTB9, PTB10, PTB11, PTE2, PTE3); //Pines LCD
+
+// esta libreria se realizo con la intension de verificar el correcto funcionamiento cuando necesito obtener un numero en vez de un vector.
+// los numeros siguen siendo los mismo que en control.h, la diferencia radicara en el uso de un ciclo for para obtener el numero.
+
+
+/*
+int ok[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,1,0,1,0,0};
+int t1[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,1,1,1,1};
+int t2[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,1,1,1,1};
+int t3[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,1};
+int t4[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,1,0,1,1,1};
+int t5[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,1,0,1,1,1};
+int t6[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1};
+int t7[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,1};
+int t8[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,1,1,0,0,0,0,0,1,0,0,1,1,1};
+int t9[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,1,1,1};
+int t0[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,1,1,0,1,1};
+int po[33]= {1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,1,1,1,1,1};
+int t77[33]= {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,1,0,1,0,0,1,1,1,0};
+int i=0;
+int numb=32;
+int numP[33];
+int a=0;
+int cont=0;
+int b=0;
+int si=0;
+int num=0;
+*/
+int j=0;
+int Num1=0;
+int Num2=0;
+int Num3=0;
+int Num4=0;
+int NUM=0;
+
+
+int control1(int A) // la variable a es la cantidad de digitos que va a tener el numero
+{
+ // se declaran las condiciones iniciales
+ j=0;
+ num=0;
+ NUM=0;
+ Num1=0;
+ Num2=0;
+ Num3=0;
+ Num4=0;
+ for(j=0; j<A; ++j) { // el ciclo for se va a recorrer las veces que el usuario solicita
+
+///////////////////////////////////////////////////////////////////////////////
+ fflush( stdin ); // borra lo que se tenga en el irda
+
+
+ for(i=0; i<numb; ++i) {
+
+ numP[i] = irda.read_high_us(); //funcion para leer un pulso alto
+ wait_us(300);
+
+ }
+ for(i=0; i<numb; ++i) { // el vector que leyo en irda lo convierte a binario
+ if(numP[i]<800) {
+ numP[i]=0;
+
+ } else {
+ numP[i]=1;
+ }
+
+
+ } //del for
+
+
+
+
+ a=0;
+
+ // este codigo de aca hacia abajo lo que hace es la comparacion de cada uno de los numeros, si coinciden todos los bit la salida es el numero en hecadecimal.
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t1[i]) {
+ a++;
+ if(a==29) {
+ num=1;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t2[i]) {
+ a++;
+ if(a==29) {
+ a=0;
+ num=2;
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t3[i]) {
+ a++;
+
+ if(a==29) {
+ a=0;
+ num=3;
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t4[i]) {
+ a++;
+ if(a==29) {
+ num=4;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t5[i]) {
+ a++;
+ if(a==29) {
+ num=5;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t6[i]) {
+ a++;
+ if(a==29) {
+ num=6;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t7[i]) {
+ a++;
+ if(a==29) {
+ num=7;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t8[i]) {
+ a++;
+ if(a==29) {
+ num=8;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==t9[i]) {
+ a++;
+ if(a==29) {
+ num=9;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==po[i]) {
+ a++;
+ if(a==29) {
+ num=88;
+
+
+ }
+ }
+ }
+ a=0;
+ for(i=2; i<numb; ++i) {
+ if(numP[i]==ok[i]) {
+ a++;
+ if(a==29) {
+ num=99;
+
+
+ }
+ }
+ }
+ pc.printf("\nel numero");
+ pc.printf("\n%d",num);
+ wait(2);
+ ///////////////////////////////////////////////////////////77
+ // arriba esta como se dijo la verificacion de cada uno de los numeros.
+
+ // estos codigos de abajo sirven para crear los numeros que tienen mas de una unidad, se aplica unidades, decenas, y centenas para construir el numero.
+ if(j==0) { //unidades
+ pc.printf("\nprimero");
+ Num1=num*1;
+ }
+ if(j==1) { //decenas
+ Num2=num*10;
+ }
+ if(j==2) {//centenas
+ Num3=num*100;
+ }
+ if(j==3) {
+ Num4=num*1000;
+ }
+
+
+ pc.printf("\n Antes de la suma");
+ NUM=Num1+Num2+Num3+Num4; // se realiza la suma de los numeros
+ pc.printf("\nla suma");
+ pc.printf("\n%d",NUM);
+ lcd.locate(8,0);
+ lcd.printf("\n%d",NUM);
+ wait(1);
+
+ }
+
+ a=0; // se reinician las variables de control
+ A=0;
+ pc.printf("\n%d",NUM);
+ return NUM; // se envia el numero
+
+
+
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ds3231.lib Fri Aug 30 14:05:20 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/Maxim-Integrated/code/ds3231/#11630748e2f2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Aug 30 14:05:20 2019 +0000
@@ -0,0 +1,2928 @@
+
+//Programa para la activacion de 6 alarmas.
+
+#include "mbed.h"
+#include "TextLCD.h"
+#include "control.h" //libreria creada para el control
+#include "control1.h"//libreria control con una modificacion
+#include <Pulse1.h> // libreria pulsador
+#include "DebouncedIn.h" //libreria para encoder
+#include "QEI.h" //libreria para encoder
+#include "ds3231.h" //libreria reloj
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+
+
+int p;
+int con=0;
+int m=0;
+int pos;
+int H=0;
+int s=0;
+int nu=0;
+int al=0;
+int m1=0;
+int y=0;
+int d=0;
+int ALM1[10];
+int ALM2[10];
+int ALM3[10];
+int ALM4[10];
+int ALM5[10];
+int ALM6[10];
+
+int ALM_1[4];
+int ALM_2[4];
+int ALM_3[4];
+int ALM_4[4];
+int ALM_5[4];
+int ALM_6[4];
+
+int FEC1[10];
+int FEC2[10];
+int FEC3[10];
+int FEC4[10];
+int FEC5[10];
+int FEC6[10];
+
+int FEC_1[8];
+int FEC_2[8];
+int FEC_3[8];
+int FEC_4[8];
+int FEC_5[8];
+int FEC_6[8];
+
+
+
+char alm_1[4];
+char alm_2[4];
+char alm_3[4];
+char alm_4[4];
+char alm_5[4];
+char alm_6[4];
+
+char fec_1[8];
+char fec_2[8];
+char fec_3[8];
+char fec_4[8];
+char fec_5[8];
+char fec_6[8];
+
+char buffer[32];
+char buffer1[32];
+char HORA[32];
+char FECHA[32];
+
+
+
+TextLCD LCD(PTB8,PTB9, PTB10, PTB11, PTE2, PTE3); //Pines LCD
+DebouncedIn button4(PTC12);// boton encoder
+Ds3231 rtc(D14, D15); //reloj
+QEI wheel (PTD7, PTD6, NC, 180); //encoder
+
+void hora() //funcion creada para leer la hora del reloj
+{
+
+
+ time_t epoch_time;
+ ds3231_cntl_stat_t rtc_control_status = {0,0};
+ rtc.set_cntl_stat_reg(rtc_control_status);
+
+
+
+ epoch_time = rtc.get_epoch();
+ strftime(buffer, 32, "%H:%M:%S", localtime(&epoch_time)); // La hora se guarda en buffer y HORA para despues ser mostrada.
+ strftime(HORA, 32, "%H%M", localtime(&epoch_time));
+ LCD.cls();
+ LCD.locate(4,0);
+ LCD.printf("%s", buffer);
+
+ strftime(buffer1, 32, "%a %Y-%m-%d", localtime(&epoch_time));// La fecha se guarda en buffer y FECHA para despues ser mostrada.
+ strftime(FECHA, 32, "%Y%m%d", localtime(&epoch_time));
+
+ LCD.locate(1,1);
+ LCD.printf("%s", buffer1);
+ wait(1);
+
+
+
+
+
+
+}
+
+
+
+
+
+
+int main()
+{
+
+ led1=0; // les iniciales de las alarmas
+ led2=1;
+
+
+
+
+ while(1) {
+
+
+
+ hora(); // se toma la hora de la funcion.
+ LCD.cls();
+ wheel.reset();
+
+ p=irda.read_high_us(4000); // se lee el irda
+
+
+ if((strncmp(HORA,alm_1,4)==0) && (strncmp(FECHA,fec_1,4)==0)&&(y==0) ) { // si la alarma es igual en hora y fecha se activa
+
+ LCD.cls();
+ LCD.printf("ALM_1_0N");
+ led2=0;
+ wait(5);
+ y=1;
+ led2=1;
+
+
+ }
+
+ if((strncmp(HORA,alm_2,4)==0) && (strncmp(FECHA,fec_2,4)==0)&&(y==0)) { // si la alarma es igual en hora y fecha se activa
+ LCD.cls();
+ LCD.printf("ALM_2_0N");
+ led2=0;
+ wait(5);
+ y=1;
+ led2=1;
+
+
+ }
+
+ if((strncmp(HORA,alm_3,4)==0) && (strncmp(FECHA,fec_3,4)==0)&&(y==0)) {// si la alarma es igual en hora y fecha se activa
+ LCD.cls();
+ LCD.printf("ALM_3_0N");
+ led2=0;
+ wait(5);
+ y=1;
+ led2=1;
+
+
+ }
+
+ if((strncmp(HORA,alm_4,4)==0) && (strncmp(FECHA,fec_4,4)==0)&&(y==0)) {// si la alarma es igual en hora y fecha se activa
+ LCD.cls();
+ LCD.printf("ALM_4_0FF");
+ led1=1;
+ wait(5);
+ y=1;
+ led1=0;
+
+
+ }
+
+ if((strncmp(HORA,alm_5,4)==0) && (strncmp(FECHA,fec_5,4)==0)&&(y==0)) {// si la alarma es igual en hora y fecha se activa
+ LCD.cls();
+ LCD.printf("ALM_5_0FF");
+ led1=1;
+ wait(5);
+ y=1;
+ led1=0;
+
+
+ }
+
+ if((strncmp(HORA,alm_6,4)==0) && (strncmp(FECHA,fec_6,4)==0)&&(y==0)) {// si la alarma es igual en hora y fecha se activa
+ LCD.cls();
+ LCD.printf("ALM_6_0FF");
+ led1=1;
+ wait(5);
+ y=1;
+ led1=0;
+
+
+ }
+
+
+///////////////////////////////////////////////////////////////////////////////
+//ENCODER
+//////////////////////////////////////////////////////////////////////////////
+
+// esta parte del codigo se utiliza para realizar la lectura inicial del enconder, una vez se presiona el boton entra en modo encoder.
+ if(button4.falling()) {
+ con++;
+
+ while(con==1) {
+ if(button4.falling()) {
+ con++;
+ wheel.reset();
+ }
+
+ m=wheel.getPulses();// se lee la posicion del encoder
+
+ if(m>3) {
+ wheel.reset();
+ m=3;
+ }
+ if(m<0) {
+ wheel.reset();
+ m=0;
+ }
+
+ LCD.cls();
+ LCD.locate(0,0);
+ LCD.printf("1-H0RA");
+ LCD.locate(8,0);
+ LCD.printf("2-FECHA");
+ LCD.locate(0,1);
+ LCD.printf("3-ALARMA");
+
+ LCD.locate(13,1);
+ LCD.printf("%i",m);
+ wait(0.5);
+ if(button4.falling()) { // al pulsar el encoder se entra en el siguiente menu
+ pos=m;
+ con++;
+ }
+
+ }
+ con=0;
+
+ }
+
+
+///////////////////////////////////////////////////////////////////////////////
+//CONTROL
+//////////////////////////////////////////////////////////////////////////////
+
+// Esta parte del codigo permite seleccionar el modo control.
+
+ if(p!=-1) { // al inicio se declara un p= irda, cuando se oprime el boton por un tiempo se vuelve -1 y nos permite entrar en modo control
+
+ fflush( stdin );
+ LCD.cls();
+ LCD.locate(0,0);
+ LCD.printf("1-H0RA");
+ LCD.locate(8,0);
+ LCD.printf("2-FECHA");
+ LCD.locate(0,1);
+ LCD.printf("3-ALARMA");
+ wait(1);
+ control();
+ if(num==1) { // se realiza una conversion de los datos enviados por el control
+ pos=1;
+ } else if(num==2) {
+ pos=2;
+ } else if (num==3) {
+ pos=3;
+ }
+
+ p=-1;
+
+ }
+///////////////////////////////////////////////////////////////////////////////
+//CASOS MENU
+//////////////////////////////////////////////////////////////////////////////
+
+
+ nu=0;
+ switch (pos) {
+ case 1: // el caso 1 configura la hora, ya sea con control o con encoder
+ LCD.cls();
+ LCD.printf("1-H0RA");
+ wait(2);
+ ds3231_time_t rtc_time;
+
+ //while(H==0) {
+ LCD.cls();
+ LCD.printf("C0NFIGURACI0N H0RA");
+ wait(2);
+ wheel.reset();
+
+ H=1;
+ m=0;
+
+
+ while(H==1) { //configuracion de hora
+ //hasta que no se de ok con encoder o se de la hora con reloj no sale del ciclo
+
+ LCD.cls();
+ LCD.printf("H0RA");
+ LCD.locate(13,0);
+ LCD.printf("%i",m );
+
+ p=irda.read_high_us(4000); // leer el irda
+ m=wheel.getPulses();
+ wait(0.5);
+
+ if(button4.falling()) {
+ wheel.reset();
+ H=H++;
+
+ }
+ if(p!=-1) {
+ m=0;
+ LCD.cls();
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ LCD.cls();
+ LCD.printf("H0RA");
+ m=control1(2);
+ H++;
+
+ }
+ rtc_time.hours = m;
+
+ }
+ m=0;
+ while(H==2) { //configuracion de minutos
+
+ LCD.cls();
+ LCD.printf("MINUT0S");
+ LCD.locate(13,0);
+ LCD.printf("%i",m );
+
+
+ p=irda.read_high_us(4000);
+ m=wheel.getPulses();
+ wait(0.5);
+
+
+
+ if(button4.falling()) {//configuracion de minutos con encoder
+ wheel.reset();
+ H=H++;
+
+ }
+ if(p!=-1) { //configuracion de minutos con control
+ m=0;
+ LCD.cls();
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ LCD.cls();
+ LCD.printf("MINUTOS");
+ m=control1(2);
+ H++;
+
+ }
+ rtc_time.minutes = m; // se graba en la memoria del reloj los minutos
+
+ }
+ m=0;
+ while(H==3) { //configuracion de segundos
+
+ LCD.cls();
+ LCD.printf("SEGUND0S");
+ LCD.locate(13,0);
+ LCD.printf("%i",m );
+
+
+ p=irda.read_high_us(4000);
+ m=wheel.getPulses();
+ wait(0.5);
+
+
+
+ if(button4.falling()) {
+ wheel.reset();
+ H=H++;
+ }
+ if(p!=-1) { // modo control
+ m=0;
+ LCD.cls();
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ LCD.cls();
+ LCD.printf("SEGUND0S");
+ m=control1(2);
+ H++; //variable para avanzar al otro modo
+
+
+ }
+ rtc_time.seconds = m; // se graba en la memoria del reloj los segundos
+
+ }
+
+
+
+ //}
+ rtc_time.mode = false; //formato 24 horas del reloj
+ rtc.set_time(rtc_time); // se guarda la hora
+
+
+ break;
+ case 2:
+
+ ds3231_calendar_t rtc_calendar; // variable para configurar el calendario
+ LCD.cls();
+ LCD.printf("2-FECHA");
+ wait(2);
+
+
+ //while(H==0) {
+ LCD.cls();
+ LCD.printf("C0NFIGURACI0N FECHA");
+ wait(2);
+ wheel.reset();
+
+ H=1;
+ m=0;
+
+
+ while(H==1) { // configuracion del dia de la semana
+ LCD.cls();
+ LCD.printf("DIA 1-7");
+ LCD.locate(13,0);
+ LCD.printf("%i",m );
+
+ p=irda.read_high_us(4000);
+ m=wheel.getPulses(); // lectura del encoder
+
+ wait(0.5);
+
+
+ if(button4.falling()) {
+ wheel.reset();
+ H=H++;
+
+ }
+ if(p!=-1) { // modo control
+ m=0;
+ LCD.cls();
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ LCD.cls();
+ LCD.printf("DIA 1-7");
+ m=control1(1);
+
+ H++;
+ wait(2);
+
+ }
+ rtc_calendar.day = m; // se guarda el dia en el reloj
+
+
+
+ }
+ m=0;
+ wheel.reset();
+ while(H==2) { // configuracion del dia igual que en los casos anteriores, se define por control o por encoder
+
+ LCD.cls();
+ LCD.printf("DIA");
+ LCD.locate(13,0);
+ LCD.printf("%i",m );
+
+
+ p=irda.read_high_us(4000);
+ m=wheel.getPulses();
+ wait(0.5);
+
+
+
+ if(button4.falling()) {
+ wheel.reset();
+ H=H++;
+
+ }
+
+ if(p!=-1) { // configuracion del dia por control
+ m=0;
+ LCD.cls();
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ LCD.cls();
+ LCD.printf("DIA");
+ m=control1(2);
+
+ H++;
+ wait(2);
+
+ }
+ rtc_calendar.date = m; // se guarda la variable dia
+
+ }
+ m=0;
+ wheel.reset();
+ while(H==3) { // configuracion del dia igual que en los casos anteriores, se define por control o por encoder
+
+ LCD.cls();
+ LCD.printf("MES");
+ LCD.locate(13,0);
+ LCD.printf("%i",m );
+
+
+ p=irda.read_high_us(4000);
+ m=wheel.getPulses();
+ wait(0.5);
+
+
+
+ if(button4.falling()) { // modo encoder
+ wheel.reset();
+ H=H++;
+
+ }
+
+ if(p!=-1) { // configuracion del dia por control
+ m=0;
+ LCD.cls();
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ LCD.cls();
+ LCD.printf("MES");
+ m=control1(2);
+
+ H++;
+ wait(2);
+
+ }
+ rtc_calendar.month = m; // se guarda la variable dia
+
+ }
+ m=0;
+ wheel.reset();
+
+
+ while(H==4) { // se configura igual que el dia y el mes
+
+ LCD.cls();
+ LCD.printf("YEAR");
+ LCD.locate(13,0);
+ LCD.printf("%i",m );
+
+
+
+ m=wheel.getPulses(); // datos del encoder
+ wait(0.5);
+
+
+
+
+
+
+
+ if(button4.falling()) {
+ wheel.reset();
+ H=H++;
+
+ }
+ p=irda.read_high_us(4000);
+ if(p!=-1) {
+ m=0;
+ LCD.cls();
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ LCD.cls();
+ LCD.printf("YEAR");
+ m=control1(2);
+
+ H++;
+ wait(1);
+
+ }
+ rtc_calendar.year = m; // variable para guardar el año
+
+
+ }
+
+
+
+
+ //}
+ //write calendar registers
+ rtc.set_calendar(rtc_calendar);
+
+
+
+
+ break;
+
+ case 3: // casos de alarmas
+
+ LCD.cls();
+ LCD.locate(0,0);
+ LCD.printf(" 0N 1 2 3 ");
+ LCD.locate(0,1);
+ LCD.printf("0FF 4 5 6 ");
+
+
+ m=0;
+ LCD.locate(13,1);
+ LCD.printf("%i",m);
+ s=0;
+ while(s!=1) {
+ p=irda.read_high_us(4000);
+ if(p!=-1) { // modo control
+ fflush( stdin );
+ LCD.locate(16,0);
+ LCD.printf("C");
+ wait(1);
+ nu=control();
+ p=-1;
+ s=1;
+ }
+
+ if(button4.falling()) { // modo encoder
+ con++;
+ wheel.reset();
+ while(con==1) {
+ if(button4.falling()) {
+ con++;
+ }
+ m=wheel.getPulses();
+ if(m>9) {
+ m=9;
+ }
+ if(m<0) {
+ m=1;
+ }
+ LCD.locate(13,1);
+ LCD.printf("%i",m);
+ wait(0.5);
+ if(button4.falling()) {
+ nu=m;
+ con++;
+ s=1;
+ }
+ }
+ con=0;
+ }
+ }
+
+
+
+ switch (nu) {
+ case 1: // configuracion alarma 1
+ LCD.cls();
+ LCD.printf(" ALM 1");
+ al=0;
+ con=0;
+ wait(1);
+ int x=0;
+ while(x==0) {
+
+ if(button4.falling()) {
+ con++;
+
+ while(con==1) { // entra al modo encoder
+ if(button4.falling()) {
+ con++;
+ }
+ m=wheel.getPulses();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 ENC0DER");
+
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) { //ciclo para crear el vector alarma,
+ ALM1[2]=0; // como ALM es un entero en la posicion donde va a ir los : se pone un cero para que no ponga problema
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM1[j]=num; // correspondiente al ciclo for se ubica el numero en la posicion
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM1[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ wheel.reset(); // borra los datos del encoder
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+
+
+ for(j=3; j<5; ++j) { // en el mismo vector se configura los minutos, nuevamente el ciclo for es para recorrer el vector
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM1[j]=num; // se recorre el vector
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM1[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+
+///////////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {// se configura el vector FEC, primeramente va el año
+ FEC1[4]=0; // estas dos posiciones es donde se van a poner "-" para no tener problemas despues se ponen en cero
+ FEC1[7]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC1[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC1[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) { // se configura de la misma manera que los dos anteriores
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC1[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC1[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {// se configura de la misma manera que los anteriores
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC1[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC1[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+//////////////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A1");
+ for(j=0; j<5; ++j) { // con este ciclo se muestra en pantalla la hora configurada
+ //
+ LCD.locate(2,0);
+ LCD.printf(":"); // el cero se dejo para poner en pantalla este simbolo
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM1[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) { //con el ciclo for se imprime la fecha
+ //
+ LCD.locate(4,1);
+ LCD.printf("-"); // los dos ceros se pusieron para poner este simbolo
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC1[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_1[0]=ALM1[0]; // lo que se hace con esto es quitar el cero que se añadio
+ ALM_1[1]=ALM1[1];
+ ALM_1[2]=ALM1[3];
+ ALM_1[3]=ALM1[4];
+
+ FEC_1[0]=FEC1[0]; // se quitan los dos ceros que se añadieron para mostrar
+ FEC_1[1]=FEC1[1];
+ FEC_1[2]=FEC1[2];
+ FEC_1[3]=FEC1[3];
+ FEC_1[4]=FEC1[5];
+ FEC_1[5]=FEC1[6];
+ FEC_1[6]=FEC1[8];
+ FEC_1[7]=FEC1[9];
+
+ // para la comparacion de la hora con la alarma se hace con dos vectores tipo chart es por eso que
+ // realizamos la transformacion de los vectores enteros a tipo char.
+
+ sprintf(alm_1,"%d%d%d%d",ALM_1[0],ALM_1[1],ALM_1[2],ALM_1[3]);
+ sprintf(fec_1,"%d%d%d%d%d%d%d%d",FEC_1[0],FEC_1[1],FEC_1[2],FEC_1[3],FEC_1[4],FEC_1[5],FEC_1[6],FEC_1[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2; // variables para entrar en los while o salir de ellos
+
+ }
+ wait(1);
+ }
+ al=0;
+ wait(1);
+ p=irda.read_high_us(4000);
+
+ if(p!=-1) { // este modo trabaja con el control, lo unico que cambia es la manera de obtener los datos, lo otro es lo mismo para las
+ // 6 alarmas.
+ while (al!=1) {
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM1[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM1[j]);
+ wait(1);
+ }
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+ for(j=3; j<5; ++j) {
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM1[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM1[j]);
+ wait(1);
+ }
+ ////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC1[4]=0;
+ FEC1[7]=0;
+
+
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC1[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC1[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC1[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC1[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC1[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC1[j]);
+ wait(1);
+ }
+
+
+ ////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A1");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM1[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC1[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_1[0]=ALM1[0];
+ ALM_1[1]=ALM1[1];
+ ALM_1[2]=ALM1[3];
+ ALM_1[3]=ALM1[4];
+
+ FEC_1[0]=FEC1[0];
+ FEC_1[1]=FEC1[1];
+ FEC_1[2]=FEC1[2];
+ FEC_1[3]=FEC1[3];
+ FEC_1[4]=FEC1[5];
+ FEC_1[5]=FEC1[6];
+ FEC_1[6]=FEC1[8];
+ FEC_1[7]=FEC1[9];
+
+ sprintf(alm_1,"%d%d%d%d",ALM_1[0],ALM_1[1],ALM_1[2],ALM_1[3]);
+ sprintf(fec_1,"%d%d%d%d%d%d%d%d",FEC_1[0],FEC_1[1],FEC_1[2],FEC_1[3],FEC_1[4],FEC_1[5],FEC_1[6],FEC_1[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+
+ x=1;
+ wait(1);
+ al=1;
+ p=-1;
+ }
+
+ wait(1);
+ }
+
+ }
+
+ wait(1);
+ nu=0;
+ y=0;
+ con=0;
+ LCD.cls();
+ LCD.printf("ALM1 PR0GRAMADA");
+ wait(5);
+ con=2;
+
+ //todas las alarmas se configuran igual, solo cambia el nombre de los vectores.
+
+ break;
+ ///////////////////////////////////////////////////////////////////////////////7777
+ case 2:
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ LCD.cls();
+ LCD.printf(" ALM 2");
+ al=0;
+ con=0;
+ wait(1);
+ x=0;
+ while(x==0) {
+
+ if(button4.falling()) {
+ con++;
+
+ while(con==1) {
+ if(button4.falling()) {
+ con++;
+ }
+ m=wheel.getPulses();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 ENC0DER");
+
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM2[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM2[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM2[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ wheel.reset();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+
+
+ for(j=3; j<5; ++j) {
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM2[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM2[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+
+///////////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC2[4]=0;
+ FEC2[7]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC2[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC2[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC2[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC2[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC2[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC2[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+//////////////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A2");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM2[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC2[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_2[0]=ALM2[0];
+ ALM_2[1]=ALM2[1];
+ ALM_2[2]=ALM2[3];
+ ALM_2[3]=ALM2[4];
+
+ FEC_2[0]=FEC2[0];
+ FEC_2[1]=FEC2[1];
+ FEC_2[2]=FEC2[2];
+ FEC_2[3]=FEC2[3];
+ FEC_2[4]=FEC2[5];
+ FEC_2[5]=FEC2[6];
+ FEC_2[6]=FEC2[8];
+ FEC_2[7]=FEC2[9];
+
+ sprintf(alm_2,"%d%d%d%d",ALM_2[0],ALM_2[1],ALM_2[2],ALM_2[3]);
+ sprintf(fec_2,"%d%d%d%d%d%d%d%d",FEC_2[0],FEC_2[1],FEC_2[2],FEC_2[3],FEC_2[4],FEC_2[5],FEC_2[6],FEC_2[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+ }
+ wait(1);
+ }
+ al=0;
+ wait(1);
+ p=irda.read_high_us(4000);
+
+ if(p!=-1) {
+ while (al!=1) {
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM2[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM2[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM2[j]);
+ wait(1);
+ }
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+ for(j=3; j<5; ++j) {
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM2[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM2[j]);
+ wait(1);
+ }
+ ////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC2[4]=0;
+ FEC2[7]=0;
+
+
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC2[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC2[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC2[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC2[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC2[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC2[j]);
+ wait(1);
+ }
+
+
+ ////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A2");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM2[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC2[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_2[0]=ALM2[0];
+ ALM_2[1]=ALM2[1];
+ ALM_2[2]=ALM2[3];
+ ALM_2[3]=ALM2[4];
+
+ FEC_2[0]=FEC2[0];
+ FEC_2[1]=FEC2[1];
+ FEC_2[2]=FEC2[2];
+ FEC_2[3]=FEC2[3];
+ FEC_2[4]=FEC2[5];
+ FEC_2[5]=FEC2[6];
+ FEC_2[6]=FEC2[8];
+ FEC_2[7]=FEC2[9];
+
+ sprintf(alm_2,"%d%d%d%d",ALM_2[0],ALM_2[1],ALM_2[2],ALM_2[3]);
+ sprintf(fec_2,"%d%d%d%d%d%d%d%d",FEC_2[0],FEC_2[1],FEC_2[2],FEC_2[3],FEC_2[4],FEC_2[5],FEC_2[6],FEC_2[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+
+ x=1;
+ wait(1);
+ al=1;
+ p=-1;
+ }
+
+ wait(1);
+ }
+
+ }
+
+ wait(1);
+ nu=0;
+ y=0;
+ con=0;
+ LCD.cls();
+ LCD.printf("ALM2 PR0GRAMADA");
+ wait(5);
+ con=2;
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ break;
+ case 3:
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ LCD.cls();
+ LCD.printf(" ALM 3");
+ al=0;
+ con=0;
+ wait(1);
+ x=0;
+ while(x==0) {
+
+ if(button4.falling()) {
+ con++;
+
+ while(con==1) {
+ if(button4.falling()) {
+ con++;
+ }
+ m=wheel.getPulses();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 ENC0DER");
+
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM3[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM3[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM3[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ wheel.reset();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+
+
+ for(j=3; j<5; ++j) {
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM3[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM3[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+
+///////////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC3[4]=0;
+ FEC3[7]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC3[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC3[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC3[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC3[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC3[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC3[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+//////////////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A3");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM3[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC3[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_3[0]=ALM3[0];
+ ALM_3[1]=ALM3[1];
+ ALM_3[2]=ALM3[3];
+ ALM_3[3]=ALM3[4];
+
+ FEC_3[0]=FEC3[0];
+ FEC_3[1]=FEC3[1];
+ FEC_3[2]=FEC3[2];
+ FEC_3[3]=FEC3[3];
+ FEC_3[4]=FEC3[5];
+ FEC_3[5]=FEC3[6];
+ FEC_3[6]=FEC3[8];
+ FEC_3[7]=FEC3[9];
+
+ sprintf(alm_3,"%d%d%d%d",ALM_3[0],ALM_3[1],ALM_3[2],ALM_3[3]);
+ sprintf(fec_3,"%d%d%d%d%d%d%d%d",FEC_3[0],FEC_3[1],FEC_3[2],FEC_3[3],FEC_3[4],FEC_3[5],FEC_3[6],FEC_3[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+ }
+ wait(1);
+ }
+ al=0;
+ wait(1);
+ p=irda.read_high_us(4000);
+
+ if(p!=-1) {
+ while (al!=1) {
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM3[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM3[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM3[j]);
+ wait(1);
+ }
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+ for(j=3; j<5; ++j) {
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM3[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM3[j]);
+ wait(1);
+ }
+ ////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC3[4]=0;
+ FEC3[7]=0;
+
+
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC3[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC3[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC3[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC3[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC3[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC3[j]);
+ wait(1);
+ }
+
+
+ ////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A3");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM3[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC3[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_3[0]=ALM3[0];
+ ALM_3[1]=ALM3[1];
+ ALM_3[2]=ALM3[3];
+ ALM_3[3]=ALM3[4];
+
+ FEC_3[0]=FEC3[0];
+ FEC_3[1]=FEC3[1];
+ FEC_3[2]=FEC3[2];
+ FEC_3[3]=FEC3[3];
+ FEC_3[4]=FEC3[5];
+ FEC_3[5]=FEC3[6];
+ FEC_3[6]=FEC3[8];
+ FEC_3[7]=FEC3[9];
+
+ sprintf(alm_3,"%d%d%d%d",ALM_3[0],ALM_3[1],ALM_3[2],ALM_3[3]);
+ sprintf(fec_3,"%d%d%d%d%d%d%d%d",FEC_3[0],FEC_3[1],FEC_3[2],FEC_3[3],FEC_3[4],FEC_3[5],FEC_3[6],FEC_3[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+
+ x=1;
+ wait(1);
+ al=1;
+ p=-1;
+ }
+
+ wait(1);
+ }
+
+ }
+
+ wait(1);
+ nu=0;
+ y=0;
+ con=0;
+ LCD.cls();
+ LCD.printf("ALM3 PR0GRAMADA");
+ wait(5);
+ con=2;
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ break;
+ case 4:
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ LCD.cls();
+ LCD.printf(" ALM 4");
+ al=0;
+ con=0;
+ wait(1);
+ x=0;
+ while(x==0) {
+
+ if(button4.falling()) {
+ con++;
+
+ while(con==1) {
+ if(button4.falling()) {
+ con++;
+ }
+ m=wheel.getPulses();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 ENC0DER");
+
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM4[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM4[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM4[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ wheel.reset();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+
+
+ for(j=3; j<5; ++j) {
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM4[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM4[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+
+///////////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC4[4]=0;
+ FEC4[7]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC4[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC4[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC4[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC4[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC4[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC4[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+//////////////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A4");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM4[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC4[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_4[0]=ALM4[0];
+ ALM_4[1]=ALM4[1];
+ ALM_4[2]=ALM4[3];
+ ALM_4[3]=ALM4[4];
+
+ FEC_4[0]=FEC4[0];
+ FEC_4[1]=FEC4[1];
+ FEC_4[2]=FEC4[2];
+ FEC_4[3]=FEC4[3];
+ FEC_4[4]=FEC4[5];
+ FEC_4[5]=FEC4[6];
+ FEC_4[6]=FEC4[8];
+ FEC_4[7]=FEC4[9];
+
+ sprintf(alm_4,"%d%d%d%d",ALM_4[0],ALM_4[1],ALM_4[2],ALM_4[3]);
+ sprintf(fec_4,"%d%d%d%d%d%d%d%d",FEC_4[0],FEC_4[1],FEC_4[2],FEC_4[3],FEC_4[4],FEC_4[5],FEC_4[6],FEC_4[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+ }
+ wait(1);
+ }
+ al=0;
+ wait(1);
+ p=irda.read_high_us(4000);
+
+ if(p!=-1) {
+ while (al!=1) {
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM4[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM4[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM4[j]);
+ wait(1);
+ }
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+ for(j=3; j<5; ++j) {
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM4[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM4[j]);
+ wait(1);
+ }
+ ////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC4[4]=0;
+ FEC4[7]=0;
+
+
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC4[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC4[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC4[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC4[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC4[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC4[j]);
+ wait(1);
+ }
+
+
+ ////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A4");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM4[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC4[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_4[0]=ALM4[0];
+ ALM_4[1]=ALM4[1];
+ ALM_4[2]=ALM4[3];
+ ALM_4[3]=ALM4[4];
+
+ FEC_4[0]=FEC4[0];
+ FEC_4[1]=FEC4[1];
+ FEC_4[2]=FEC4[2];
+ FEC_4[3]=FEC4[3];
+ FEC_4[4]=FEC4[5];
+ FEC_4[5]=FEC4[6];
+ FEC_4[6]=FEC4[8];
+ FEC_4[7]=FEC4[9];
+
+ sprintf(alm_4,"%d%d%d%d",ALM_4[0],ALM_4[1],ALM_4[2],ALM_4[3]);
+ sprintf(fec_4,"%d%d%d%d%d%d%d%d",FEC_4[0],FEC_4[1],FEC_4[2],FEC_4[3],FEC_4[4],FEC_4[5],FEC_4[6],FEC_4[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+
+ x=1;
+ wait(1);
+ al=1;
+ p=-1;
+ }
+
+ wait(1);
+ }
+
+ }
+
+ wait(1);
+ nu=0;
+ y=0;
+ con=0;
+ LCD.cls();
+ LCD.printf("ALM4 PR0GRAMADA");
+ wait(5);
+ con=2;
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ break;
+ case 5:
+ LCD.cls();
+ LCD.printf(" ALM 5");
+ al=0;
+ con=0;
+ wait(1);
+ x=0;
+ while(x==0) {
+
+ if(button4.falling()) {
+ con++;
+
+ while(con==1) {
+ if(button4.falling()) {
+ con++;
+ }
+ m=wheel.getPulses();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 ENC0DER");
+
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM5[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM5[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM5[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ wheel.reset();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+
+
+ for(j=3; j<5; ++j) {
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM5[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM5[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+
+///////////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC5[4]=0;
+ FEC5[7]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC5[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC5[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC5[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC5[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC5[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC5[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+//////////////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A5");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM5[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC5[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_5[0]=ALM5[0];
+ ALM_5[1]=ALM5[1];
+ ALM_5[2]=ALM5[3];
+ ALM_5[3]=ALM5[4];
+
+ FEC_5[0]=FEC5[0];
+ FEC_5[1]=FEC5[1];
+ FEC_5[2]=FEC5[2];
+ FEC_5[3]=FEC5[3];
+ FEC_5[4]=FEC5[5];
+ FEC_5[5]=FEC5[6];
+ FEC_5[6]=FEC5[8];
+ FEC_5[7]=FEC5[9];
+
+ sprintf(alm_5,"%d%d%d%d",ALM_5[0],ALM_5[1],ALM_5[2],ALM_5[3]);
+ sprintf(fec_5,"%d%d%d%d%d%d%d%d",FEC_5[0],FEC_5[1],FEC_5[2],FEC_5[3],FEC_5[4],FEC_5[5],FEC_5[6],FEC_5[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+ }
+ wait(1);
+ }
+ al=0;
+ wait(1);
+ p=irda.read_high_us(4000);
+
+ if(p!=-1) {
+ while (al!=1) {
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM5[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM5[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM5[j]);
+ wait(1);
+ }
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+ for(j=3; j<5; ++j) {
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM5[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM5[j]);
+ wait(1);
+ }
+ ////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC5[4]=0;
+ FEC5[7]=0;
+
+
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC5[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC5[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC5[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC5[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC5[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC5[j]);
+ wait(1);
+ }
+
+
+ ////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A5");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM5[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC5[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_5[0]=ALM5[0];
+ ALM_5[1]=ALM5[1];
+ ALM_5[2]=ALM5[3];
+ ALM_5[3]=ALM5[4];
+
+ FEC_5[0]=FEC5[0];
+ FEC_5[1]=FEC5[1];
+ FEC_5[2]=FEC5[2];
+ FEC_5[3]=FEC5[3];
+ FEC_5[4]=FEC5[5];
+ FEC_5[5]=FEC5[6];
+ FEC_5[6]=FEC5[8];
+ FEC_5[7]=FEC5[9];
+
+ sprintf(alm_5,"%d%d%d%d",ALM_5[0],ALM_5[1],ALM_5[2],ALM_5[3]);
+ sprintf(fec_5,"%d%d%d%d%d%d%d%d",FEC_5[0],FEC_5[1],FEC_5[2],FEC_5[3],FEC_5[4],FEC_5[5],FEC_5[6],FEC_5[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+
+ x=1;
+ wait(1);
+ al=1;
+ p=-1;
+ }
+
+ wait(1);
+ }
+
+ }
+
+ wait(1);
+ nu=0;
+ y=0;
+ con=0;
+ LCD.cls();
+ LCD.printf("ALM5 PR0GRAMADA");
+ wait(5);
+ con=2;
+
+ break;
+ case 6:
+ LCD.cls();
+ LCD.printf(" ALM 6");
+ al=0;
+ con=0;
+ wait(1);
+ x=0;
+ while(x==0) {
+
+ if(button4.falling()) {
+ con++;
+
+ while(con==1) {
+ if(button4.falling()) {
+ con++;
+ }
+ m=wheel.getPulses();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 ENC0DER");
+
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM6[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM6[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM6[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ wheel.reset();
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+
+
+ for(j=3; j<5; ++j) {
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ ALM6[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM6[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+
+///////////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC6[4]=0;
+ FEC6[7]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC6[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC6[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC6[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC6[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ d=0;
+ wheel.reset();
+ while(d==0) {
+ num=wheel.getPulses();
+ if(num>9) {
+ num=9;
+ }
+ if(num<0) {
+ num=0;
+ }
+ FEC6[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC6[j]);
+ if(button4.falling()) {
+ d=1;
+ }
+ }
+ wait(1);
+ }
+
+//////////////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A6");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM6[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC6[j]);
+
+
+ }
+ wait(5);
+
+ // como se dijo anteriormente solo cambian las variables
+
+ ALM_6[0]=ALM6[0];
+ ALM_6[1]=ALM6[1];
+ ALM_6[2]=ALM6[3];
+ ALM_6[3]=ALM6[4];
+
+ FEC_6[0]=FEC6[0];
+ FEC_6[1]=FEC6[1];
+ FEC_6[2]=FEC6[2];
+ FEC_6[3]=FEC6[3];
+ FEC_6[4]=FEC6[5];
+ FEC_6[5]=FEC6[6];
+ FEC_6[6]=FEC6[8];
+ FEC_6[7]=FEC6[9];
+
+ sprintf(alm_6,"%d%d%d%d",ALM_6[0],ALM_6[1],ALM_6[2],ALM_6[3]);
+ sprintf(fec_6,"%d%d%d%d%d%d%d%d",FEC_6[0],FEC_6[1],FEC_6[2],FEC_6[3],FEC_6[4],FEC_6[5],FEC_6[6],FEC_6[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+ }
+ wait(1);
+ }
+ al=0;
+ wait(1);
+ p=irda.read_high_us(4000);
+
+ if(p!=-1) {
+ while (al!=1) {
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("M0D0 C0NTR0L");
+ wait(2);
+ int j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("H0RA");
+ for(j=0; j<2; ++j) {
+ ALM6[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM6[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM6[j]);
+ wait(1);
+ }
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MIN");
+
+ for(j=3; j<5; ++j) {
+ fflush( stdin );
+ //wait(1);
+ control();
+ ALM6[j]=num;
+ LCD.locate(j-3,0);
+ LCD.printf("%i",ALM6[j]);
+ wait(1);
+ }
+ ////////////////////////
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("YEAR");
+ for(j=0; j<4; ++j) {
+ FEC6[4]=0;
+ FEC6[7]=0;
+
+
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC6[j]=num;
+ LCD.locate(j,0);
+ LCD.printf("%i",FEC6[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("MES");
+ for(j=5; j<7; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC6[j]=num;
+ LCD.locate(j-5,0);
+ LCD.printf("%i",FEC6[j]);
+ wait(1);
+ }
+
+
+ j=0;
+ LCD.cls();
+ LCD.locate(0,1);
+ LCD.printf("DIA");
+ for(j=8; j<10; ++j) {
+ //ALM1[2]=0;
+ fflush( stdin );
+ //wait(1);
+ control();
+ FEC6[j]=num;
+ LCD.locate(j-8,0);
+ LCD.printf("%i",FEC6[j]);
+ wait(1);
+ }
+
+
+ ////////////////////////
+ LCD.cls();
+ LCD.locate(14,0);
+ LCD.printf("A6");
+ for(j=0; j<5; ++j) {
+ //
+ LCD.locate(2,0);
+ LCD.printf(":");
+ LCD.locate(j,0);
+ LCD.printf("%i",ALM6[j]);
+
+
+ }
+
+
+ for(j=0; j<10; ++j) {
+ //
+ LCD.locate(4,1);
+ LCD.printf("-");
+ LCD.locate(7,1);
+ LCD.printf("-");
+ LCD.locate(j,1);
+ LCD.printf("%i",FEC6[j]);
+
+
+ }
+ wait(5);
+
+
+ ALM_6[0]=ALM6[0];
+ ALM_6[1]=ALM6[1];
+ ALM_6[2]=ALM6[3];
+ ALM_6[3]=ALM6[4];
+
+ FEC_6[0]=FEC6[0];
+ FEC_6[1]=FEC6[1];
+ FEC_6[2]=FEC6[2];
+ FEC_6[3]=FEC6[3];
+ FEC_6[4]=FEC6[5];
+ FEC_6[5]=FEC6[6];
+ FEC_6[6]=FEC6[8];
+ FEC_6[7]=FEC6[9];
+
+ sprintf(alm_6,"%d%d%d%d",ALM_6[0],ALM_6[1],ALM_6[2],ALM_6[3]);
+ sprintf(fec_6,"%d%d%d%d%d%d%d%d",FEC_6[0],FEC_6[1],FEC_6[2],FEC_6[3],FEC_6[4],FEC_6[5],FEC_6[6],FEC_6[7]);
+
+ x=1;
+ wait(1);
+ al=1;
+ con=2;
+
+
+ x=1;
+ wait(1);
+ al=1;
+ p=-1;
+ }
+
+ wait(1);
+ }
+
+ }
+
+ wait(1);
+ nu=0;
+ y=0;
+ con=0;
+ LCD.cls();
+ LCD.printf("ALM6 PR0GRAMADA");
+ wait(5);
+ con=2;
+
+ break;
+
+ }
+
+
+ break;
+
+// todas las anteriores alarmas fueron programadas de la misma manera que la 1, solo se cambiaron las variables dependiendo de que alarma estaba.
+
+
+ } //del switch
+ pos=0;// variable de control
+ }
+
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Aug 30 14:05:20 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file