Forum: Compiler & IDEs i2c-eeprom


von ROB (Gast)


Lesenswert?

Hallo.

Ich habe ein kleines Problem

Ich möchte eine Variable vom Typ long double in
4 Bytes zerlegen, im I2C EEPROM ablegen,auslesen und
am Display anzeigen.

Wie eine 2-dimensionele array ?

Wie kann ich dass tunn ?

Gr,

Rob

von Karsten Brandt (Gast)


Lesenswert?

Hello Rob,

welchen Datentyp soll Deine Variable denn nun haben?
long oder double?
Oder gibt es den Datentyp long double?
Wenn ja, welche Länge (in Bytes) hat dieser?

Ich gehe mal von einer Länge mit 4 Bytes aus.

Dann würde ich dies folgendermaßen erledigen:
1
bool writeByte(unsigned char* eeprom_address, unsigned char* data)
2
{
3
   // write here data into the EEPROM
4
}
5
6
bool writeLong(unsigned long* eeprom_address, long* data)
7
{
8
   unsigned char* pAddress = (unsigned char*)eeprom_address;
9
   unsigned char* bytePtr = (unsigned char*)data;
10
11
   // write variable into EEPROM
12
   for( count=0; count<sizeof(long); count++ )
13
   {
14
      if( writeByte( pAddress, bytePtr ) == true )
15
      {
16
         pAddress++;
17
         bytePtr++;
18
19
         // ...
20
      }
21
   }
22
23
   // ...
24
}
25
26
bool readByte(unsigned char* eeprom_address, unsigned char* buffer)
27
{
28
   // read byte from EEPROM
29
   *buffer = //...
30
}
31
32
bool readLong(unsigned long* eeprom_address, long* buffer)
33
{
34
   unsigned char* pAddress = (unsigned char*)eeprom_address;
35
   unsigned char* bytePtr = (unsigned char*)buffer;
36
37
   // read variable from EEPROM
38
   for( count=0; count<sizeof(long); count++ )
39
   {
40
      if( readByte( pAddress, bytePtr ) == true )
41
      {
42
         pAddress++;
43
         bytePtr++;
44
45
         // ...
46
      }
47
   }
48
49
   // ...
50
}

Sollte ungefähr so funktionieren.

Karsten

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.