123456789101112131415161718192021222324252627282930313233343536373839 |
- void ee_write_byte(unsigned char address, unsigned char _data){
- EEDATA = _data;
- EEADR = address;
-
- EECON1bits.EEPGD = 0;
- EECON1bits.CFGS = 0;
- EECON1bits.WREN = 1;
- INTCONbits.GIEH = 0;
-
- EECON2 = 0x55;
- EECON2 = 0x0AA;
- EECON1bits.WR = 1;
- while(EECON1bits.WR){
- _asm nop _endasm;}
- if(EECON1bits.WRERR){
- printf("ERROR: writing to EEPROM failed!\n");
- }
- EECON1bits.WREN = 0;
- INTCONbits.GIEH = 1;
-
- }
- unsigned char ee_read_byte(unsigned char address){
- EEADR = address;
- EECON1bits.CFGS = 0;
- EECON1bits.EEPGD = 0;
- EECON1bits.RD = 1;
- return EEDATA;
- }
|