{{{ /* Carlos Soto check 21/03/11 RTC DS1307 (modificación en sitio) SHT15 8 salidas 4 entradas */ //Este programa realiza una verificación del rct (real clock time), //en este caso utilizando el chip DS1307, permitiendo realizar las //operaciones permitidas, como configurar la hora, asi como //también la lectura desde el el DS1307, esta es la base del código //del proyecto HAPA, pues tenemos un control programado de riego. //La verificación se realiza mediante el puerto serial //Ademas se realiza una visualizacion de la hora actual por LCD //Se agrega la medicion de temperatura #include "Wire.h" #define DS1307_I2C_ADDRESS 0x68 //Declaracion de LCD mediante la libreria LiquidCrystal.h // include the library code: #include // initialize the library with the numbers of the interface pins LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // Convirtiendo número decimal en bcd byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); } // Convirtiendo bcd en número decimal byte bcdToDec(byte val) { return ( (val/16*10) + (val%16) ); } // Stops the DS1307, but it has the side effect of setting seconds to 0 // Probably only want to use this for testing /*void stopDs1307() { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(0); Wire.send(0x80); Wire.endTransmission(); }*/ // 1) Sets the date and time on the ds1307 // 2) Starts the clock // 3) Sets hour mode to 24 hour clock // Assumes you're passing in valid numbers void setDateDs1307(byte second, // 0-59 byte minute, // 0-59 byte hour, // 1-23 byte dayOfWeek, // 1-7 byte dayOfMonth, // 1-28/29/30/31 byte month, // 1-12 byte year) // 0-99 { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(0); Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock Wire.send(decToBcd(minute)); Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set // bit 6 (also need to change readDateDs1307) Wire.send(decToBcd(dayOfWeek)); Wire.send(decToBcd(dayOfMonth)); Wire.send(decToBcd(month)); Wire.send(decToBcd(year)); Wire.endTransmission(); } /////////////////////// //Configuracion de las entradas //para la interface, // Boton01 (visualizacion) //Boton02,Boton03 (Modificacion) // Boton04 (set) //Manejo de Entradas const int inPin01 = 4; const int inPin02 = 5; const int inPin03 = 6; const int inPin04 = 7; //Variables de control de botones int boton01=0; int boton02=0; int boton03=0; int boton04=0; //Retardo int dd2=500; //Modificacion de Hora float Horatemp=12; int boton02temp; int boton03temp; ////////////////////////////////////// //Configuracion del expansor int dd=50; #define expander B0100000 // Direccion del expansor alpha-num // 0 1 0 0 A2 A1 A0 // 0 1 0 0 0 0 0 // Note that the R/W bit is not part of this address. ///////////////////////////////////////// // Pegando el expansor void expanderWrite(byte _data ) { Wire.beginTransmission(expander); Wire.send(_data); Wire.endTransmission(); } // Gets the date and time from the ds1307 void getDateDs1307(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year) { // Reset the register pointer Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(0); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 7); // A few of these need masks because certain bits are control bits *second = bcdToDec(Wire.receive() & 0x7f); *minute = bcdToDec(Wire.receive()); *hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm *dayOfWeek = bcdToDec(Wire.receive()); *dayOfMonth = bcdToDec(Wire.receive()); *month = bcdToDec(Wire.receive()); *year = bcdToDec(Wire.receive()); } /////////////////////////////////// //Inicio Configuracion sensor SHT15 ////////////////////////////// ////////////////////////////// #define comandoTemp 0x03 //Comando para obtener la temperatura del SHT15 #define comandoHume 0x04 //Comando para obtener la humedad del SHT15 #define pinDatos 3 #define pinReloj 2 float temperatura, humedad; ///////////SHT15//////////////////////// //Funciones para la lectura del SHT15/// int leerDatos (int numBits) //Función para leer datos en forma serial. { int deci = 0; for (int i=0; i