ATmega128 и EEPROM (+)Читать получается стабилно а вот писать как-то хоатично неправильные данные лезут.Где грабли ?
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено UserAvr 21 апреля 2005 г. 18:19


#include "stdafx.h"
#include "eeprom.h"

unsigned char EEPROM_read( unsigned int location)
{
EEAR = location;

EECR |= 0x01; // Set READ strobe
#if defined(_MSC_VER)
EEDR=__BASE_E2[location];
#endif
return (EEDR); // Return byte
}

void EEPROM_ReadBytes( void *ptr,unsigned int addr,int size)
{
char *dst = ptr;

while (size--)
{
*dst = EEPROM_read(addr);
addr++;
dst++;
}
}

int EEPROM_write( unsigned int location, unsigned char byte)
{
unsigned char oldSREG;

EEAR = location;
#if defined(_MSC_VER)
__BASE_E2[location]=byte;
#endif

EEDR = byte;

oldSREG = SREG;
SREG &= ~0x80; // disable interrupt

EECR |= 0x04; // Set MASTER WRITE enable
EECR |= 0x02; // Set WRITE strobe

while (EECR & 0x02)
#if defined(_MSC_VER)
EECR &= ~(0x02)
#endif
; // Wait until write is done

SREG = oldSREG;
return 0; // return Success.
// Could be expanded so that
// the routine checks that the address
// is within the range of the chip.
}

void EEPROM_WriteBytes( void *ptr,unsigned int addr, int size)
{
char *src = ptr;

while (size--)
{
EEPROM_write(addr, *src);
addr++;
src++;
}
}

 

Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru