Nesse exemplo mostro como utilizar a EEPROM Interna ao microcontrolador fazendo o acesso direto nos registradores.

Segue o código:

[sections] [section title=”Código Fonte”]

unsigned char EEPROM_Read(unsigned char address)
{
EEADR=address;
EECON1.EEPGD= 0; // 0 = Access data EEPROM memory
EECON1.CFGS = 0; // 0 = Access Flash program or DATA EEPROM memory
EECON1.RD = 1; // EEPROM Read
return EEDATA; // return data
}

void EEPROM_Write(unsigned char address,unsigned char value)
{
unsigned char INTCON_SAVE;
EEADR = address;
EEDATA = value;

EECON1.EEPGD= 0; // 0 = Access data EEPROM memory
EECON1.CFGS = 0; // 0 = Access Flash program or DATA EEPROM memory
EECON1.WREN = 1; // enable writes to internal EEPROM

INTCON_SAVE=INTCON; // Save INTCON register contants
INTCON=0; // Disable interrupts, Next two lines SHOULD run without interrupts

EECON2=0x55; // Required sequence for write to internal EEPROM
EECON2=0xaa; // Required sequence for write to internal EEPROM

EECON1.WR=1; // begin write to internal EEPROM
INTCON=INTCON_SAVE; //Now we can safely enable interrupts if previously used

while (PIR2.EEIF==0); //Wait till write operation complete

EECON1.WREN=0; // Disable writes to EEPROM on write complete (EEIF flag on set PIR2 )
PIR2.EEIF=0; //Clear EEPROM write complete flag. (must be cleared in software. So we do it here)
}

[/section] [/sections]
Obrigado e até o próximo post.

DATEK Tecnologia Eletrônica
[PIC][MIKROC] Gravação da EEPROM Interna acessando registradores
Tags:                     

Deixe uma resposta

%d blogueiros gostam disto: