Autor Tema: Problema con programacion de la alarma  (Leído 7097 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: Problema con programacion de la alarma
« Respuesta #30 en: 27 de Febrero de 2010, 14:12:23 »
Formar el string de los datos recibidos es sencillo:


Código: [Seleccionar]
char ValoresLeidos[5];

sprintf(ValoresLeidos,"02%u02"u",hour, min);

Con eso ya deberías de tener en ValoresLeidos un string idéntico al guardado en eeprom. El tema de los if puedes buscar en la ayuda de CCS, no recuerdo que devuelve en cada caso la comparación.

En estos casos ir haciendo un debug en MPLab o en proteus ayuda a entender que se está haciendo mal, se van aprendiendo detalles, y uno se vuelve más independiente  ;-)

Saludos!
No contesto mensajes privados, las consultas en el foro

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Problema con programacion de la alarma
« Respuesta #31 en: 27 de Febrero de 2010, 15:47:03 »
Gracias de nuevo Suky ahora lo veo mas facil, referente al debug lo hare como dices e intentare entenderlo.

 Miquel_S
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Problema con programacion de la alarma
« Respuesta #32 en: 27 de Febrero de 2010, 21:11:14 »
Al fin creo tenerlo funcionando  :-/ :-/

Pero..... , en la simulacion el reloj que visualizo en el lcd no anda,  os dejo el codigo y el esquema en proteus por si alguien sabe el porque, es el unico problema lo demas funciona bien.

Código: CSS
  1. #include <16f877a.h>
  2. #fuses XT,NOWDT,NOPROTECT,NODEBUG,NOBROWNOUT,NOWRT,NOLVP,PUT
  3. #use delay(clock=4000000)
  4. #use i2c(Master, sda=PIN_C4, scl=PIN_C3)
  5. #define LCD_DB4 PIN_B4                    //Configuramos pines...
  6. #define LCD_DB5 PIN_B5
  7. #define LCD_DB6 PIN_B6
  8. #define LCD_DB7 PIN_B7
  9. #define LCD_E   PIN_B0
  10. #define LCD_RS  PIN_B1
  11. #define LCD_RW  PIN_B2                    //...para el LCD
  12.  
  13. //#define DAL_SCL   PIN_A0
  14. //#define DAL_SDA   PIN_A1
  15.  
  16. #include <string.h>
  17. #include <flex_lcd.0.c>               //Libreria manejo LCD
  18. #include <_ds1307.c>             //Libreria manejo RTC
  19. //#include <ds1621.c>              //Libreria sensor Temp
  20.  
  21.  
  22.  //FUNCIONES ESCRITURA Y LECTURA EEPROM INTERNA
  23.  void write_string_eeprom(int address,char *data){
  24.    while(*data!=0){
  25.       write_eeprom(address++,*data);
  26.       data++;
  27.    }
  28.    write_eeprom(address,0);
  29. }
  30.  
  31. void read_string_eeprom(int address,char *sl){
  32.      sl--;
  33.    do{
  34.       sl++;
  35.       *sl=read_eeprom(address++);
  36.    }
  37.    while(*sl!=0);
  38. }
  39.  
  40.  byte hr,min,sec,day,month,yr,dow;
  41.  char sdow[11];
  42.  //byte value;
  43.  char ValoresLeidos[65];
  44.  
  45.  void main(){
  46.    char alarmas[65];
  47.    char alarma1[]="0830";
  48.    char alarma2[]="0900";
  49.    char alarma3[]="0925";
  50.    char alarma4[]="1000";
  51.    char alarma5[]="1020";
  52.    char alarma6[]="1030";
  53.    char alarma7[]="1115";
  54.    char alarma8[]="1135";
  55.    char alarma9[]="1200";
  56.    char alarma10[]="1230";
  57.    char alarma11[]="1245";
  58.    char alarma12[]="1315";
  59.    char alarma13[]="1430";
  60.    //char alarma14[]="1530";
  61.    //char alarma15[]="1630";
  62.    char *leido=alarmas;
  63.  
  64.    
  65.  //ESCRITURA ALARMAS
  66.    write_string_eeprom(0x00,alarma1);
  67.    write_string_eeprom(0x05,alarma2);
  68.    write_string_eeprom(0x0A,alarma3);
  69.    write_string_eeprom(0x0F,alarma4);
  70.    write_string_eeprom(0x14,alarma5);
  71.    write_string_eeprom(0x19,alarma6);
  72.    write_string_eeprom(0x1E,alarma7);
  73.    write_string_eeprom(0x23,alarma8);
  74.    write_string_eeprom(0x28,alarma9);
  75.    write_string_eeprom(0x2D,alarma10);
  76.    write_string_eeprom(0x3D,alarma11);
  77.    write_string_eeprom(0x44,alarma12);
  78.    write_string_eeprom(0x4B,alarma13);
  79.    //write_string_eeprom(0x52,alarma14);
  80.    //write_string_eeprom(0x59,alarma15);  
  81.    
  82.  //INICIALIZA DS1307 Y LCD
  83.    lcd_init();
  84.    ds1307_init(DS1307_ALL_DISABLED);
  85.    ds1307_set_date_time(11,2,10,3,14,30,0);
  86.    
  87.  //LEE FECHA Y HORA ACTUAL DS1307
  88.    ds1307_get_day_of_week((char*) sdow);
  89.    ds1307_get_date(day,month,yr,dow);
  90.    ds1307_get_time(hr,min,sec);
  91.    printf(lcd_putc,"\f%s  %02u-%02u-%02u",sdow,day,month,yr);
  92.    printf(lcd_putc,"\n%02u:%02u:%02u",hr,min,sec);
  93.    
  94.  //LECTURA ALARMAS/DS1307 Y COMPARACION
  95.    sprintf(ValoresLeidos,"%02u%02u",hr,min);
  96.    read_string_eeprom(0x00,leido);
  97.       if(strcmp(ValoresLeidos,leido)==0)
  98.          output_high(PIN_C0);
  99.       else
  100.          output_low(PIN_C0);
  101.    read_string_eeprom(0x05,leido);
  102.       if(strcmp(ValoresLeidos,leido)==0)
  103.          output_high(PIN_C0);
  104.       else
  105.          output_low(PIN_C0);
  106.    read_string_eeprom(0x0A,leido);
  107.       if(strcmp(ValoresLeidos,leido)==0)
  108.          output_high(PIN_C0);
  109.       else
  110.          output_low(PIN_C0);
  111.    read_string_eeprom(0x0F,leido);
  112.       if(strcmp(ValoresLeidos,leido)==0)
  113.          output_high(PIN_C0);
  114.       else
  115.          output_low(PIN_C0);
  116.    read_string_eeprom(0x14,leido);
  117.       if(strcmp(ValoresLeidos,leido)==0)
  118.          output_high(PIN_C0);
  119.       else
  120.          output_low(PIN_C0);
  121.    read_string_eeprom(0x19,leido);
  122.       if(strcmp(ValoresLeidos,leido)==0)
  123.          output_high(PIN_C0);
  124.       else
  125.          output_low(PIN_C0);
  126.    read_string_eeprom(0x1E,leido);
  127.       if(strcmp(ValoresLeidos,leido)==0)
  128.          output_high(PIN_C0);
  129.       else
  130.          output_low(PIN_C0);
  131.    read_string_eeprom(0x23,leido);
  132.       if(strcmp(ValoresLeidos,leido)==0)
  133.          output_high(PIN_C0);
  134.       else
  135.          output_low(PIN_C0);
  136.    read_string_eeprom(0x28,leido);
  137.       if(strcmp(ValoresLeidos,leido)==0)
  138.          output_high(PIN_C0);
  139.       else
  140.          output_low(PIN_C0);
  141.    read_string_eeprom(0x2D,leido);
  142.       if(strcmp(ValoresLeidos,leido)==0)
  143.          output_high(PIN_C0);
  144.       else
  145.          output_low(PIN_C0);
  146.    read_string_eeprom(0x3D,leido);
  147.       if(strcmp(ValoresLeidos,leido)==0)
  148.          output_high(PIN_C0);
  149.       else
  150.          output_low(PIN_C0);
  151.    read_string_eeprom(0x44,leido);
  152.       if(strcmp(ValoresLeidos,leido)==0)
  153.         output_high(PIN_C0);
  154.       else
  155.          output_low(PIN_C0);
  156.    read_string_eeprom(0x4B,leido);
  157.       if(strcmp(ValoresLeidos,leido)==0)
  158.          output_high(PIN_C0);
  159.       else
  160.          output_low(PIN_C0);      
  161.  }

He quitado dos alarmas y el sensor de temperatura por falta de ram.

 Gracias por vuestra ayuda y a por otro proyecto.

 Miquel_S
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Problema con programacion de la alarma
« Respuesta #33 en: 27 de Febrero de 2010, 21:20:19 »
Perdon me deje el esquema  :-/  :-/

 Miquel_S
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: Problema con programacion de la alarma
« Respuesta #34 en: 27 de Febrero de 2010, 22:03:32 »
Me parece que lo único que falta es un while después de setear todo  ;-)


