* the executable file might be covered by the GNU General Public License.
*/
+#if defined(__SDCC)
#include <sdcc-lib.h>
#include <pic18fregs.h> /* ONLY FOR PIC18x */
+#else
+#include <xc.h>
+#endif
#include <signal.h>
#include "iodef.h"
#include "ui.h"
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1;
- INTCONbits.GIE = 0; // Disable Interrupt
+// INTCONbits.GIE = 0; // Disable Interrupt
// Dummy write , needs from datasheet.
EECON2 = 0x55;
EECON2 = 0xaa;
EECON1bits.WR = 1;
do {
+#ifdef __SDCC
delay1ktcy(8);
+#else
+ __delay_ms(1);
+#endif
} while(EECON1bits.WR != 0);
// if(EECON1bits.WRERR != 0){
// Write-Error occured.
// return 0; // Error
// }
// Write OK.
- INTCONbits.GIE = 1; // Enable Interrupt
+// INTCONbits.GIE = 1; // Enable Interrupt
EECON1bits.WREN = 0;
return 0xff;
}
-unsigned char readbyte_eeprom(unsigned int p, unsigned int *sum)
+unsigned char readbyte_eeprom(unsigned int *p, unsigned int *sum)
{
unsigned char b;
ClrWdt();
- b = eeprom_readbyte(p);
+ b = eeprom_readbyte(*p);
*sum = calcsum_byte(*sum, b);
+ *p = *p + 1;
return b;
}
-unsigned int readword_eeprom(unsigned int p, unsigned int *sum)
+unsigned int readword_eeprom(unsigned int *p, unsigned int *sum)
{
unsigned char h,l;
unsigned int s;
// ClrWdt();
h = readbyte_eeprom(p, sum);
- l = readbyte_eeprom(p + 1, sum);
+ l = readbyte_eeprom(p, sum);
s = (h << 8) | l;
return s;
return 0xff;
}
-unsigned int writebyte_eeprom(unsigned int p, unsigned int *sum, unsigned char b)
+unsigned int writebyte_eeprom(unsigned int *p, unsigned int *sum, unsigned char b)
{
ClrWdt();
- if(eeprom_writebyte(p, b) == 0) return p; // Error
+ if(eeprom_writebyte(*p, b) == 0) return *p; // Error
*sum = calcsum_byte(*sum, b);
+ *p = *p + 1;
return 0xffff;
}
-unsigned int writeword_eeprom(unsigned int p, unsigned int *sum, unsigned int word)
+unsigned int writeword_eeprom(unsigned int *p, unsigned int *sum, unsigned int word)
{
// ClrWdt();
- if(writebyte_eeprom(p, sum, word >> 8) == 0) return p; // Error
- if(writebyte_eeprom(p + 1, sum, word & 0xff) == 0) return p + 1; // Error
+ if(writebyte_eeprom(p, sum, word >> 8) == 0) return *p; // Error
+ if(writebyte_eeprom(p, sum, word & 0xff) == 0) return *p; // Error
return 0xffff;
}