#include <16f877a.h>
#fuses XT,NOWDT,NOPROTECT,NODEBUG,NOBROWNOUT,NOWRT,NOLVP,PUT
#use delay(clock=4000000)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3)
#define LCD_DB4 PIN_B4 //Configuramos pines...
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_B6
#define LCD_DB7 PIN_B7
#define LCD_E PIN_B0
#define LCD_RS PIN_B1
#define LCD_RW PIN_B2 //...para el LCD
//#define DAL_SCL PIN_A0
//#define DAL_SDA PIN_A1
#include <string.h>
#include <flex_lcd.0.c> //Libreria manejo LCD
#include <_ds1307.c> //Libreria manejo RTC
//#include <ds1621.c> //Libreria sensor Temp
//FUNCIONES ESCRITURA Y LECTURA EEPROM INTERNA
void write_string_eeprom(int address,char *data){
while(*data!=0){
write_eeprom(address++,*data);
data++;
}
write_eeprom(address,0);
}
void read_string_eeprom(int address,char *sl){
sl--;
do{
sl++;
*sl=read_eeprom(address++);
}
while(*sl!=0);
}
byte hr,min,sec,day,month,yr,dow;
char sdow[11];
//byte value;
char ValoresLeidos[65];
void main(){
char alarmas[65];
char alarma1[]="0830";
char alarma2[]="0900";
char alarma3[]="0925";
char alarma4[]="1000";
char alarma5[]="1020";
char alarma6[]="1030";
char alarma7[]="1115";
char alarma8[]="1135";
char alarma9[]="1200";
char alarma10[]="1230";
char alarma11[]="1245";
char alarma12[]="1315";
char alarma13[]="1430";
//char alarma14[]="1530";
//char alarma15[]="1630";
char *leido=alarmas;
//ESCRITURA ALARMAS
write_string_eeprom(0x00,alarma1);
write_string_eeprom(0x05,alarma2);
write_string_eeprom(0x0A,alarma3);
write_string_eeprom(0x0F,alarma4);
write_string_eeprom(0x14,alarma5);
write_string_eeprom(0x19,alarma6);
write_string_eeprom(0x1E,alarma7);
write_string_eeprom(0x23,alarma8);
write_string_eeprom(0x28,alarma9);
write_string_eeprom(0x2D,alarma10);
write_string_eeprom(0x3D,alarma11);
write_string_eeprom(0x44,alarma12);
write_string_eeprom(0x4B,alarma13);
//write_string_eeprom(0x52,alarma14);
//write_string_eeprom(0x59,alarma15);
//INICIALIZA DS1307 Y LCD
lcd_init();
ds1307_init(DS1307_ALL_DISABLED);
ds1307_set_date_time(11,2,10,3,14,30,0);
//LEE FECHA Y HORA ACTUAL DS1307
ds1307_get_day_of_week((char*) sdow);
ds1307_get_date(day,month,yr,dow);
ds1307_get_time(hr,min,sec);
printf(lcd_putc,"\f%s %02u-%02u-%02u",sdow,day,month,yr);
printf(lcd_putc,"\n%02u:%02u:%02u",hr,min,sec);
//LECTURA ALARMAS/DS1307 Y COMPARACION
sprintf(ValoresLeidos,"%02u%02u",hr,min);
read_string_eeprom(0x00,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x05,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x0A,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x0F,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x14,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x19,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x1E,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x23,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x28,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x2D,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x3D,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x44,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
read_string_eeprom(0x4B,leido);
if(strcmp(ValoresLeidos,leido)==0)
output_high(PIN_C0);
else
output_low(PIN_C0);
}