//===EEPROM===================================================================================
void eeprom_write(int16 adresse,int8 wert)
  {
  int8 byte1,byte2;
  byte2=(int8)adresse;
  byte1=(int8)(adresse>>8);
  SPI_CS_EEPROM=1;
  SPI_WRITE(0x02);
  SPI_WRITE(byte1);
  SPI_WRITE(byte2);
  SPI_WRITE(wert);
  SPI_CS_EEPROM=0;
  delay_ms(2);
  }

int8 eeprom_read(int16 adresse)
  {
  int8 wert,byte1,byte2;
  byte2=(int8)adresse;
  byte1=(int8)(adresse>>8);
  SPI_CS_EEPROM=0;
  SPI_WRITE(0x03);
  SPI_WRITE(byte1);
  SPI_WRITE(byte2);
  wert=SPI_READ();
  SPI_CS_EEPROM=1;
  delay_ms(2);
  return wert;
  }

void init_eeprom(void)
  {
  SPI_CS_EEPROM=0;
  SPI_WRITE(0b00000110);    // Write Enable
  SPI_CS_EEPROM=1;
  delay_ms(40);

  SPI_CS_EEPROM=0;
  SPI_WRITE(0b00000001);
  SPI_WRITE(0b00000010);    // Write Status Register
  SPI_CS_EEPROM=1;
  delay_ms(2);
  }


//===Hauptprogramm============================================================================
  adresse=0x0333; //max. 0x03FF !
  wert_out=0x55;

  lcd_curs(cursor_off);
  lcd_putc("\fEEPROM-Test:\n");      // \f=desplay löschen! \n=auf 2.zeile
  printf(lcd_putc,"Adresse: %4LX",adresse);
while(1)
  {
  eeprom_write(adresse,wert_out);
  delay_ms(100);
  wert=eeprom_read(adresse);
  printf(lcd_putc,"\mWert: %2X",wert);   // \m=auf 3.zeile
  delay_ms(1000);
  }