AVR Embedded Tutorial - EEPROM/de

From Lazarus wiki
Revision as of 21:36, 15 December 2017 by Mathias (talk | contribs) (Created page with "{{Translate}} =Daten in den EEPROM speichern und lesen.= ==Vorwort== Dieser Code ist für einen Atmega328/Arduino mit 16MHz. Wie man die UART ansteuert, steht hier: * AVR...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Template:Translate

Daten in den EEPROM speichern und lesen.

Vorwort

Dieser Code ist für einen Atmega328/Arduino mit 16MHz. Wie man die UART ansteuert, steht hier:

  • UART UARTInit und UARTSendString(...

Daten speichern

  procedure EEPROM_write(uiAddress: int16; ucData: byte);
  begin
    while (EECR and (1 shl EEPE)) <> 0 do begin
    end;
    EEAR := uiAddress;
    EEDR := ucData;
    EECR := EECR or (1 shl EEMPE);
    EECR := EECR or (1 shl EEPE);
  end;


Daten lesen

  function EEPROM_read(uiAddress: int16): byte;
  begin
    while (EECR and (1 shl EEPE)) <> 0 do begin
    end;
    EEAR := uiAddress;
    EECR := EECR or (1 shl EERE);
    Result := EEDR;
  end;


Beispiel

const
  sz = 'Hello World';

var
  i: integer;
  l: byte;
  s: string;

begin
  UARTInit;
  l := Length(sz);

  for i := 1 to l do begin
    //    EEPROM_write(i, byte(sz[i]));
  end;

  SetLength(s, l + 2);
  for i := 1 to l do begin
    s[i] := char(EEPROM_read(i));
  end;
  s[l + 1] := ' ';
  s[l + 2] := ' ';

  repeat
    UARTSendString(s);
  until 1 = 2;
end.


Siehe auch