Bienvenido a los foros de FT81x Manía. Te invitamos a regístrate totalmente gratis. Disfruta de tu experiencia con un grandes amigos y Staff.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Thread Contributor: lightcalamarCodigo Actividad BUS I2C

#1
0
Aquí dejo este código que uso.
Tendrán que modificar las direcciones de Hexadecimal a decimal del componente.


 void Actividad() {

  do {
   
 GD.ClearColorRGB(DKTEAL2);
 GD.ColorRGB(WHITE);
 GD.Clear(1, 1, 1);
 GD.get_inputs();    

 GD.Begin(LINES);
 GD.SaveContext();
 GD.Vertex2ii(0, 70, 20, 0);         // DOS LINEAS DEBAJO DEL MENU SUPERIOR
 GD.Vertex2ii(480, 70, 20, 0);
 GD.VertexTranslateX(16*320); GD.Vertex2ii(480, 70, 20, 0);
 GD.VertexTranslateX(16*320); GD.Vertex2ii(0, 70, 20, 0);
 GD.RestoreContext();

     
 GD.SaveContext();
 GD.Vertex2ii(0, 65, 20, 0);
 GD.Vertex2ii(480, 65, 20, 0);
 GD.VertexTranslateX(16*320); GD.Vertex2ii(480, 65, 20, 0);
 GD.VertexTranslateX(16*320); GD.Vertex2ii(0, 65, 20, 0);
 GD.RestoreContext();

 
 GD.SaveContext();
 GD.Vertex2ii(0, 478, 20, 0);        // LINEA INFERIOR DE LA PANTALLA
 GD.Vertex2ii(478, 478, 20, 0);
 GD.VertexTranslateX(16*320); GD.Vertex2ii(0, 478, 20, 0);
 GD.VertexTranslateX(16*320); GD.Vertex2ii(478, 478, 20, 0);    
 GD.RestoreContext();

 
 GD.SaveContext();
 GD.Vertex2ii(0, 480, 20, 0);        // LINEA LATERAL IZQUIERDA
 GD.Vertex2ii(0, 65, 20, 0);
 GD.RestoreContext();
     
                                         // LINEA LATERAL DERECHA
 GD.SaveContext();
 GD.VertexTranslateX(16*318); GD.Vertex2ii(480, 65, 20, 0);    
 GD.VertexTranslateX(8*636);  GD.Vertex2ii(480, 480, 20, 0);                    
 GD.RestoreContext();      
       
 GD.End();

 GD.Tag(100);
 GD.cmd_fgcolor(0x21610B);   // COLOR VERDESM
 GD.ColorRGB(WHITE);
 GD.cmd_romfont(1, 32);
 GD.cmd_button(0, 0, 800, 62, 1, 0, "Analizador Sistema BUS I2C");
    if (GD.inputs.tag==100) {
 GD.ColorRGB(0xff8000);
 GD.cmd_fgcolor(0x000000);
    GD.play(NOTCH);
      delay(150); espera(); PIx=0, velP=VX, AvanceC=1, MenuInicio(); }
   
 GD.ColorRGB(WHITE);

 blockText1(30, 125, 31,  "Radio");
 blockText1(30, 170, 31, "EEPROM");
 blockText1(30, 215, 31, "DS3231");
 blockText1(30, 260, 31, "BMP085");
 blockText1(30, 305, 31, "24LC32");
 

 GD.cmd_text(135, 90, 29, 0, "Componentes I2C, direcciones y estados actuales");

 GD.ColorRGB(TEAL);
   
 // ==========================================================================
 // BAROMETRO 0x77
 Wire.requestFrom(0x77, 1);    // request 6 bytes from slave device #2
 while(Wire.available())       // slave may send less than requested
  {
   char baro [3]; // = Wire.read();      // receive a byte as character
   sprintf(baro, "%2d-%2d-%2d", Wire.read() );
   blockText1(370, 260, 31, baro );  // SIGNIFICA RADIO POR EJEMPLO OK
  }
 delay(200);  

// =======================================================================
 // DS1307 ( RELOJ ) 0x68
 Wire.requestFrom(0x68, 1);      // request 6 bytes from slave device #2
 while(Wire.available())         // slave may send less than requested
{
 char clore [3];                 //  Wire.read(); // receive a byte as character
 sprintf(clore, "%2d-%2d-%2d", Wire.read() );
 blockText1(370, 215, 31, clore );  // SIGNIFICA RADIO POR EJEMPLO OK
  }
 delay(200);

 // =======================================================================
 // RADIO SI4703 0x10
 Wire.requestFrom(0x10, 1);      // request 6 bytes from slave device #2
 while(Wire.available())         // slave may send less than requested
 {
 char rafm [3];                 //  Wire.read(); // receive a byte as character
 sprintf(rafm, "%2d-%2d-%2d", Wire.read() );
 blockText1(370, 125, 31, rafm );  // SIGNIFICA RADIO POR EJEMPLO OK
  }
 delay(200);

 // --------------------------
 // EEPROM MODULO DS1307 0x57
 // --------------------------
 Wire.requestFrom(0x57, 1);      // request 6 bytes from slave device #2
 while(Wire.available())         // slave may send less than requested
  {
 char memo [3];                              //  Wire.read();
 sprintf(memo, "%2d-%2d-%2d", Wire.read() );
 GD.cmd_text(370, 170, 31, 0, memo );        // SIGNIFICA RADIO POR EJEMPLO OK
}

 // --------------------------
 // EEPROM 24LC32 0x50
 // --------------------------
 Wire.requestFrom(0x50, 1);      // request 6 bytes from slave device #2
 while(Wire.available())         // slave may send less than requested
  {
 char lcmem [3];                              //  Wire.read();
 sprintf(lcmem, "%2d-%2d-%2d", Wire.read() );
 GD.cmd_text(370, 305, 31, 0, lcmem );        // SIGNIFICA RADIO POR EJEMPLO OK
}

 delay(200);
 
 GD.ColorRGB(YELLOW);
 char bus  [10];
 sprintf(bus,"0x%02x", 16 );
 blockText1(240, 125, 31, bus );        //  RADIO  0x10
 char bus2 [10];
 sprintf(bus2,"0x%02x",87  );
 blockText1(240, 170, 31, bus2 );       //  EEPROM  0x57
 char bus3 [10];
 sprintf(bus3,"0x%02x",104  );          //  RELOJ DS1307  0x68
 blockText1(240, 215, 31, bus3 );
 char bus4 [10];
 sprintf(bus4,"0x%02x",119  );
 blockText1(240, 260, 31, bus4 );       //  BAROMETRO  0x77  
 char bus5 [10];
 sprintf(bus5,"0x%02x",80  );
 blockText1(240, 305, 31, bus5 );       //  EEPROM 24LC32 0x50

 GD.VertexTranslateX(16*245);
 GD.Vertex2ii(500, 140, 4, 1);
 GD.Vertex2ii(500, 185, 4, 1);
 GD.Vertex2ii(500, 230, 4, 1);
 GD.Vertex2ii(500, 275, 4, 1);
 GD.Vertex2ii(500, 320, 4, 1);    
 GD.swap();
  }  
 while(1);

}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)