![](/media/cache/profiles/bd1ce36d68a5c2bea97fe45863673b20.jpg.50x50_q85.jpg)
reloj con ds1307 y LCD de 20x4
Dependencies: RTC-DS1307 TextLCD mbed
Fork of Rtc_Ds1307_Sample by
main.cpp@3:fda6508b1efc, 2016-05-01 (annotated)
- Committer:
- tony63
- Date:
- Sun May 01 11:25:30 2016 +0000
- Revision:
- 3:fda6508b1efc
- Parent:
- 2:3be003301107
reloj con ds1307 y LCD de 20x4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 3:fda6508b1efc | 1 | /* |
tony63 | 3:fda6508b1efc | 2 | reloj con ds1307 para que el circuitotrabaje bien se hacen las siguientes recomendaciones |
tony63 | 3:fda6508b1efc | 3 | 1. ponerle un cristal de un reloj de buena calidad no usar el cristal originalmente instalado..retirelo |
tony63 | 3:fda6508b1efc | 4 | 2. retire las resistencias de superficie pull up que son R2 y R3 |
tony63 | 3:fda6508b1efc | 5 | 3.conforme un circuito externo con dos nuevas pull up de al menos 4.7k a una linea de alimentacion de 3,3v |
tony63 | 3:fda6508b1efc | 6 | 4 coloque diodos in4148 con los anodos a masa y cada catodo conectado a las lineas sda y scl |
tony63 | 3:fda6508b1efc | 7 | |
tony63 | 3:fda6508b1efc | 8 | si hace esto el circuito trabajara muy bien |
tony63 | 3:fda6508b1efc | 9 | antes de configurar parar el reloj y despues de configurar darle start al reloj, no lo olvide |
tony63 | 3:fda6508b1efc | 10 | |
tony63 | 3:fda6508b1efc | 11 | el reloj se configura desde la pc |
tony63 | 3:fda6508b1efc | 12 | adicionalmente al ejemplo de mbed este programa imprime en una lcd y pide el dia ya que originalmente solo se |
tony63 | 3:fda6508b1efc | 13 | ajusta a un dia domingo |
tony63 | 3:fda6508b1efc | 14 | |
tony63 | 3:fda6508b1efc | 15 | originalmente trabaja en modo 24 horas seria interesante trabajarlo a modo 12 horas haciendo uno la flag |
tony63 | 3:fda6508b1efc | 16 | bool thm = true; |
tony63 | 3:fda6508b1efc | 17 | de la libreria en la linea 64 Rtc_Ds1307,ccp |
tony63 | 3:fda6508b1efc | 18 | los registros son en bcd |
tony63 | 3:fda6508b1efc | 19 | segundos 00h |
tony63 | 3:fda6508b1efc | 20 | minutos 01h |
tony63 | 3:fda6508b1efc | 21 | horas 02h bit 6 es el modo 24/12 --0/1.. y el bit 5 es el indicador si la hora es am/pm 0/1 |
tony63 | 3:fda6508b1efc | 22 | dia 03h |
tony63 | 3:fda6508b1efc | 23 | date 04h |
tony63 | 3:fda6508b1efc | 24 | mes 05h |
tony63 | 3:fda6508b1efc | 25 | año 06h |
tony63 | 3:fda6508b1efc | 26 | control 07h |
tony63 | 3:fda6508b1efc | 27 | zona de ram 08h-3fh |
tony63 | 3:fda6508b1efc | 28 | |
tony63 | 3:fda6508b1efc | 29 | */ |
tony63 | 3:fda6508b1efc | 30 | |
leihen | 0:431183c5b136 | 31 | #include "mbed.h" |
leihen | 0:431183c5b136 | 32 | #include "Rtc_Ds1307.h" |
tony63 | 3:fda6508b1efc | 33 | #include "TextLCD.h" |
leihen | 0:431183c5b136 | 34 | |
tony63 | 3:fda6508b1efc | 35 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5, TextLCD::LCD20x4); // rs, e, d4-d7 |
leihen | 2:3be003301107 | 36 | //RtcCls rtc(p28, p27, p29, true); |
tony63 | 3:fda6508b1efc | 37 | Rtc_Ds1307 rtc(PTE0, PTE1); |
leihen | 0:431183c5b136 | 38 | |
leihen | 0:431183c5b136 | 39 | Serial pc(USBTX, USBRX, "pc"); |
leihen | 0:431183c5b136 | 40 | |
leihen | 0:431183c5b136 | 41 | char buffer[128]; |
leihen | 0:431183c5b136 | 42 | int readptr = 0; |
tony63 | 3:fda6508b1efc | 43 | int segundos =0; |
leihen | 1:6dbe51fe0737 | 44 | |
leihen | 0:431183c5b136 | 45 | int main() { |
leihen | 0:431183c5b136 | 46 | char c; |
leihen | 2:3be003301107 | 47 | Rtc_Ds1307::Time_rtc tm = {}; |
leihen | 0:431183c5b136 | 48 | |
leihen | 0:431183c5b136 | 49 | while(1) { |
leihen | 0:431183c5b136 | 50 | pc.printf("*************************************\n"); |
leihen | 0:431183c5b136 | 51 | pc.printf("* Menu for RTC Test : *\n"); |
leihen | 0:431183c5b136 | 52 | pc.printf("* read - reads the clock *\n"); |
leihen | 0:431183c5b136 | 53 | pc.printf("* start - start the clock *\n"); |
leihen | 0:431183c5b136 | 54 | pc.printf("* stop - stop the clock *\n"); |
leihen | 1:6dbe51fe0737 | 55 | pc.printf("* write - write the clock *\n"); |
leihen | 1:6dbe51fe0737 | 56 | pc.printf("* ena - enable Square wave output *\n"); |
leihen | 1:6dbe51fe0737 | 57 | pc.printf("* dis - disable square wave outp. *\n"); |
leihen | 0:431183c5b136 | 58 | pc.printf("*************************************\n"); |
leihen | 0:431183c5b136 | 59 | |
leihen | 0:431183c5b136 | 60 | while( (c = pc.getc()) != '\n') { |
leihen | 0:431183c5b136 | 61 | buffer[readptr++] = c; |
leihen | 0:431183c5b136 | 62 | } |
leihen | 0:431183c5b136 | 63 | buffer[readptr++] = 0; |
leihen | 0:431183c5b136 | 64 | if (strncmp(buffer, "read", 4) == 0) { |
leihen | 0:431183c5b136 | 65 | // perform read |
leihen | 0:431183c5b136 | 66 | pc.printf("Performing read operation\n"); |
tony63 | 3:fda6508b1efc | 67 | lop1: if (rtc.getTime(tm) ) { |
tony63 | 3:fda6508b1efc | 68 | //pc.printf("The current time is : %02d:%02d:%02d\n", tm.hour, tm.min, tm.sec); |
tony63 | 3:fda6508b1efc | 69 | //pc.printf("The current date is : %s, %02d/%02d/%04d\n", rtc.weekdayToString(tm.wday), tm.mon, tm.date, tm.year); |
tony63 | 3:fda6508b1efc | 70 | |
tony63 | 3:fda6508b1efc | 71 | lcd.cls(); |
tony63 | 3:fda6508b1efc | 72 | lcd.locate(0,0); |
tony63 | 3:fda6508b1efc | 73 | lcd.printf("%02d:%02d:%02d", tm.hour, tm.min, tm.sec); |
tony63 | 3:fda6508b1efc | 74 | lcd.locate(0,1); |
tony63 | 3:fda6508b1efc | 75 | lcd.printf("%s/%02d/%02d/%4d", rtc.weekdayToString(tm.wday), tm.date, tm.mon, tm.year); |
tony63 | 3:fda6508b1efc | 76 | wait_ms(200); |
tony63 | 3:fda6508b1efc | 77 | goto lop1; |
tony63 | 3:fda6508b1efc | 78 | |
tony63 | 3:fda6508b1efc | 79 | |
leihen | 0:431183c5b136 | 80 | } |
leihen | 0:431183c5b136 | 81 | |
leihen | 0:431183c5b136 | 82 | } |
leihen | 0:431183c5b136 | 83 | else if (strncmp(buffer, "write", 5) == 0) { |
leihen | 0:431183c5b136 | 84 | // perform write |
leihen | 1:6dbe51fe0737 | 85 | pc.printf("Enter the date (date 0..31)"); |
leihen | 1:6dbe51fe0737 | 86 | pc.scanf("%d", &tm.date); |
leihen | 1:6dbe51fe0737 | 87 | pc.printf("Enter the date (month 1..12)"); |
leihen | 1:6dbe51fe0737 | 88 | pc.scanf("%d", &tm.mon); |
leihen | 1:6dbe51fe0737 | 89 | pc.printf("Enter the date (year)"); |
leihen | 1:6dbe51fe0737 | 90 | pc.scanf("%d", &tm.year); |
leihen | 1:6dbe51fe0737 | 91 | pc.printf("Enter the time (hours 0..23)"); |
leihen | 1:6dbe51fe0737 | 92 | pc.scanf("%d", &tm.hour); |
leihen | 1:6dbe51fe0737 | 93 | pc.printf("Enter the time (minutes 0..59)"); |
leihen | 1:6dbe51fe0737 | 94 | pc.scanf("%d", &tm.min); |
leihen | 1:6dbe51fe0737 | 95 | pc.printf("Enter the time (seconds 0..59)"); |
leihen | 1:6dbe51fe0737 | 96 | pc.scanf("%d", &tm.sec); |
tony63 | 3:fda6508b1efc | 97 | pc.printf("Enter the day (sunday=1)"); |
tony63 | 3:fda6508b1efc | 98 | pc.scanf("%d", &tm.wday); |
leihen | 0:431183c5b136 | 99 | pc.printf("Performing write operation\n"); |
leihen | 1:6dbe51fe0737 | 100 | |
leihen | 1:6dbe51fe0737 | 101 | while(pc.readable()) |
leihen | 1:6dbe51fe0737 | 102 | pc.getc(); |
leihen | 1:6dbe51fe0737 | 103 | rtc.setTime(tm, false, false); |
leihen | 0:431183c5b136 | 104 | } |
leihen | 0:431183c5b136 | 105 | else if (strncmp(buffer, "start", 5) == 0) { |
leihen | 0:431183c5b136 | 106 | // start |
leihen | 0:431183c5b136 | 107 | pc.printf("Performing start operation\n"); |
leihen | 1:6dbe51fe0737 | 108 | rtc.startClock(); |
leihen | 0:431183c5b136 | 109 | } |
leihen | 0:431183c5b136 | 110 | else if (strncmp(buffer, "stop", 4) == 0) { |
leihen | 0:431183c5b136 | 111 | // stop |
leihen | 0:431183c5b136 | 112 | pc.printf("Performing stop operation\n"); |
leihen | 1:6dbe51fe0737 | 113 | rtc.stopClock(); |
leihen | 1:6dbe51fe0737 | 114 | } |
leihen | 1:6dbe51fe0737 | 115 | else if (strncmp(buffer, "ena", 3) == 0) { |
leihen | 1:6dbe51fe0737 | 116 | int rs; |
leihen | 1:6dbe51fe0737 | 117 | pc.printf("Please specify the frequency : [0 = 1Hz, 1 = 4.096kHz, 2 = 8.192kHz, 3 = 32.768kHz] "); |
leihen | 1:6dbe51fe0737 | 118 | scanf("%d", &rs); |
leihen | 1:6dbe51fe0737 | 119 | pc.printf("Enabling the output with %d option\n", rs); |
leihen | 2:3be003301107 | 120 | rtc.setSquareWaveOutput(true, (Rtc_Ds1307::SqwRateSelect_t)rs); |
leihen | 1:6dbe51fe0737 | 121 | } |
leihen | 1:6dbe51fe0737 | 122 | else if (strncmp(buffer, "dis", 3) == 0) { |
leihen | 1:6dbe51fe0737 | 123 | pc.printf("Disableing square wave output\n"); |
leihen | 2:3be003301107 | 124 | rtc.setSquareWaveOutput(false, Rtc_Ds1307::RS1Hz); |
leihen | 0:431183c5b136 | 125 | } |
leihen | 0:431183c5b136 | 126 | else { |
leihen | 0:431183c5b136 | 127 | pc.printf("syntax error\n"); |
leihen | 0:431183c5b136 | 128 | } |
leihen | 0:431183c5b136 | 129 | readptr = 0; |
leihen | 0:431183c5b136 | 130 | pc.printf("\n\n\n"); |
leihen | 0:431183c5b136 | 131 | } |
leihen | 0:431183c5b136 | 132 | } |