Control PID para horno de reflujo con seguimiento de consigna

Dependencies:   Debounced Pulse1 QEI RTC-DS1307 TextLCD mbed

Fork of Tarea3_procesadores_Ds1307 by Camilo Londoño

Tarea 4 procesadores 2018-1

Juan Camilo Londoño Julieta Serrano Escalante

PID para horno de reflujo conseguimiento de consigna

/media/uploads/jclondonol/4.jpg

Committer:
jclondonol
Date:
Wed May 09 19:55:50 2018 +0000
Revision:
2:bef1b1c9e387
Parent:
1:0639f31dd59f
Child:
3:35a40be1047f
Reloj con 7 alarmas configurables y 9 menus correspondientes a la recepcion de datos de irda, rejoj, y 1 por cada alarma

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jepalacioh 0:c2ed510ee88d 1 #include "mbed.h"
Jepalacioh 0:c2ed510ee88d 2 #include "DebouncedIn.h"
Jepalacioh 0:c2ed510ee88d 3 #include "TextLCD.h"
Jepalacioh 0:c2ed510ee88d 4 #include "QEI.h"
Jepalacioh 0:c2ed510ee88d 5 #include "Rtc_Ds1307.h"
jclondonol 2:bef1b1c9e387 6 #include <Pulse1.h>
Jepalacioh 0:c2ed510ee88d 7
jclondonol 2:bef1b1c9e387 8 TextLCD lcd(PTB0, PTB1, PTB2, PTB3, PTC2, PTC1); // rs, e, d4, d5, d6, d7
Jepalacioh 0:c2ed510ee88d 9 Rtc_Ds1307 rtc(PTE0, PTE1);
jclondonol 2:bef1b1c9e387 10 QEI wheel (PTD7, PTD6, NC, 30);
Jepalacioh 0:c2ed510ee88d 11 DebouncedIn button_enco(PTC5);
jclondonol 2:bef1b1c9e387 12 PwmOut Sonido(PTD1);
jclondonol 2:bef1b1c9e387 13 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
Jepalacioh 0:c2ed510ee88d 14
Jepalacioh 0:c2ed510ee88d 15
Jepalacioh 0:c2ed510ee88d 16 float periodo;
jclondonol 2:bef1b1c9e387 17 float Frecuencia = 4000;
jclondonol 2:bef1b1c9e387 18 int C1 = 0x0C;
jclondonol 2:bef1b1c9e387 19 int m = 0, flag = 0;
jclondonol 2:bef1b1c9e387 20 uint8_t pot[7] = {1, 2, 4, 8, 16, 32, 64};
jclondonol 2:bef1b1c9e387 21 uint8_t pot1[7] = {254, 253, 251, 248, 239, 223, 191};
jclondonol 2:bef1b1c9e387 22 int Lugar = 0; // Definen el punto en el cual va el programa
jclondonol 2:bef1b1c9e387 23 int i = 0, j = 0;
jclondonol 2:bef1b1c9e387 24 int pos = 0; // Reloj:0, Alarma1:1, Alarma2:2, ... , Alarma7:7
jclondonol 2:bef1b1c9e387 25 uint8_t state_alarms = 0, pos_alarm = 0, alarma = 0;
jclondonol 2:bef1b1c9e387 26
jclondonol 2:bef1b1c9e387 27 //irda
jclondonol 2:bef1b1c9e387 28 int header = 0; //tiempo de cabecera pulso abajo
jclondonol 2:bef1b1c9e387 29 const int head_H = 4532; //+20% medida con osciloscopio en microsegundos
jclondonol 2:bef1b1c9e387 30 const int head_L = 4494;//-20% medida con osciloscopio
jclondonol 2:bef1b1c9e387 31 int g = 0, h = 0, count = 0;
jclondonol 2:bef1b1c9e387 32 const int T_alto = 1600;//ponga su tiempo de la prueba
jclondonol 2:bef1b1c9e387 33 const int T_bajo = 485;//ponga su tiempo de la prueba
jclondonol 2:bef1b1c9e387 34 const int num_bits = 32;//ponga su numero de bits
jclondonol 2:bef1b1c9e387 35 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
jclondonol 2:bef1b1c9e387 36 int sec[num_bits];//cadena para almacenar la cadena codificada en binario
jclondonol 2:bef1b1c9e387 37 int dato; // tiempo de cada dato que se lee
jclondonol 2:bef1b1c9e387 38 int boton_sel = 10;
jclondonol 2:bef1b1c9e387 39 int boton[10][32]= {{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,0}, //0
jclondonol 2:bef1b1c9e387 40 {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,0}, //1
jclondonol 2:bef1b1c9e387 41 {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,0}, //2
jclondonol 2:bef1b1c9e387 42 {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,0}, //3
jclondonol 2:bef1b1c9e387 43 {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,0}, //4
jclondonol 2:bef1b1c9e387 44 {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,0}, //5
jclondonol 2:bef1b1c9e387 45 {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,0}, //6
jclondonol 2:bef1b1c9e387 46 {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,0}, //7
jclondonol 2:bef1b1c9e387 47 {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,0}, //8
jclondonol 2:bef1b1c9e387 48 {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,0}}; //9
jclondonol 2:bef1b1c9e387 49
Jepalacioh 0:c2ed510ee88d 50
Jepalacioh 0:c2ed510ee88d 51 int main()
Jepalacioh 0:c2ed510ee88d 52 {
Jepalacioh 0:c2ed510ee88d 53 Rtc_Ds1307::Time_rtc tm = {};
jclondonol 2:bef1b1c9e387 54 Rtc_Ds1307::Time_rtc Alarm[7] = {};
Jepalacioh 0:c2ed510ee88d 55 lcd.cls();
Jepalacioh 0:c2ed510ee88d 56 lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
Jepalacioh 0:c2ed510ee88d 57 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 58 periodo=(1/Frecuencia);
Jepalacioh 0:c2ed510ee88d 59 Sonido.period(periodo);
tony63 1:0639f31dd59f 60 rtc.getTime(tm); //lee el tiempo del DS1307
jclondonol 2:bef1b1c9e387 61 Sonido.write(255);
jclondonol 2:bef1b1c9e387 62
Jepalacioh 0:c2ed510ee88d 63
Jepalacioh 0:c2ed510ee88d 64 while(1)
Jepalacioh 0:c2ed510ee88d 65 {
Jepalacioh 0:c2ed510ee88d 66 switch (Lugar)
jclondonol 2:bef1b1c9e387 67 {
Jepalacioh 0:c2ed510ee88d 68 case 0:
jclondonol 2:bef1b1c9e387 69
jclondonol 2:bef1b1c9e387 70 rtc.getTime(tm);
jclondonol 2:bef1b1c9e387 71 m = wheel.getPulses();
jclondonol 2:bef1b1c9e387 72 if(m != 0)
jclondonol 2:bef1b1c9e387 73 {
jclondonol 2:bef1b1c9e387 74 wheel.reset();
jclondonol 2:bef1b1c9e387 75 pos = pos + m;
jclondonol 2:bef1b1c9e387 76 m = 0;
jclondonol 2:bef1b1c9e387 77 lcd.cls();
jclondonol 2:bef1b1c9e387 78 }
jclondonol 2:bef1b1c9e387 79 if(pos > 7)
jclondonol 2:bef1b1c9e387 80 {
jclondonol 2:bef1b1c9e387 81 pos = -1;
jclondonol 2:bef1b1c9e387 82 }
jclondonol 2:bef1b1c9e387 83 if(pos < -1)
jclondonol 2:bef1b1c9e387 84 {
jclondonol 2:bef1b1c9e387 85 pos = 7;
jclondonol 2:bef1b1c9e387 86 }
jclondonol 2:bef1b1c9e387 87 if(pos == 0)
jclondonol 2:bef1b1c9e387 88 {
jclondonol 2:bef1b1c9e387 89 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 90 lcd.printf("Time: ");
jclondonol 2:bef1b1c9e387 91 lcd.locate(8,0);
jclondonol 2:bef1b1c9e387 92 lcd.printf("%02d:",tm.hour);
jclondonol 2:bef1b1c9e387 93 lcd.printf("%02d:",tm.min);
jclondonol 2:bef1b1c9e387 94 lcd.printf("%02d",tm.sec);
jclondonol 2:bef1b1c9e387 95 lcd.locate(0,1);
jclondonol 2:bef1b1c9e387 96 lcd.printf("%02d/",tm.mon);
jclondonol 2:bef1b1c9e387 97 lcd.printf("%02d/",tm.date);
jclondonol 2:bef1b1c9e387 98 lcd.printf("%02d",tm.year);
jclondonol 2:bef1b1c9e387 99 wait(0.1);
Jepalacioh 0:c2ed510ee88d 100 }
Jepalacioh 0:c2ed510ee88d 101
jclondonol 2:bef1b1c9e387 102 if(pos == -1)
jclondonol 2:bef1b1c9e387 103 {
jclondonol 2:bef1b1c9e387 104 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 105 lcd.printf("Alarm Setup IRDA");
Jepalacioh 0:c2ed510ee88d 106 wait(0.1);
Jepalacioh 0:c2ed510ee88d 107 }
Jepalacioh 0:c2ed510ee88d 108
jclondonol 2:bef1b1c9e387 109
jclondonol 2:bef1b1c9e387 110 if(pos > 0)
jclondonol 2:bef1b1c9e387 111 {
jclondonol 2:bef1b1c9e387 112 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 113 lcd.printf("Alarm %d", pos);
jclondonol 2:bef1b1c9e387 114 lcd.locate(8,0);
jclondonol 2:bef1b1c9e387 115 lcd.printf("%02d:",Alarm[pos - 1].hour);
jclondonol 2:bef1b1c9e387 116 lcd.printf("%02d:",Alarm[pos - 1].min);
jclondonol 2:bef1b1c9e387 117 lcd.printf("%02d",Alarm[pos - 1].sec);
jclondonol 2:bef1b1c9e387 118 lcd.locate(0,1);
jclondonol 2:bef1b1c9e387 119 lcd.printf("%02d/",Alarm[pos - 1].mon);
jclondonol 2:bef1b1c9e387 120 lcd.printf("%02d/",Alarm[pos - 1].date);
jclondonol 2:bef1b1c9e387 121 lcd.printf("%02d",Alarm[pos - 1].year);
jclondonol 2:bef1b1c9e387 122 lcd.locate(13,1);
jclondonol 2:bef1b1c9e387 123 if((state_alarms&(pot[pos - 1])) == pot[pos - 1])
jclondonol 2:bef1b1c9e387 124 {
jclondonol 2:bef1b1c9e387 125 lcd.printf("On ");
jclondonol 2:bef1b1c9e387 126 }
jclondonol 2:bef1b1c9e387 127 else
jclondonol 2:bef1b1c9e387 128 {
jclondonol 2:bef1b1c9e387 129 lcd.printf("Off");
jclondonol 2:bef1b1c9e387 130 }
jclondonol 2:bef1b1c9e387 131
jclondonol 2:bef1b1c9e387 132 wait(0.1);
Jepalacioh 0:c2ed510ee88d 133 }
jclondonol 2:bef1b1c9e387 134 for(j=0;j<7;j++)
jclondonol 2:bef1b1c9e387 135 {
jclondonol 2:bef1b1c9e387 136 if( (tm.date==Alarm[j].date)&&(tm.mon==Alarm[j].mon)&&(tm.year==Alarm[j].year)&&(tm.hour==Alarm[j].hour)&&(tm.min==Alarm[j].min)&&(tm.sec==Alarm[j].sec)&&((state_alarms&(pot[j])) == pot[j]))
jclondonol 2:bef1b1c9e387 137 {
jclondonol 2:bef1b1c9e387 138 Lugar = 2;
jclondonol 2:bef1b1c9e387 139 lcd.cls();
jclondonol 2:bef1b1c9e387 140 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 141 lcd.printf("Active Alarm%d!!!",(j+1));
jclondonol 2:bef1b1c9e387 142 lcd.locate(0,1);
jclondonol 2:bef1b1c9e387 143 lcd.printf("->Disable ");
jclondonol 2:bef1b1c9e387 144 lcd.locate(10,1);
jclondonol 2:bef1b1c9e387 145 lcd.printf("--5min");
jclondonol 2:bef1b1c9e387 146 pos_alarm = j;
jclondonol 2:bef1b1c9e387 147 }
jclondonol 2:bef1b1c9e387 148 }
jclondonol 2:bef1b1c9e387 149
jclondonol 2:bef1b1c9e387 150 if (button_enco.falling()) //si se pulsa boton encoder
jclondonol 2:bef1b1c9e387 151 {
jclondonol 2:bef1b1c9e387 152 if(pos == -1)
jclondonol 2:bef1b1c9e387 153 {Lugar = 3;
jclondonol 2:bef1b1c9e387 154 lcd.cls();}
jclondonol 2:bef1b1c9e387 155 else
jclondonol 2:bef1b1c9e387 156 {Lugar = 1;}
jclondonol 2:bef1b1c9e387 157
jclondonol 2:bef1b1c9e387 158 }
jclondonol 2:bef1b1c9e387 159
Jepalacioh 0:c2ed510ee88d 160 break;
Jepalacioh 0:c2ed510ee88d 161
Jepalacioh 0:c2ed510ee88d 162 case 1:
Jepalacioh 0:c2ed510ee88d 163 switch(i)
Jepalacioh 0:c2ed510ee88d 164 {
Jepalacioh 0:c2ed510ee88d 165 case 0:
jclondonol 2:bef1b1c9e387 166 if(pos == 0)
Jepalacioh 0:c2ed510ee88d 167 {
Jepalacioh 0:c2ed510ee88d 168 lcd.cls();
Jepalacioh 0:c2ed510ee88d 169 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 170 lcd.printf("Time Setup");
jclondonol 2:bef1b1c9e387 171 }
jclondonol 2:bef1b1c9e387 172
jclondonol 2:bef1b1c9e387 173 if(pos > 0)
Jepalacioh 0:c2ed510ee88d 174 {
Jepalacioh 0:c2ed510ee88d 175 lcd.cls();
Jepalacioh 0:c2ed510ee88d 176 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 177 lcd.printf("Alarm %d Setup", pos);
jclondonol 2:bef1b1c9e387 178 }
jclondonol 2:bef1b1c9e387 179 wait(1);
jclondonol 2:bef1b1c9e387 180 i++;
jclondonol 2:bef1b1c9e387 181 lcd.cls();
jclondonol 2:bef1b1c9e387 182 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 183 lcd.printf("Day: ");
Jepalacioh 0:c2ed510ee88d 184 break;
Jepalacioh 0:c2ed510ee88d 185
Jepalacioh 0:c2ed510ee88d 186 case 1:
jclondonol 2:bef1b1c9e387 187 m = wheel.getPulses();
jclondonol 2:bef1b1c9e387 188 if (m != 0)
Jepalacioh 0:c2ed510ee88d 189 {
jclondonol 2:bef1b1c9e387 190 tm.date = tm.date + m;
jclondonol 2:bef1b1c9e387 191 if(tm.date > 31)
Jepalacioh 0:c2ed510ee88d 192 {
jclondonol 2:bef1b1c9e387 193 tm.date = 1;
Jepalacioh 0:c2ed510ee88d 194 }
jclondonol 2:bef1b1c9e387 195 if(tm.date < 1)
Jepalacioh 0:c2ed510ee88d 196 {
jclondonol 2:bef1b1c9e387 197 tm.date = 31;
Jepalacioh 0:c2ed510ee88d 198 }
Jepalacioh 0:c2ed510ee88d 199 wheel.reset();
jclondonol 2:bef1b1c9e387 200 m = 0;
Jepalacioh 0:c2ed510ee88d 201 }
Jepalacioh 0:c2ed510ee88d 202 lcd.locate(5,0);
Jepalacioh 0:c2ed510ee88d 203 lcd.printf("%02d",tm.date);
Jepalacioh 0:c2ed510ee88d 204
Jepalacioh 0:c2ed510ee88d 205 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 206 {
Jepalacioh 0:c2ed510ee88d 207 i++;
Jepalacioh 0:c2ed510ee88d 208 lcd.cls();
Jepalacioh 0:c2ed510ee88d 209 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 210 lcd.printf("Month: ");
Jepalacioh 0:c2ed510ee88d 211 }
Jepalacioh 0:c2ed510ee88d 212 break;
Jepalacioh 0:c2ed510ee88d 213
Jepalacioh 0:c2ed510ee88d 214 case 2:
jclondonol 2:bef1b1c9e387 215 m = wheel.getPulses();
jclondonol 2:bef1b1c9e387 216 if (m != 0)
Jepalacioh 0:c2ed510ee88d 217 {
jclondonol 2:bef1b1c9e387 218 tm.mon = tm.mon + m;
jclondonol 2:bef1b1c9e387 219 if(tm.mon > 12)
Jepalacioh 0:c2ed510ee88d 220 {
jclondonol 2:bef1b1c9e387 221 tm.mon = 1;
Jepalacioh 0:c2ed510ee88d 222 }
jclondonol 2:bef1b1c9e387 223 if(tm.mon < 1)
Jepalacioh 0:c2ed510ee88d 224 {
jclondonol 2:bef1b1c9e387 225 tm.mon = 12;
Jepalacioh 0:c2ed510ee88d 226 }
Jepalacioh 0:c2ed510ee88d 227 wheel.reset();
jclondonol 2:bef1b1c9e387 228 m = 0;
Jepalacioh 0:c2ed510ee88d 229 }
jclondonol 2:bef1b1c9e387 230 lcd.locate(7,0);
Jepalacioh 0:c2ed510ee88d 231 lcd.printf("%02d",tm.mon);
Jepalacioh 0:c2ed510ee88d 232
Jepalacioh 0:c2ed510ee88d 233 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 234 {
Jepalacioh 0:c2ed510ee88d 235 i++;
Jepalacioh 0:c2ed510ee88d 236 lcd.cls();
Jepalacioh 0:c2ed510ee88d 237 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 238 lcd.printf("Year: ");
Jepalacioh 0:c2ed510ee88d 239 }
Jepalacioh 0:c2ed510ee88d 240 break;
Jepalacioh 0:c2ed510ee88d 241
Jepalacioh 0:c2ed510ee88d 242 case 3:
jclondonol 2:bef1b1c9e387 243 m = wheel.getPulses();
jclondonol 2:bef1b1c9e387 244 if (m != 0)
Jepalacioh 0:c2ed510ee88d 245 {
jclondonol 2:bef1b1c9e387 246 tm.year = tm.year + m;
jclondonol 2:bef1b1c9e387 247 if(tm.year < 2000)
Jepalacioh 0:c2ed510ee88d 248 {
jclondonol 2:bef1b1c9e387 249 tm.year = 2000;
Jepalacioh 0:c2ed510ee88d 250 }
Jepalacioh 0:c2ed510ee88d 251 wheel.reset();
jclondonol 2:bef1b1c9e387 252 m = 0;
Jepalacioh 0:c2ed510ee88d 253 }
Jepalacioh 0:c2ed510ee88d 254 lcd.locate(6,0);
Jepalacioh 0:c2ed510ee88d 255 lcd.printf("%02d",tm.year);
Jepalacioh 0:c2ed510ee88d 256
Jepalacioh 0:c2ed510ee88d 257 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 258 {
Jepalacioh 0:c2ed510ee88d 259 i++;
Jepalacioh 0:c2ed510ee88d 260 lcd.cls();
Jepalacioh 0:c2ed510ee88d 261 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 262 lcd.printf("Hours: ");
Jepalacioh 0:c2ed510ee88d 263 }
Jepalacioh 0:c2ed510ee88d 264 break;
Jepalacioh 0:c2ed510ee88d 265
jclondonol 2:bef1b1c9e387 266 case 4:
jclondonol 2:bef1b1c9e387 267 m = wheel.getPulses();
jclondonol 2:bef1b1c9e387 268 if (m != 0)
Jepalacioh 0:c2ed510ee88d 269 {
jclondonol 2:bef1b1c9e387 270 tm.hour = tm.hour + m;
jclondonol 2:bef1b1c9e387 271 if(tm.hour > 23)
Jepalacioh 0:c2ed510ee88d 272 {
jclondonol 2:bef1b1c9e387 273 tm.hour = 0;
Jepalacioh 0:c2ed510ee88d 274 }
jclondonol 2:bef1b1c9e387 275 if(tm.hour < 0)
Jepalacioh 0:c2ed510ee88d 276 {
jclondonol 2:bef1b1c9e387 277 tm.hour = 23;
Jepalacioh 0:c2ed510ee88d 278 }
Jepalacioh 0:c2ed510ee88d 279 wheel.reset();
jclondonol 2:bef1b1c9e387 280 m = 0;
Jepalacioh 0:c2ed510ee88d 281 }
jclondonol 2:bef1b1c9e387 282 lcd.locate(7,0);
Jepalacioh 0:c2ed510ee88d 283 lcd.printf("%02d",tm.hour);
Jepalacioh 0:c2ed510ee88d 284
Jepalacioh 0:c2ed510ee88d 285 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 286 {
Jepalacioh 0:c2ed510ee88d 287 i++;
Jepalacioh 0:c2ed510ee88d 288 lcd.cls();
Jepalacioh 0:c2ed510ee88d 289 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 290 lcd.printf("Minutes: ");
Jepalacioh 0:c2ed510ee88d 291 }
Jepalacioh 0:c2ed510ee88d 292
Jepalacioh 0:c2ed510ee88d 293 break;
Jepalacioh 0:c2ed510ee88d 294
Jepalacioh 0:c2ed510ee88d 295 case 5:
jclondonol 2:bef1b1c9e387 296 m = wheel.getPulses();
jclondonol 2:bef1b1c9e387 297 if (m != 0)
Jepalacioh 0:c2ed510ee88d 298 {
jclondonol 2:bef1b1c9e387 299 tm.min = tm.min + m;
jclondonol 2:bef1b1c9e387 300 if(tm.min > 59)
Jepalacioh 0:c2ed510ee88d 301 {
jclondonol 2:bef1b1c9e387 302 tm.min = 0;
Jepalacioh 0:c2ed510ee88d 303 }
jclondonol 2:bef1b1c9e387 304 if(tm.min < 0)
Jepalacioh 0:c2ed510ee88d 305 {
jclondonol 2:bef1b1c9e387 306 tm.min = 59;
Jepalacioh 0:c2ed510ee88d 307 }
Jepalacioh 0:c2ed510ee88d 308
Jepalacioh 0:c2ed510ee88d 309 wheel.reset();
jclondonol 2:bef1b1c9e387 310 m = 0;
Jepalacioh 0:c2ed510ee88d 311 }
jclondonol 2:bef1b1c9e387 312 lcd.locate(9,0);
Jepalacioh 0:c2ed510ee88d 313 lcd.printf("%02d",tm.min);
Jepalacioh 0:c2ed510ee88d 314
Jepalacioh 0:c2ed510ee88d 315 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 316 {
Jepalacioh 0:c2ed510ee88d 317 i++;
Jepalacioh 0:c2ed510ee88d 318 lcd.cls();
Jepalacioh 0:c2ed510ee88d 319 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 320 lcd.printf("Seconds: ");
Jepalacioh 0:c2ed510ee88d 321 }
Jepalacioh 0:c2ed510ee88d 322 break;
Jepalacioh 0:c2ed510ee88d 323
Jepalacioh 0:c2ed510ee88d 324
Jepalacioh 0:c2ed510ee88d 325 case 6:
jclondonol 2:bef1b1c9e387 326 m = wheel.getPulses();
jclondonol 2:bef1b1c9e387 327 if (m != 0)
Jepalacioh 0:c2ed510ee88d 328 {
jclondonol 2:bef1b1c9e387 329 tm.sec = tm.sec + m;
jclondonol 2:bef1b1c9e387 330 if(tm.sec > 59)
Jepalacioh 0:c2ed510ee88d 331 {
jclondonol 2:bef1b1c9e387 332 tm.sec = 0;
Jepalacioh 0:c2ed510ee88d 333 }
jclondonol 2:bef1b1c9e387 334 if(tm.sec < 0)
Jepalacioh 0:c2ed510ee88d 335 {
jclondonol 2:bef1b1c9e387 336 tm.sec = 59;
Jepalacioh 0:c2ed510ee88d 337 }
Jepalacioh 0:c2ed510ee88d 338 wheel.reset();
jclondonol 2:bef1b1c9e387 339 m = 0;
Jepalacioh 0:c2ed510ee88d 340 }
Jepalacioh 0:c2ed510ee88d 341 lcd.locate(9,0);
Jepalacioh 0:c2ed510ee88d 342 lcd.printf("%02d",tm.sec);
Jepalacioh 0:c2ed510ee88d 343
Jepalacioh 0:c2ed510ee88d 344 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 345 {
jclondonol 2:bef1b1c9e387 346 if(pos==0)
Jepalacioh 0:c2ed510ee88d 347 {
Jepalacioh 0:c2ed510ee88d 348 rtc.setTime(tm, false, false);
Jepalacioh 0:c2ed510ee88d 349 rtc.startClock();
Jepalacioh 0:c2ed510ee88d 350 lcd.cls();
jclondonol 2:bef1b1c9e387 351 lcd.locate(0, 0);
jclondonol 2:bef1b1c9e387 352 lcd.printf("Time Set");
Jepalacioh 0:c2ed510ee88d 353 wait(1);
jclondonol 2:bef1b1c9e387 354 i = 0;
jclondonol 2:bef1b1c9e387 355 Lugar = 0;
jclondonol 2:bef1b1c9e387 356 lcd.cls();
jclondonol 2:bef1b1c9e387 357 }
jclondonol 2:bef1b1c9e387 358 if(pos > 0)
jclondonol 2:bef1b1c9e387 359 {
jclondonol 2:bef1b1c9e387 360 i++;
jclondonol 2:bef1b1c9e387 361 lcd.cls();
Jepalacioh 0:c2ed510ee88d 362 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 363 lcd.printf("Enable: Off");
jclondonol 2:bef1b1c9e387 364 }
Jepalacioh 0:c2ed510ee88d 365 }
Jepalacioh 0:c2ed510ee88d 366 break;
jclondonol 2:bef1b1c9e387 367
jclondonol 2:bef1b1c9e387 368 case 7:
jclondonol 2:bef1b1c9e387 369 m = wheel.getPulses();
jclondonol 2:bef1b1c9e387 370 if (m != 0)
jclondonol 2:bef1b1c9e387 371 {
jclondonol 2:bef1b1c9e387 372 if(flag == 0)
jclondonol 2:bef1b1c9e387 373 {
jclondonol 2:bef1b1c9e387 374 lcd.locate(8,0);
jclondonol 2:bef1b1c9e387 375 lcd.printf("On ");
jclondonol 2:bef1b1c9e387 376 flag = 1; //se activa la alarma
jclondonol 2:bef1b1c9e387 377 }
jclondonol 2:bef1b1c9e387 378 else
jclondonol 2:bef1b1c9e387 379 if(flag == 1)
jclondonol 2:bef1b1c9e387 380 {
jclondonol 2:bef1b1c9e387 381 lcd.locate(8,0);
jclondonol 2:bef1b1c9e387 382 lcd.printf("Off");
jclondonol 2:bef1b1c9e387 383 flag = 0; //se desactiva la alarma
jclondonol 2:bef1b1c9e387 384 }
jclondonol 2:bef1b1c9e387 385 wheel.reset();
jclondonol 2:bef1b1c9e387 386 m = 0;
jclondonol 2:bef1b1c9e387 387 }
jclondonol 2:bef1b1c9e387 388
jclondonol 2:bef1b1c9e387 389 if (button_enco.falling())
jclondonol 2:bef1b1c9e387 390 {
jclondonol 2:bef1b1c9e387 391 if(flag == 1)
jclondonol 2:bef1b1c9e387 392 {
jclondonol 2:bef1b1c9e387 393 state_alarms = state_alarms | pot[(pos - 1)];
jclondonol 2:bef1b1c9e387 394 }
jclondonol 2:bef1b1c9e387 395 if(flag == 0)
jclondonol 2:bef1b1c9e387 396 {
jclondonol 2:bef1b1c9e387 397 state_alarms = state_alarms & pot1[(pos - 1)];
jclondonol 2:bef1b1c9e387 398 }
jclondonol 2:bef1b1c9e387 399 Alarm[pos - 1] = tm;
jclondonol 2:bef1b1c9e387 400 lcd.cls();
jclondonol 2:bef1b1c9e387 401 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 402 lcd.printf("Alarm %d Set", pos);
jclondonol 2:bef1b1c9e387 403 wait(1);
jclondonol 2:bef1b1c9e387 404 i = 0;
jclondonol 2:bef1b1c9e387 405 Lugar = 0;
jclondonol 2:bef1b1c9e387 406 flag = 0;
jclondonol 2:bef1b1c9e387 407 lcd.cls();
jclondonol 2:bef1b1c9e387 408 }
jclondonol 2:bef1b1c9e387 409 break;
Jepalacioh 0:c2ed510ee88d 410 }
Jepalacioh 0:c2ed510ee88d 411 break;
Jepalacioh 0:c2ed510ee88d 412
Jepalacioh 0:c2ed510ee88d 413 case 2:
jclondonol 2:bef1b1c9e387 414 Sonido.write(0.5);
jclondonol 2:bef1b1c9e387 415 wait(0.2);
jclondonol 2:bef1b1c9e387 416 Sonido.write(255);
jclondonol 2:bef1b1c9e387 417 wait(0.2);
jclondonol 2:bef1b1c9e387 418 Sonido.write(0.5);
jclondonol 2:bef1b1c9e387 419 wait(0.2);
jclondonol 2:bef1b1c9e387 420 Sonido.write(255);
jclondonol 2:bef1b1c9e387 421 wait(0.2);
Jepalacioh 0:c2ed510ee88d 422
jclondonol 2:bef1b1c9e387 423 m = wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 424
jclondonol 2:bef1b1c9e387 425 if(alarma == 0) //pos_alarm
jclondonol 2:bef1b1c9e387 426 {
jclondonol 2:bef1b1c9e387 427 if(m != 0)
Jepalacioh 0:c2ed510ee88d 428 {
jclondonol 2:bef1b1c9e387 429 alarma = 1;
Jepalacioh 0:c2ed510ee88d 430 wheel.reset();
jclondonol 2:bef1b1c9e387 431 m = 0;
jclondonol 2:bef1b1c9e387 432 lcd.locate(1,1);
Jepalacioh 0:c2ed510ee88d 433 lcd.printf("-");
jclondonol 2:bef1b1c9e387 434 lcd.locate(11,1);
Jepalacioh 0:c2ed510ee88d 435 lcd.printf(">");
Jepalacioh 0:c2ed510ee88d 436 }
Jepalacioh 0:c2ed510ee88d 437 }
Jepalacioh 0:c2ed510ee88d 438
jclondonol 2:bef1b1c9e387 439 if(alarma == 1)
Jepalacioh 0:c2ed510ee88d 440 {
jclondonol 2:bef1b1c9e387 441 if(m != 0)
Jepalacioh 0:c2ed510ee88d 442 {
jclondonol 2:bef1b1c9e387 443 alarma = 0;
Jepalacioh 0:c2ed510ee88d 444 wheel.reset();
jclondonol 2:bef1b1c9e387 445 m = 0;
jclondonol 2:bef1b1c9e387 446 lcd.locate(1,1);
Jepalacioh 0:c2ed510ee88d 447 lcd.printf(">");
jclondonol 2:bef1b1c9e387 448 lcd.locate(11,1);
Jepalacioh 0:c2ed510ee88d 449 lcd.printf("-");
Jepalacioh 0:c2ed510ee88d 450 }
Jepalacioh 0:c2ed510ee88d 451 }
Jepalacioh 0:c2ed510ee88d 452
Jepalacioh 0:c2ed510ee88d 453 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 454 {
jclondonol 2:bef1b1c9e387 455 if(alarma == 0)
Jepalacioh 0:c2ed510ee88d 456 {
Jepalacioh 0:c2ed510ee88d 457 wheel.reset();
Jepalacioh 0:c2ed510ee88d 458 m=0;
jclondonol 2:bef1b1c9e387 459 Sonido.write(255);
Jepalacioh 0:c2ed510ee88d 460 lcd.cls();
jclondonol 2:bef1b1c9e387 461 wait(0.5);
Jepalacioh 0:c2ed510ee88d 462
Jepalacioh 0:c2ed510ee88d 463 }
Jepalacioh 0:c2ed510ee88d 464 if(alarma==1)
Jepalacioh 0:c2ed510ee88d 465 {
Jepalacioh 0:c2ed510ee88d 466 rtc.getTime(tm);
jclondonol 2:bef1b1c9e387 467 if(tm.min >= 55)
Jepalacioh 0:c2ed510ee88d 468 {
jclondonol 2:bef1b1c9e387 469 Alarm[pos_alarm].min = (tm.min + 5) - 60;
jclondonol 2:bef1b1c9e387 470 Alarm[pos_alarm].hour = tm.hour + 1;
Jepalacioh 0:c2ed510ee88d 471 }
jclondonol 2:bef1b1c9e387 472 else
Jepalacioh 0:c2ed510ee88d 473 {
jclondonol 2:bef1b1c9e387 474 Alarm[pos_alarm].min = tm.min + 5;
Jepalacioh 0:c2ed510ee88d 475 }
Jepalacioh 0:c2ed510ee88d 476 lcd.cls();
Jepalacioh 0:c2ed510ee88d 477 alarma=0;
Jepalacioh 0:c2ed510ee88d 478
Jepalacioh 0:c2ed510ee88d 479 }
jclondonol 2:bef1b1c9e387 480 Lugar = 0;
Jepalacioh 0:c2ed510ee88d 481 }
jclondonol 2:bef1b1c9e387 482 break;
jclondonol 2:bef1b1c9e387 483
jclondonol 2:bef1b1c9e387 484 case 3:
jclondonol 2:bef1b1c9e387 485 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 486 lcd.printf("Waiting IRDA");
jclondonol 2:bef1b1c9e387 487 header = 0;
jclondonol 2:bef1b1c9e387 488 header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo
jclondonol 2:bef1b1c9e387 489 if (header > head_L && header < head_H)//verificar que este en la tolerancia +-20%
jclondonol 2:bef1b1c9e387 490 {
jclondonol 2:bef1b1c9e387 491 //leo los datos de la trama y se meten a un arreglo
jclondonol 2:bef1b1c9e387 492 wait_us(2000);
jclondonol 2:bef1b1c9e387 493 for(g = 0; g<(num_bits-1); g++) // POR OSCILOSCOPIO se determina que llegan (num_bits),datos
jclondonol 2:bef1b1c9e387 494 {
jclondonol 2:bef1b1c9e387 495 dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control
jclondonol 2:bef1b1c9e387 496 num[g]=dato;
jclondonol 2:bef1b1c9e387 497 wait_us(332);
jclondonol 2:bef1b1c9e387 498 }
jclondonol 2:bef1b1c9e387 499 for(g = 0; g<num_bits; g++) // guardo la secuancia en binario
jclondonol 2:bef1b1c9e387 500 {
jclondonol 2:bef1b1c9e387 501 if(num[g] > ((T_alto+T_bajo)/2)){sec[g]=1;}
jclondonol 2:bef1b1c9e387 502 else {sec[g]=0;}
jclondonol 2:bef1b1c9e387 503 }
jclondonol 2:bef1b1c9e387 504 for(h = 0; h < 8; h++)
jclondonol 2:bef1b1c9e387 505 {
jclondonol 2:bef1b1c9e387 506 for(g = 0; g < 32; g++)
jclondonol 2:bef1b1c9e387 507 {
jclondonol 2:bef1b1c9e387 508 if(sec[g]==boton[h][g]) //en caso de que un bit no coincida se descarta el boton 1
jclondonol 2:bef1b1c9e387 509 {
jclondonol 2:bef1b1c9e387 510 count++;
jclondonol 2:bef1b1c9e387 511 if(count==32)
jclondonol 2:bef1b1c9e387 512 {
jclondonol 2:bef1b1c9e387 513 boton_sel = h - 1;
jclondonol 2:bef1b1c9e387 514 lcd.cls();
jclondonol 2:bef1b1c9e387 515 lcd.locate(0,0);
jclondonol 2:bef1b1c9e387 516 lcd.printf("Alarm %d: ",(boton_sel+1));
jclondonol 2:bef1b1c9e387 517 if(boton_sel >= 0)
jclondonol 2:bef1b1c9e387 518 {
jclondonol 2:bef1b1c9e387 519 if((state_alarms&(pot[boton_sel])) == pot[boton_sel])
jclondonol 2:bef1b1c9e387 520 {
jclondonol 2:bef1b1c9e387 521 state_alarms = state_alarms & pot1[boton_sel];
jclondonol 2:bef1b1c9e387 522 lcd.locate(10,0);
jclondonol 2:bef1b1c9e387 523 lcd.printf("Off");
jclondonol 2:bef1b1c9e387 524 wait(1.5);
jclondonol 2:bef1b1c9e387 525 lcd.cls();
jclondonol 2:bef1b1c9e387 526 }
jclondonol 2:bef1b1c9e387 527 else
jclondonol 2:bef1b1c9e387 528 {
jclondonol 2:bef1b1c9e387 529 state_alarms = state_alarms | pot[boton_sel];
jclondonol 2:bef1b1c9e387 530 lcd.locate(10,0);
jclondonol 2:bef1b1c9e387 531 lcd.printf("On ");
jclondonol 2:bef1b1c9e387 532 wait(1.5);
jclondonol 2:bef1b1c9e387 533 lcd.cls();
jclondonol 2:bef1b1c9e387 534 }
jclondonol 2:bef1b1c9e387 535 }
jclondonol 2:bef1b1c9e387 536 else
jclondonol 2:bef1b1c9e387 537 {
jclondonol 2:bef1b1c9e387 538 Lugar = 0;
jclondonol 2:bef1b1c9e387 539 pos = 0;
jclondonol 2:bef1b1c9e387 540 lcd.cls();
jclondonol 2:bef1b1c9e387 541 }
jclondonol 2:bef1b1c9e387 542 }
jclondonol 2:bef1b1c9e387 543 }
jclondonol 2:bef1b1c9e387 544 }
jclondonol 2:bef1b1c9e387 545 count = 0;
jclondonol 2:bef1b1c9e387 546 }
jclondonol 2:bef1b1c9e387 547 }
jclondonol 2:bef1b1c9e387 548
Jepalacioh 0:c2ed510ee88d 549
Jepalacioh 0:c2ed510ee88d 550 break;
Jepalacioh 0:c2ed510ee88d 551 }
Jepalacioh 0:c2ed510ee88d 552 }
jclondonol 2:bef1b1c9e387 553 }