Tarea Reloj DS3231-Control Remoto samsung Procesadores 2019-1 Equipo verde Guillermo Eduardo Luna Rozo Susana Buriticá Alvaro Javier Vargas David Cordoba Santiago Yepes Funciona correctamente, con 8 alarmas, se puede modificar la hora ccon encoder, y se configuran las alarmas con encoder y control.
Dependencies: mbed QEI Debounced ds3231 TextLCD RTC-DS1307 Pulse1
Diff: main.cpp
- Revision:
- 1:0075319c0341
- Parent:
- 0:fd394f5c0449
diff -r fd394f5c0449 -r 0075319c0341 main.cpp --- a/main.cpp Tue Aug 13 19:25:23 2019 +0000 +++ b/main.cpp Wed Aug 28 19:41:40 2019 +0000 @@ -1,361 +1,1078 @@ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> +//Tarea Reloh DS3231-Control Remoto samsung Procesadores 2019-1 Equipo verde +//Guillermo Eduardo Luna Rozo +//Susana Buriticá +//Alvaro Javier Vargas +//David Cordoba +//Santiago Yepes +//Funciona correctamente, con 8 alarmas, se puede modificar la hora ccon encoder, y se configuran las alarmas con encoder y control + #include "mbed.h" -#include "DebouncedIn.h" +#include "QEI.h" #include "TextLCD.h" -#include "QEI.h" +#include "DebouncedIn.h" +#include "string.h" #include "ds3231.h" +#include <Pulse1.h> #include "Rtc_Ds1307.h" -#include "string.h" -#include <Pulse1.h> + #define ESC 0x1B - -///////////////////////////////// LIB LCD -TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 -// Se debe conectar Vss a GND; VDD a 5V; V0 a pot con otro lado conectado a GND -// El puerto A va hacia una resistencia de 200 hom a 5 V -// EL puerto K va a GND - -Serial pc(USBTX, USBRX); -///////////////////////////////// LIB RELOJ 3231 -//Ds3231 rtc(PTE0, PTE1); // SDA SCL - + + +//Use X4 encoding. +//QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING); +//Use X2 encoding by default. +PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo +Serial pc(USBTX, USBRX); +QEI wheel (PTD7, PTD6, NC, 50);//Encoder +DebouncedIn bot1(PTC5);//Botón encoder +DebouncedIn boton(PTA17);//Botón +DebouncedIn boton2(PTA16);//Botón configurar alarma +TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5, TextLCD::LCD16x2); // rs, e, d4-d7 +DigitalOut led1(PTC7);//Salidas +DigitalOut led2(PTC0); +DigitalOut led3(PTC3); +DigitalOut led(LED3); +DigitalOut ledd2(LED1); + +//-----------parametros IRDA ------- +int header =0; //tiempo de cabecera pulso abajo +const int head_H = 4900; //+20% medida con osciloscopio en microsegundos +const int head_L = 3500 ;//-20% medida con osciloscopio +int il=0, x=0; +const int T_alto=1694;//ponga su tiempo de la prueba +const int T_bajo=632;//ponga su tiempo de la prueba +const int num_bits = 32;//ponga su numero de bits +int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos +char sel[num_bits];//cadena para almacenar la cadena codificada en binario +char uno[]="1110000011100000001000001101111"; //0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,1,0,1,1,0 +char dos[]="1110000011100000101000000101111"; +char tres[]="1110000011100000011000001001111"; +char cuatro[]="1110000011100000000100001110111"; +char cinco[]="1110000011100000100100000110111"; +char seis[]="1110000011100000010100001010111"; +char siete[]="1110000011100000001100001100111"; +char ocho[]="1110000011100000101100000100111"; +char nueve[]="1110000011100000011100001000111"; +char cero[]="1110000011100000100010000111011"; + +char ok[]="1110000011100000000101101110100"; //"00100000110111110000000011111110"; //0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0 +char izq[]="1110000011100000101001100101100";//"00100000110111110010001011011100 +char der[]="1110000011100000010001101011100"; +int dato; // tiempo de cada dato que se lee +int irdan(void); +int y=0; +int detectar(void);//funcion detecta irda +int Alarm_IRDA(void);//funcion valor irda +int ConfiReloj(void); //configurarrelogsinno + +void get_user_input(char* message, uint8_t min, uint8_t max, uint32_t* member); +void get_user_input(char* message, uint8_t min, uint8_t max, bool* member); + +int mode=0; +int numb=34; + +// + +int d; +int m; +int mes; +int an,h,min,sec,a; +int Conf=0; +int s=0; // 0: si y 1:no alarma ok +int f=0; // 0: si y 1:no otra alrama +int Lugar=1,Lugar2=2,Lugar3=3; +int pos=0,n=0; // Definen el punto en el cual va el programa +int i=0; +int j=1; //Cuenta las alarmas +int Select=1; //Alarma Seleccionada +int StarReadIR=0; +int visual=0; //0: Reloj y 1:Alarm +int alarma=0; //0: Desactivar y 1:Posponer +int Vec1[7]; +int Vec2[7]; +int Vec3[7]; +int Vec4[7]; +int Vec5[7]; +int Vec6[7]; Rtc_Ds1307 rtc(PTE0, PTE1);//SCL,SDA Rtc_Ds1307::Time_rtc tm = {}; -time_t epoch_time; -///////////////////////////////// LIB Encoder - -QEI wheel (PTD7, PTD6, NC, 50); -DebouncedIn button_enco(PTC5); -int EncoderInput; -int EncoderBoton; -////////////////////////////////// Sensor IRDA -PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo -BusOut leds(LED1,LED2,LED3); -int IRDAInput; -int IRDAOpcion; -/////////////////////////////////////////// Declarar Variables globales -int OpcionMenu; - - -void ImprimirHora(){ - int Hora=0; - while(Hora==0){ +time_t epoch_time; + + +int main() +{ + + Ds3231 rtc(PTE0, PTE1); + Rtc_Ds1307::Time_rtc tm = {}; + time_t epoch_time; + ds3231_cntl_stat_t rtc_control_status = {0,0}; + ds3231_time_t rtc_time={0,0,0,0,0}; + ds3231_calendar_t rtc_calendar={0,0,0,0}; + rtc.set_cntl_stat_reg(rtc_control_status); + + + +loop1: + epoch_time = rtc.get_epoch(); + rtc.get_time(&rtc_time); + rtc.get_calendar(&rtc_calendar); + j=1; + Conf=0; + s=0; + f=0; + Lugar=1; + Lugar2=2; + Lugar3=3; + pos=0; + i=0; + y=0; + lcd.cls(); + lcd.locate(14,0); + lcd.printf("-A"); + lcd.locate(2,0); + lcd.printf("\nFecha:%02d/%02d/%02d",rtc_calendar.date,rtc_calendar.month,rtc_calendar.year); + m=wheel.getPulses(); + //Reloj corriendo y comparamdo con alarmas// + while(!bot1.falling() && !boton.falling() && !boton2.falling()){ + rtc.get_time(&rtc_time); + lcd.locate(0,1); + lcd.printf("\nHora:%02d:%02d:%02d", rtc_time.hours,rtc_time.minutes,rtc_time.seconds ); + if(Vec1[1]==rtc_calendar.date && Vec1[2]==rtc_calendar.month && Vec1[3]==rtc_calendar.year && Vec1[4]==rtc_time.hours && Vec1[5]==rtc_time.minutes && Vec1[6]==rtc_time.seconds){ + led1=1;} + if(Vec2[1]==rtc_calendar.date && Vec2[2]==rtc_calendar.month && Vec2[3]==rtc_calendar.year && Vec2[4]==rtc_time.hours && Vec2[5]==rtc_time.minutes && Vec2[6]==rtc_time.seconds){ + led2=1;} + if(Vec3[1]==rtc_calendar.date && Vec3[2]==rtc_calendar.month && Vec3[3]==rtc_calendar.year && Vec3[4]==rtc_time.hours && Vec3[5]==rtc_time.minutes && Vec3[6]==rtc_time.seconds){ + led3=1;} + if(Vec4[1]==rtc_calendar.date && Vec4[2]==rtc_calendar.month && Vec4[3]==rtc_calendar.year && Vec4[4]==rtc_time.hours && Vec4[5]==rtc_time.minutes && Vec4[6]==rtc_time.seconds){ + led1=0;} + if(Vec5[1]==rtc_calendar.date && Vec5[2]==rtc_calendar.month && Vec5[3]==rtc_calendar.year && Vec5[4]==rtc_time.hours && Vec5[5]==rtc_time.minutes && Vec5[6]==rtc_time.seconds){ + led2=0;} + if(Vec6[1]==rtc_calendar.date && Vec6[2]==rtc_calendar.month && Vec6[3]==rtc_calendar.year && Vec6[4]==rtc_time.hours && Vec6[5]==rtc_time.minutes && Vec6[6]==rtc_time.seconds){ + led3=0;} + } + + while(1) + { + + if (bot1.falling()){ //Para que trabaje con encoder + Lugar++; + } + if(boton.falling()){ + Lugar2++; + } + if(boton2.falling()){ + Lugar3++; + } + switch (Lugar)//Encoder + { + case 2: + switch(i) + { + case 0: + if(Conf==0){ + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Alarma: "); + i++; + } + break; + case 1: + m=0; + m=wheel.getPulses(); + if (m!=0){ + a=m; + if(a>9){ + a=8; + } + if (a<1){ + a=1; + } + } + lcd.locate(10,0); + lcd.printf("%02d ",a); + if(bot1.falling()){ +loop2: + lcd.cls(); + lcd.printf("Config. Alarmas "); + wait(1); lcd.cls(); - Rtc_Ds1307::Time_rtc tm = {}; - rtc.getTime(tm); - lcd.locate(0,0); - lcd.printf("Hora :"); - lcd.locate(7,0); - lcd.printf("%02d:",tm.hour); - lcd.printf("%02d:",tm.min); - lcd.printf("%02d",tm.sec); - lcd.locate(0,1); - lcd.printf("BY Procesadores "); - wait_ms(100); - if(button_enco.falling()){ - Hora=1; - } - //epoch_time = rtc.get_epoch(); - //lcd.cls(); - //lcd.locate(0,0); - //lcd.printf(" CLK %s", ctime(&epoch_time)); + i=2; + s=0; + f=0; + Lugar=2; + pos=0; + lcd.locate(0,0); + lcd.printf("Dia: "); + m=0; + wheel.reset(); } -} - - -int LeerEncoder(){ - wheel.reset(); - int Valor=0; - while(Valor==0){ - EncoderInput=wheel.getPulses(); - lcd.cls(); - lcd.locate(0,0); - lcd.printf("Leyendo Encoder"); - lcd.locate(0,5); - lcd.printf("Val : %i",wheel.getPulses()); - if(button_enco.falling()){ - EncoderBoton=1; - EncoderInput=wheel.getPulses(); - pc.printf("Boton %i\n", wheel.getPulses()); - Valor=1; + break; + case 2: // Dia + m=0; + m=wheel.getPulses(); + if (m!=0) + { + d=m; + if(d>31) + { + d=31; + } + if(d<1) + { + d=1; + } + + + } + lcd.locate(5,0); + lcd.printf("%02d ",d); + + if (bot1.falling()) + { + i++; + m=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Mes: "); + + wheel.reset(); + + } + break; + + case 3: // Mes + m=0; + m=wheel.getPulses(); + if (m!=0) + { + mes=m; + if(mes>12) + { + mes=12; + } + if(mes<1) + { + mes=1; + } + + + } + lcd.locate(7,0); + lcd.printf("%02d",mes); + + if (bot1.falling()) + { + i++; + m=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Anno: "); + wheel.reset(); + } + + break; + + case 4: //Año + m=wheel.getPulses(); + if (m!=0) + { + an=m; + + if(an<0) + { + an=0; + } + if(an>99){ + an=99; + } + + + } + lcd.locate(6,0); + lcd.printf("%02d",an); + + if (bot1.falling()) + { + i++; + m=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Config. Hora"); + wait(1); + lcd.cls(); + lcd.printf("Hora: "); + wheel.reset(); + + } + + break; + + case 5: //HORA + + + m=0; + m=wheel.getPulses(); + if (m!=0) + { + h= m; + if(h>23) + { + h=23; + } + if(h<0) + { + h=0; + } + + } + lcd.locate(6,0); + lcd.printf("%02d",h); + + if (bot1.falling()) + { + i++; + m=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Minuto: "); + wheel.reset(); + } + + break; + + case 6: //MINUTOS + m=0; + m=wheel.getPulses(); + if (m!=0) + { + min=m; + if(min>59) + { + min=59; + } + if(min<0) + { + min=0; + } + + } + lcd.locate(8,0); + lcd.printf("%02d",min); + + if (bot1.falling()) + { + i++; + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Segundo: "); + wheel.reset(); + } + + break; + + + case 7: //SEGUNDOS + m=0; + m=wheel.getPulses(); + if (m!=0) + { + sec=m; + if(sec>59) + { + sec=59; + } + if(sec<0) + { + sec=0; + } + + } + + lcd.locate(8,0); + lcd.printf("%02d",sec); + if(bot1.falling()){ + + i++; + + lcd.cls(); + wheel.reset(); + + } + break; + case 8: + m=0; + lcd.locate(0,1); + lcd.printf("\nAlarm:%02d:%02d:%02d",h,min,sec); + lcd.locate(2,0); + lcd.printf("\nFecha:%02d/%02d/%02d",d,mes,an); + wait(2); + lcd.cls(); + lcd.locate(0,1); + lcd.printf("Alarma OK ?"); + lcd.locate(2,0); + lcd.printf("--Si --No"); + i++; + wheel.reset(); + break; + + case 9: + + m=wheel.getPulses(); // m son los datos del encoder + if(m!=0 && s==0){ + s=1; + wheel.reset(); + m=0; } - wait_ms(50); - } - return EncoderInput; - } - -void LeerIRDA(){ - //////////////////////// Declaro Variables + + if(m!=0 && s==1){ + s=0; + wheel.reset(); + m=0; + } + + if(s==0){ + + lcd.locate(11,0); + lcd.printf("-"); + lcd.locate(1,0); + lcd.printf(">"); + lcd.locate(0,1); + wait(0.1); + } + if(s==1){ + + lcd.locate(1,0); + lcd.printf("-"); + lcd.locate(11,0); + lcd.printf(">"); + lcd.locate(0,1); + wait(0.1); + } + + if(s==1){ + + lcd.locate(1,0); + lcd.printf("-"); + lcd.locate(11,0); + lcd.printf(">"); + lcd.locate(0,1); + wait(0.1); + } + + if (bot1.falling()){ //si se pulsa boton encoder + pos++; + m=0; + } + + break; + + + + } + switch (pos) + { + case 1: + if(s==0){ + lcd.cls(); + lcd.locate(0,1); + if(a==1){ + Vec1[1]=d; + Vec1[2]=mes; + Vec1[3]=an; + Vec1[4]=h; + Vec1[5]=min; + Vec1[6]=sec; + } + if(a==2){ + Vec2[1]=d; + Vec2[2]=mes; + Vec2[3]=an; + Vec2[4]=h; + Vec2[5]=min; + Vec2[6]=sec; + } + if(a==3){ + Vec3[1]=d; + Vec3[2]=mes; + Vec3[3]=an; + Vec3[4]=h; + Vec3[5]=min; + Vec3[6]=sec; + } + if(a==4){ + Vec4[1]=d; + Vec4[2]=mes; + Vec4[3]=an; + Vec4[4]=h; + Vec4[5]=min; + Vec4[6]=sec; + } + if(a==5){ + Vec5[1]=d; + Vec5[2]=mes; + Vec5[3]=an; + Vec5[4]=h; + Vec5[5]=min; + Vec5[6]=sec; + } + if(a==6){ + Vec6[1]=d; + Vec6[2]=mes; + Vec6[3]=an; + Vec6[4]=h; + Vec6[5]=min; + Vec6[6]=sec; + } + lcd.printf("Otra alarma? %0.2d",Vec1[6]); + lcd.locate(2,0); + lcd.printf("--Si --No"); + wheel.reset(); + pos++; + } + + if(s==1){ + lcd.cls(); + goto loop2; + } + + break; + case 2: + m=wheel.getPulses(); // m son los datos del encoder + if(m!=0 && f==0){ + f=1; + wheel.reset(); + m=0; + } + + if(m!=0 && f==1){ + f=0; + wheel.reset(); + m=0; + } + + if(f==0){ + + lcd.locate(11,0); + lcd.printf("-"); + lcd.locate(1,0); + lcd.printf(">"); + lcd.locate(0,1); + wait(0.1); + } + if(f==1){ + + lcd.locate(1,0); + lcd.printf("-"); + lcd.locate(11,0); + lcd.printf(">"); + lcd.locate(0,1); + wait(0.1); + } + + if(f==1){ + + lcd.locate(1,0); + lcd.printf("-"); + lcd.locate(11,0); + lcd.printf(">"); + lcd.locate(0,1); + wait(0.1); + } - int header =0; //tiempo de cabecera pulso abajo - const int head_H = 10884; //+20% medida con osciloscopio en microsegundos - const int head_L = 7256;//-20% medida con osciloscopio - int i=0; - const int T_alto=1570;//ponga su tiempo de la prueba - const int T_bajo=467;//ponga su tiempo de la prueba - const int num_bits = 32;//ponga su numero de bits - int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos - int sec[num_bits];//cadena para almacenar la cadena codificada en binario 00100000110111111000100001110111 - int boton1[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,1,0,1,1,0}; //00100000110111111000100001110110 Boton 1 - int boton2[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,1,0,0,1,0,0,0,1,0,1,1,0,1,1,0}; //00100000110111110100100010110110 Boton 2 - int boton3[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,1,1,0,1,1,0}; //00100000110111111100100000110110 Boton 3 - int boton4[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,0,1,0,1,0,0,0,1,1,0,1,0,1,1,0}; //00100000110111110010100011010110 Boton 4 - int boton5[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,0,1,0,1,0,0,0,0,1,0,1,0,1,1,0}; //00100000110111111010100001010110 Boton 5 - int boton6[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,1,0}; //00100000110111110110100010010110 Boton 6 - int boton7[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,1,0,1,1,0}; //00100000110111111110100000010110 Boton 7 - int boton8[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,0,0,1,1,0,0,0,1,1,1,0,0,1,1,0}; //00100000110111110001100011100110 Boton 8 - int boton9[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0}; //00100000110111111001100001100110 Boton 9 - int boton0[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,0,0,0,1,0,0,0,1,1,1,1,0,1,1,0}; //00100000110111110000100011110110 Boton 0 - int botonEnt[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,0,1,0,0,0,1,0,1,1,0,1,1,1,0,0}; //00100000110111110010001011011100 Boton Ent - int botonIzq[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0}; //00100000110111111110000000011110 Boton Izq - int botonDer[]= {0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,1,1,0,0,0,0,0,1,0,0,1,1,1,1,0}; //00100000110111110110000010011110 Boton Der - - - int flag1,flag2,flag3,flag4,flag5,flag6,flag7,flag8,flag9,flag0,flagEnt,flagIzq,flagDer; //Banderas de boton presionado - int dato; // tiempo de cada dato que se lee - int LeerIRDA=1; - //////////////////////////////////////////////////////// Funcion leer datos IRDA - - - leds = 1; // Color en LED Azul + if (bot1.falling()){ //si se pulsa boton encoder + wheel.reset(); + lcd.cls(); + pos++; + + + + } + break; + case 3: + if(f==0){ + wheel.reset(); + lcd.cls(); + goto loop1; + } + if(f==1){ + wheel.reset(); + lcd.cls(); + goto loop1; //Va al reloj + } + break; + + } + + } - lcd.locate(0,0); - while(LeerIRDA==1) - { -ini1: - pc.printf("Esperando entrada control remoto: \n"); - header=0; - header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo - if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% - else goto ini1; + switch (Lugar2)//Control + { + case 3: + + switch(i) + { + + case 0: + if(Conf==0){ +loop3: + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Alarma: "); + i++; + Conf++; + m=0; + } + + case 1: + if (Conf==1){ + + m=Alarm_IRDA(); + if(m!=0){ + a=m; + if(a>8){ + a=8; + } + if (a<1){ + a=1; + } + } + lcd.locate(10,0); + pc.printf("Alarma: %02d",a); + lcd.printf("%02d",a); + +loop5: + if(Alarm_IRDA()==-8){ + lcd.cls(); + lcd.printf("Config. Alarmas "); + wait(1); + lcd.cls(); + i=2; + s=0; + f=0; + Lugar=2; + pos=0; + lcd.locate(0,0); + lcd.printf("Dia: "); + m=0; + } + } + + case 2: // Dia + m=0; + m=Alarm_IRDA(); + if (m!=0) + { + d=m; + if(d>31) + { + d=31; + } + if(d<1) + { + d=1; + } + + + } + lcd.locate(5,0); + lcd.printf("%02d ",d); + + if (Alarm_IRDA()==-8) + { + i++; + m=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Mes: "); + + + + } + + + case 3: // Mes + m=0; + m=Alarm_IRDA(); + if (m!=0) + { + mes=m; + if(mes>12) + { + mes=12; + } + if(mes<1) + { + mes=1; + } + + + } + lcd.locate(7,0); + lcd.printf("%02d",mes); + + if (Alarm_IRDA()==-8) + { + i++; + m=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Anno: "); + + } + + + + case 4: //Año + m=Alarm_IRDA(); + if (m!=0) + { + an=m; + + if(an<0) + { + an=0; + } + if(an>99){ + an=99; + } + + + } + lcd.locate(6,0); + lcd.printf("%02d",an); + + if (Alarm_IRDA()==-8) + { + i++; + m=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Config. Hora"); + wait(1); + lcd.cls(); + lcd.printf("Hora: "); + + + } + + + + case 5: //HORA + -seguir: - //leo los datos de la trama y se meten a un arreglo - wait_us(2000); - for(i=0; i<(num_bits-1); ++i) // POR OSCILOSCOPIO se determina que llegan (num_bits),datos - { - dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control - num[i]=dato; - wait_us(332); + m=0; + m=Alarm_IRDA(); + if (m!=0) + { + h= m; + if(h>23) + { + h=23; + } + if(h<0) + { + h=0; + } + + } + lcd.locate(6,0); + lcd.printf("%02d",h); + + if (Alarm_IRDA()==-8) + { + i++; + m=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Minuto: "); + + } + + + + case 6: //MINUTOS + m=0; + m=Alarm_IRDA(); + if (m!=0) + { + min=m; + if(min>59) + { + min=59; + } + if(min<0) + { + min=0; + } + + } + lcd.locate(8,0); + lcd.printf("%02d",min); + + if (Alarm_IRDA()==-8) + { + i++; + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Segundo: "); + + } + + + + + case 7: //SEGUNDOS + m=0; + m=Alarm_IRDA(); + if (m!=0) + { + sec=m; + if(sec>59) + { + sec=59; + } + if(sec<0) + { + sec=0; + } + + } + + lcd.locate(8,0); + lcd.printf("%02d",sec); + if(Alarm_IRDA()==-8){ + + i++; + + lcd.cls(); + + + } + + case 8: + m=0; + lcd.locate(0,1); + lcd.printf("\nAlarm:%02d:%02d:%02d",h,min,sec); + lcd.locate(2,0); + lcd.printf("\nFecha:%02d/%02d/%02d",d,mes,an); + wait(2.5); + lcd.cls(); + lcd.locate(0,1); + lcd.printf("Alarma OK ?"); + lcd.locate(2,0); + lcd.printf("--Si --No"); + i++; + + + + case 9: + + m=Alarm_IRDA(); // + if(m==-2){ + goto loop5; + + } + if (m==-1){ // + pos++; + + } + m=0; + + + + + } + switch (pos) + { + case 1: + if(s==0){ + lcd.cls(); + lcd.locate(0,1); + if(a==1){ + Vec1[1]=d; + Vec1[2]=mes; + Vec1[3]=an; + Vec1[4]=h; + Vec1[5]=min; + Vec1[6]=sec; + } + if(a==2){ + Vec2[1]=d; + Vec2[2]=mes; + Vec2[3]=an; + Vec2[4]=h; + Vec2[5]=min; + Vec2[6]=sec; + } + if(a==3){ + Vec3[1]=d; + Vec3[2]=mes; + Vec3[3]=an; + Vec3[4]=h; + Vec3[5]=min; + Vec3[6]=sec; + } + if(a==4){ + Vec4[1]=d; + Vec4[2]=mes; + Vec4[3]=an; + Vec4[4]=h; + Vec4[5]=min; + Vec4[6]=sec; + } + if(a==5){ + Vec5[1]=d; + Vec5[2]=mes; + Vec5[3]=an; + Vec5[4]=h; + Vec5[5]=min; + Vec5[6]=sec; + } + if(a==6){ + Vec6[1]=d; + Vec6[2]=mes; + Vec6[3]=an; + Vec6[4]=h; + Vec6[5]=min; + Vec6[6]=sec; + } + lcd.printf("Otra alarma? %0.2d",Vec1[6]); + lcd.locate(2,0); + lcd.printf("--Si --No"); + + pos++; + m=0; + } + + case 2: + m=Alarm_IRDA(); // m son los datos del + + if(m==-2){ + + lcd.cls(); + m=0; + goto loop1;// Va al reloj + } + if(m==-1){ + + lcd.cls(); + m=0; + goto loop3; //Va a alarma + } + break; + + } + } - //wait(0.5); //espero un poquito antes de leer todo el arreglo y ponerlo en pantalla - pc.printf(",%d",header); - for(i=0; i<num_bits; ++i) - { - pc.printf(",%d",num[i]); - } - //wait(0.1); //espero e imprimo en binario - pc.printf("\n\n"); - for(i=0; i<num_bits; ++i) + switch (Lugar3)//Control + { + case 4: + ConfiReloj(); + goto loop1; + break; +} +} +} +// ---- IRDA ----// + +int detectar(void){ + int y = 0; + header=0; + ledd2=1; + led=1; + header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header + if (header > head_L && header < head_H){wait_us(2000);//verificar que este en la tolerancia +-20% + + // ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO + ledd2=0; + for(il=0;il<(num_bits-1);++il){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos + dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control + num[il]=dato; + wait_us(300); + } + //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla + + for(il=0;il<(num_bits-1);++il){ + if(num[il] > ((T_alto+T_bajo)/2)){ pc.printf("1");sel[il]='1';} + else {pc.printf("0");sel[il]='0';} + } + pc.printf("\n"); + y = 1; + pc.printf("%d",y); +} + return y; +} + +int irdan(void){ + int numirda; + + + for(il=0; il<32; ++il) { - if(num[i] > ((T_alto+T_bajo)/2)) + if(!strcmp(sel,uno)) + { + numirda=1; + break; + } + if(!strcmp(sel,dos)) + { + numirda=2; + } + if(!strcmp(sel,tres)) { - pc.printf("1"); - sec[i]=1; // guardo la secuancia en binario + numirda=3; + } + if(!strcmp(sel,cuatro)) + { + numirda=4; + } + if(!strcmp(sel,cinco)) + { + numirda=5; + } + if(!strcmp(sel,seis)) + { + numirda=6; } - else + if(!strcmp(sel,siete)) + { + numirda=7; + } + if(!strcmp(sel,ocho)) + { + numirda=8; + } + if(!strcmp(sel,nueve)) + { + numirda=9; + } + if(!strcmp(sel,cero)) { - sec[i]=0; //guardo la secuencia en binario - pc.printf("0"); + numirda=0; + } + if(!strcmp(sel,ok)) + { + numirda=-8; } + if(!strcmp(sel,izq)) + { + numirda=-1; + } + if(!strcmp(sel,der)) + { + numirda=-2; + } + } + return numirda; } - flag1=1;flag4=1;flag7=1;flag0=1;flagDer=1; - flag2=1;flag5=1;flag8=1;flagEnt=1; - flag3=1;flag6=1;flag9=1;flagIzq=1; - - for(i=0; i<32; ++i) - { - if(sec[i]!=boton1[i]) //en caso de que un bit no coincida se descarta el boton 1 - { - //pc.printf("NO Presionaste 1"); - flag1=0; - } - if(sec[i]!=boton2[i]) //en caso de que un bit no coincida se descarta el boton 2 - { - //pc.printf("NO Presionaste 2"); - flag2=0; - } - if(sec[i]!=boton3[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flag3=0; - } - if(sec[i]!=boton4[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flag4=0; - } - if(sec[i]!=boton5[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flag5=0; - } - if(sec[i]!=boton6[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flag6=0; - } - if(sec[i]!=boton7[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flag7=0; - } - if(sec[i]!=boton8[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flag8=0; - } - if(sec[i]!=boton9[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flag9=0; - } - if(sec[i]!=boton0[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flag0=0; - } - if(sec[i]!=botonEnt[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flagEnt=0; - } - if(sec[i]!=botonIzq[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flagIzq=0; - } - if(sec[i]!=botonDer[i]) //en caso de que un bit no coincida se descarta el boton 3 - { - //pc.printf("NO Presionaste 3"); - flagDer=0; - } - } - if(flag1==1) - { - - lcd.printf("\n Presionaste 1 \n"); //si coincidieron todos los bits del boton 1 - leds = 2; // Led Color Rosa - IRDAInput=1; - LeerIRDA=0; - } - else if(flag2==1) - { - leds=2; // Led Color Amarillo - lcd.printf("\n Presionaste 2 \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=2; - LeerIRDA=0; - } - else if(flag3==1) - { - leds=2; // Led Color Verde - lcd.printf("\n Presionaste 3 \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=3; - LeerIRDA=0; - } - else if(flag4==1) - { - leds=2; // Led Color Verde - lcd.printf("\n Presionaste 4 \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=4; - LeerIRDA=0; - } - else if(flag5==1) - { - leds=2; // Led Color Verde - lcd.printf("\n Presionaste 5 \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=5; - LeerIRDA=0; - } - else if(flag6==1) - { - leds=2; // Led Color Verde - lcd.printf("\n Presionaste 6 \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=6; - LeerIRDA=0; - } - else if(flag7==1) - { - leds=2; // Led Color Verde - lcd.printf("\n Presionaste 7 \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=7; - LeerIRDA=0; - } - else if(flag8==1) - { - leds=2; // Led Color Verde - lcd.printf("\n Presionaste 8 \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=8; - LeerIRDA=0; - } - else if(flag9==1) - { - leds=2; // Led Color Verde - lcd.printf("\n Presionaste 9 \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=9; - LeerIRDA=0; - } - else if(flag0==1) - { - leds=2; // Led Color Verde - lcd.printf("\n Presionaste 0 \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=0; - LeerIRDA=0; - } - else if(flagEnt==1) - { - leds=5; // Led Color Verde - lcd.printf("\n Presionaste Ent \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=3; - LeerIRDA=0; - }else if(flagIzq==1) - { - leds=5; // Led Color Verde - lcd.printf("\n Presionaste Izq \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=3; - LeerIRDA=0; - } - else if(flagDer==1) - { - leds=5; - lcd.printf("\n Presionaste Der \n"); //si coincidieron todos los bits del boton 1 - IRDAInput=3; - LeerIRDA=0; - } - else - { - leds=8; // Led Color Blanco - lcd.printf("boton no reconocido"); //si coincidieron todos los bits del boton 1 - IRDAInput=4; - LeerIRDA=0; - } - } - wait_ms(1000); - } - - -void Menu(){ - lcd.cls(); - lcd.locate(0,0); - lcd.printf("1_Hora"); - lcd.locate(8,0); - lcd.printf("3_Alarma"); - lcd.locate(0,1); - lcd.printf("2_Config Hora"); - - wait_ms(1000); - } - - //////////////////////////////////////// Configurar Reloj ///////////////// -void ConfiReloj(){ + int ConfiReloj(void){ Rtc_Ds1307::Time_rtc tm = {}; //;config = 0,config = 0,config = 0,ano = 2019,hora = 0, min = 0, int configR = 0, cont = 1, set = 0; int estado = 1; - leds=2; wait(0.2); while(estado == 1){ if(configR == 0) { @@ -380,7 +1097,7 @@ lcd.printf(" SI "); //wait_ms(10); } - if(button_enco.falling()){ + if(bot1.falling()){ if(set==1){ configR=1; }else if(set!=1){ @@ -401,7 +1118,7 @@ lcd.locate(0, 1); lcd.printf("Dia: %02d ", cont); tm.date = cont; - if(button_enco.falling()){ + if(bot1.falling()){ configR=2; } @@ -418,7 +1135,7 @@ lcd.locate(0, 1); lcd.printf("Mes: %02d ", cont); - if(button_enco.falling()){ + if(bot1.falling()){ tm.mon = cont; configR = 3; } @@ -435,7 +1152,7 @@ lcd.locate(0, 1); lcd.printf("Anno: %02d ", cont); - if(button_enco.falling()){ + if(bot1.falling()){ tm.year = cont; configR = 4; } @@ -453,7 +1170,7 @@ lcd.printf("Dia semana: %1d", cont); //tm.wday = cont; - if(button_enco.falling()){ + if(bot1.falling()){ tm.wday = cont; configR = 5; } @@ -470,7 +1187,7 @@ lcd.locate(0, 1); lcd.printf("Hora: %02d ", cont); //tm.hour = cont; - if(button_enco.falling()){ + if(bot1.falling()){ tm.hour = cont; configR = 6; } @@ -487,7 +1204,7 @@ lcd.locate(0, 1); lcd.printf("Minutos: %02d ", cont); //tm.min = cont; - if(button_enco.falling()){ + if(bot1.falling()){ tm.min = cont; configR = 7; } @@ -504,7 +1221,7 @@ lcd.locate(0, 1); lcd.printf("Segundos: %02d ", cont); tm.sec = cont; - if(button_enco.falling()){ + if(bot1.falling()){ tm.sec = cont; configR = 8; } @@ -518,44 +1235,64 @@ configR = 0; estado=0; wait(2); + } } } - + + + +int Alarm_IRDA(void){ + int x1 = 0, x2 = 0, x3 = 0, c = 0; -int main(){ - while(1) { - pc.printf("Corriendo ...\n"); - - Menu(); - wait_ms(1000); - OpcionMenu = LeerEncoder(); - pc.printf("%i",OpcionMenu); - switch(OpcionMenu){ - //pc.printf("%i",OpcionMenu); - case 1: - // 1 HORA - ImprimirHora(); - case 2: - //Configurar hora - ConfiReloj(); - break; - case 3: - // Alarmas - break; - case 4: - lcd.cls(); - lcd.locate(0,0); - lcd.printf("Esperando trama"); - lcd.locate(0,1); - lcd.printf("control remoto"); - LeerIRDA(); - break; - } - //ImprimirHora(); - wait_ms(500); - //LeerEncoder(); - //wait_ms(50); - //LeerIRDA(); - } -} + while(1){ + if (detectar() == 1){ + c++; + if(c == 1){ + x1 = irdan(); + pc.printf("\nx1: %d c: %d\n",x1,c); + x = x1; + if(x1==-8){ + x=x1; + break; + } + pc.printf("\nx: %02d",x); + pc.printf("num: %032d",irdan()); + }//c1 + + if(c == 2){ + x2 = irdan(); + pc.printf("\nx2: %d c: %d\n",x2,c); + if( x2 == -8){ + x = x1; + pc.printf("\nx: %02d",x); + pc.printf("num: %032d",sel); + break; + } + else{ + x = x1*10 + x2; + pc.printf("\nx: %02d",x); + pc.printf("num: %032d",sel); + + } + + + }//c2 + if (c == 3){ + x3 = irdan(); + pc.printf("\nx3: %d c: %d\n",x3,c); + pc.printf("\nx: %02d",x); + pc.printf("num: %032d",sel); + if( x3 == -8){ + x = ((x1*10) + x2); + pc.printf("\nx: %02d",x); + pc.printf("num: %032d",sel); + break; + } + } //c3 + }//detectar + + }//while + return x; + + }//funcion \ No newline at end of file