por medio del modulo i2c se realizo un reloj con alarma al cual se el configura la hora actual y la alarma por medio de botones y un encoder.
Dependencies: Debounced QEI RTC-DS1307 TextLCD mbed
main.cpp
- Committer:
- lopjohn_26
- Date:
- 2014-05-06
- Revision:
- 0:98d22ab8a13c
File content as of revision 0:98d22ab8a13c:
#include "mbed.h" #include "Rtc_Ds1307.h" #include "TextLCD.h" #include "DebouncedIn.h" #include "QEI.h" //RtcCls rtc(p28, p27, p29, true); Rtc_Ds1307 rtc(PTC9, PTC8); TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); //Puertos LCD rs, e, d4, d5, d6, d7 PwmOut sound(PTA12); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); int a, kp, sp, kd, ki, valor; int hr, mn, se, di, me, an, ho; int loop = 10; int encod(int); int encod(){ sp=0; QEI Encoder (PTA1, PTA2, NC, 624); DebouncedIn bot1(PTC12); //cambiar la posición (CONECTO ESTA ENTRADA A LA ULTIMA SALIDA DEL ENCONDER, ASI SE UTILIZARA EL BOTON DEL ENCODER) DebouncedIn bot4(PTC17); int C1=0x0E; //int C4=0x0C; led1=led2=1; lcd.writeCommand(C1); //comando para mostrar el cursor en el LCD lcd.locate(0,0); // Ubica e imprime nombre de los parámetros en del PID en la pantalla LCD lcd.printf("dato="); //Inicio del ciclo while(1) { if (bot1.falling()) { //----------------- Aumenta de posición el cursor a la primera línea de menu sound=1.0f; wait(0.1); sound=0; break; } valor = Encoder.getPulses(); //------------- Asigna el valor de los pulsos del encoder a una variable llamada "valor" sp = sp + valor; //------------- Asigna el valor del encoder al parámetro sp y tiene en cuenta el valor anterior Encoder.reset(); //------------- Resetea el valor del encoder if (sp<0){ sp=0; //------------- No se admite valores negativos } lcd.locate(4,0); //------------- Ubica e imprime el parámetro "sp" en la pantalla LCD lcd.printf("= ",sp); lcd.locate(5,0); lcd.printf("%i",sp); wait(0.15); } return sp; } int main() { inicio: DebouncedIn bot1(PTC10); DebouncedIn bot2(PTC11); DebouncedIn bot3(PTC16); DebouncedIn bot4(PTC17); Rtc_Ds1307::Time_rtc tm = {}; while(1) { lcd.printf("configuracion reloj y alarma \n"); wait(1.5); lcd.cls(); lcd.printf("oprima uno de los botones \n"); wait(1.5); lcd.cls(); lcd.printf("a: configurar el reloj\n"); wait(2); lcd.cls(); lcd.printf("b: configurar laalarma\n"); wait(2); lcd.cls(); lcd.printf("c: iniciar el reloj\n"); wait(2); lcd.cls(); lcd.printf("d: salir de configuracion \n"); wait(2); lcd.cls(); lcd.printf("digite la opcion elegida\n"); wait(5); lcd.cls(); if (bot1.falling()) { lcd.cls(); lcd.printf("ingrese hora\n"); wait(1); lcd.cls(); tm.hour = encod(); lcd.cls(); lcd.printf("ingrese minutos\n"); wait(1); lcd.cls(); tm.min = encod(); lcd.cls(); lcd.printf("ingrese segundos\n"); wait(1); lcd.cls(); tm.sec = encod(); lcd.cls(); lcd.printf("ingrese ano\n"); wait(1); lcd.cls(); tm.year = encod(); lcd.cls(); lcd.printf("ingrese mes\n"); wait(1); lcd.cls(); tm.mon = encod(); lcd.cls(); lcd.printf("ingrese dia\n"); wait(1); lcd.cls(); tm.date = encod(); lcd.cls(); rtc.setTime(tm, false, false); } if (bot2.falling()) { lcd.cls(); lcd.printf("ingrese hora\n"); wait(1); lcd.cls(); hr = encod(); lcd.cls(); lcd.printf("ingrese minutos\n"); wait(1); lcd.cls(); mn = encod(); lcd.cls(); lcd.printf("ingrese segundos\n"); wait(1); lcd.cls(); se = encod(); lcd.cls(); lcd.printf("ingrese ano\n"); wait(1); lcd.cls(); an = encod(); lcd.cls(); lcd.printf("ingrese mes\n"); wait(1); lcd.cls(); me = encod(); lcd.cls(); lcd.printf("ingrese dia\n"); wait(1); lcd.cls(); di= encod(); lcd.cls(); } if (bot3.falling()) { // start lcd.printf("realizando inicializacion\n"); wait(3); lcd.cls(); rtc.startClock(); } if (bot4.falling()) { //exit led1=led2=led3=1; //------------- Flash para salir del bucle wait(0.25); led1=led2=led3=0; lcd.printf("saliendo del menu\n"); wait(1.5); lcd.cls(); break; } } //------------------------------sonido alarma----------------------------------------------------------------------------------------------- while (loop>0){ // Loop continously if (rtc.getTime(tm) ) { lcd.locate(0,0); lcd.printf("%02d:%02d:%02d\n", tm.hour, tm.min, tm.sec); lcd.printf("%02d:%02d:%02d\n", hr, mn,se); wait(0.1); lcd.cls(); } if ((tm.hour==hr) && (tm.min==mn) && (tm.sec==se)){ while (1){ sound=1.0f; wait(0.3); sound=0; wait(0.2); if(bot1.falling()){ se= se+20; if(se>=60){ mn++; se=se-60; } if(mn>=60){ hr++; mn=mn-60; } break; } if(bot2.falling()){ break; } } } if(bot1.falling()){ lcd.printf("regresando a configuracion\n"); break; } } goto inicio; }