pic16f877-EEPROM-Functions

by Marwen Maghrebi
void EEPROM_Write(unsigned char address, unsigned char data) {
    while(EECON1bits.WR);    // Wait for write completion
    EEADR = address;         // Set address register
    EEDATA = data;           // Set data register
    EECON1bits.EEPGD = 0;    // Point to data memory
    EECON1bits.WREN = 1;     // Enable write
    
    INTCONbits.GIE = 0;      // Disable interrupts
    EECON2 = 0x55;           // Write 55h
    EECON2 = 0xAA;           // Write AAh
    EECON1bits.WR = 1;       // Begin write operation
    INTCONbits.GIE = 1;      // Enable interrupts
    
    EECON1bits.WREN = 0;     // Disable write
}

unsigned char EEPROM_Read(unsigned char address) {
    EEADR = address;         // Set address register
    EECON1bits.EEPGD = 0;    // Point to data memory
    EECON1bits.RD = 1;       // Read EEPROM
    return EEDATA;           // Return data
}
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00