Saludos!
No contesto mensajes privados, las consultas en el foro

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Problema con programacion de la alarma
« Respuesta #35 en: 28 de Febrero de 2010, 10:10:54 »
Gracias Suky por tu ayuda,  pense con ello mas tarde,  pero ya estaba en la cama  :sleepy:

 Saludos
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Problema con programacion de la alarma
« Respuesta #36 en: 21 de Marzo de 2010, 18:19:27 »
 :5] Todavia sigo liado y no me funciona y no encuentro el fallo, he probado con diferentes librerias y hace lo mismo.
       Os dejo el codigo de la parte del reloj por si me podeis decir el fallo:

 
Código: CSS
  1. #include <16f877a.h>
  2. #fuses HS,NOWDT,NOPROTECT,NODEBUG,NOBROWNOUT,NOWRT,NOLVP,PUT
  3. #use delay(clock=20000000)
  4. #define RTC_SDA  PIN_C4
  5. #define RTC_SCL  PIN_C3  
  6. #define use_portb_lcd TRUE
  7. #include <LCD.c>            
  8. #include <DS_1307.c>          
  9.  
  10. byte hr,min,sec,day,mth,year,dow;
  11. //char sdow[11];
  12.  
  13.  void main()
  14.  {
  15.  ds1307_init();
  16.    ds1307_set_date_time(21,3,10,2,18,00,0);
  17.    //ds1307_get_day_of_week((char*) sdow);
  18.    ds1307_get_date(day,mth,year,dow);
  19.    ds1307_get_time(hr,min,sec);
  20.    
  21.  lcd_init();
  22.    printf(lcd_putc,"Reloj ds1307");
  23.    printf(lcd_putc,"\nMiquel_S 2010");
  24.    delay_ms(1500);
  25.    lcd_putc("\f");
  26.    printf(lcd_putc,"%02u   %02u-%02u-%02u",dow,day,mth,year);
  27.    printf(lcd_putc,"\n%02u:%02u:%02u",hr,min,sec);
  28.  }

 Libreria ds_1307
Código: CSS
  1. ////////////////////////////////////////////////////////////////////////////////
  2. ///                               DS1307.C                                   ///
  3. ///                     Driver for Real Time Clock                           ///
  4. ///                                                                          ///
  5. /// ds1307_init() - Enable oscillator without clearing the seconds register -///
  6. ///                 used when PIC loses power and DS1307 run from 3V BAT     ///
  7. ///               - Disable squarewave output                                ///
  8. ///                                                                          ///
  9. /// ds1307_set_date_time(day,mth,year,dow,hour,min,sec)  Set the date/time   ///
  10. ///                                                                          ///
  11. /// ds1307_get_date(day,mth,year,dow)               Get the date             ///
  12. ///                                                                          ///
  13. /// ds1307_get_time(hr,min,sec)                     Get the time             ///
  14. ///                                                                          ///
  15. ////////////////////////////////////////////////////////////////////////////////
  16.  
  17. #define RTC_SDA  PIN_C4
  18. #define RTC_SCL  PIN_C3
  19.  
  20. #use i2c(master, sda=RTC_SDA, scl=RTC_SCL)
  21.  
  22. BYTE bin2bcd(BYTE binary_value);
  23. BYTE bcd2bin(BYTE bcd_value);
  24.  
  25. void ds1307_init(void)
  26. {
  27.    BYTE seconds = 0;
  28.  
  29.    i2c_start();
  30.    i2c_write(0xD0);      // WR to RTC
  31.    i2c_write(0x00);      // REG 0
  32.    i2c_start();
  33.    i2c_write(0xD1);      // RD from RTC
  34.    seconds = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307
  35.    i2c_stop();
  36.    seconds &= 0x7F;
  37.  
  38.    delay_us(3);
  39.  
  40.    i2c_start();
  41.    i2c_write(0xD0);      // WR to RTC
  42.    i2c_write(0x00);      // REG 0
  43.    i2c_write(bin2bcd(seconds));     // Start oscillator with current "seconds value
  44.   i2c_start();
  45.   i2c_write(0xD0);      // WR to RTC
  46.   i2c_write(0x07);      // Control Register
  47.   i2c_write(0x80);     // Disable squarewave output pin
  48.   i2c_stop();
  49.  
  50. }
  51.  
  52. void ds1307_set_date_time(BYTE day, BYTE mth, BYTE year, BYTE dow, BYTE hr, BYTE min, BYTE sec)
  53. {
  54.  sec &= 0x7F;
  55.  hr &= 0x3F;
  56.  
  57.  i2c_start();
  58.  i2c_write(0xD0);            // I2C write address
  59.  i2c_write(0x00);            // Start at REG 0 - Seconds
  60.  i2c_write(bin2bcd(sec));      // REG 0
  61.  i2c_write(bin2bcd(min));      // REG 1
  62.  i2c_write(bin2bcd(hr));      // REG 2
  63.  i2c_write(bin2bcd(dow));      // REG 3
  64.  i2c_write(bin2bcd(day));      // REG 4
  65.  i2c_write(bin2bcd(mth));      // REG 5
  66.  i2c_write(bin2bcd(year));      // REG 6
  67.  i2c_write(0x80);            // REG 7 - Disable squarewave output pin
  68.  i2c_stop();
  69. }
  70.  
  71. void ds1307_get_date(BYTE &day, BYTE &mth, BYTE &year, BYTE &dow)
  72. {
  73.  i2c_start();
  74.  i2c_write(0xD0);
  75.  i2c_write(0x03);            // Start at REG 3 - Day of week
  76.  i2c_start();
  77.  i2c_write(0xD1);
  78.  dow  = bcd2bin(i2c_read() & 0x7f);   // REG 3
  79.  day  = bcd2bin(i2c_read() & 0x3f);   // REG 4
  80.  mth  = bcd2bin(i2c_read() & 0x1f);   // REG 5
  81.  year = bcd2bin(i2c_read(0));            // REG 6
  82.  i2c_stop();
  83. }
  84.  
  85. void ds1307_get_time(BYTE &hr, BYTE &min, BYTE &sec)
  86. {
  87.  i2c_start();
  88.  i2c_write(0xD0);
  89.  i2c_write(0x00);            // Start at REG 0 - Seconds
  90.  i2c_start();
  91.  i2c_write(0xD1);
  92.  sec = bcd2bin(i2c_read() & 0x7f);
  93.  min = bcd2bin(i2c_read() & 0x7f);
  94.  hr  = bcd2bin(i2c_read(0) & 0x3f);
  95.  i2c_stop();
  96.  
  97. }
  98.  
  99. BYTE bin2bcd(BYTE binary_value)
  100. {
  101.  BYTE temp;
  102.  BYTE retval;
  103.  
  104.  temp = binary_value;
  105.  retval = 0;
  106.  
  107.  while(1)
  108.  {
  109.    // Get the tens digit by doing multiple subtraction
  110.    // of 10 from the binary value.
  111.    if(temp >= 10)
  112.    {
  113.      temp -= 10;
  114.      retval += 0x10;
  115.    }
  116.    else // Get the ones digit by adding the remainder.
  117.    {
  118.      retval += temp;
  119.      break;
  120.    }
  121.  }
  122.  
  123.  return(retval);
  124. }
  125.  
  126.  
  127. // Input range - 00 to 99.
  128. BYTE bcd2bin(BYTE bcd_value)
  129. {
  130.  BYTE temp;
  131.  
  132.  temp = bcd_value;
  133.  // Shifting upper digit right by 1 is same as multiplying by 8.
  134.  temp >>= 1;
  135.  // Isolate the bits for the upper digit.
  136.  temp &= 0x78;
  137.  
  138.  // Now return: (Tens * 8) + (Tens * 2) + Ones
  139.  
  140.  return(temp + (temp >> 2) + (bcd_value & 0x0f));
  141. }

 Os dejo una foto.

 Saludos y Gracias

 Miquel_S
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Problema con programacion de la alarma
« Respuesta #37 en: 12 de Mayo de 2010, 17:43:36 »
 :-/ :-/ :-/ :-/ :-/ :-/

Al fin os lo dejo funcionando al 100%

Miquel_S

Saludos
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.