Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

programming about EEPROM in PIC

Status
Not open for further replies.
Using Hi-tech c writing to internal eeprom:

Code:
#include <htc.h>
#include <stddef.h>

struct ee_map_s {
    char  sn[9];    /* Serial number string */
    long  l;
    float f;
    char  c;
};

#define EE_ADDR(member) (offsetof(struct ee_map_s, (member)))

void ee_read(unsigned char ee_addr, void *vp, unsigned char n)
{
    unsigned char *p = vp;

    while (n--) {
        *p++ = eeprom_read(ee_addr++);
    }
}

void ee_write(unsigned char ee_addr, void *vp, unsigned char n)
{
    unsigned char *p = vp;

    while (n--) {
        eeprom_write(ee_addr++, *p++);
    }
}

void main(void)
{
    float f = 1.234;
    long  l = 1234;

    ee_write(EE_ADDR(f), &f, sizeof f);
    ee_write(EE_ADDR(l), &l, sizeof l);

    ee_read(EE_ADDR(f), &f, sizeof f);

    for (;;);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top