* 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"
unsigned char eeprom_readbyte(unsigned int offset)
{
- unsigned char eecon1;
// Set address.
EEADR = (offset & 0x0ff);
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 {
- Nop();
- Nop();
+#ifdef __SDCC
+ delay1ktcy(8);
+#else
+ __delay_ms(1);
+#endif
} while(EECON1bits.WR != 0);
-
- if(EECON1bits.WRERR != 0){
+ // if(EECON1bits.WRERR != 0){
// Write-Error occured.
- EECON1bits.WREN = 0;
- INTCONbits.GIE = 1;
- return 0; // Error
- }
+ // EECON1bits.WREN = 0;
+ // INTCONbits.GIE = 1;
+ // 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 b;
+
+ ClrWdt();
+
+ 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 char h,l;
+ unsigned int s;
+
+// ClrWdt();
+
+ h = readbyte_eeprom(p, sum);
+ l = readbyte_eeprom(p, sum);
+
+ s = (h << 8) | l;
+ return s;
+}
+
+
+
unsigned int calcsum_byte(unsigned int seed, unsigned char byte)
{
return seed + byte;
return 0xff;
}
+unsigned int writebyte_eeprom(unsigned int *p, unsigned int *sum, unsigned char b)
+{
+ ClrWdt();
+ 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)
+{
+// ClrWdt();
+ if(writebyte_eeprom(p, sum, word >> 8) == 0) return *p; // Error
+ if(writebyte_eeprom(p, sum, word & 0xff) == 0) return *p; // Error
+ return 0xffff;
+}
+
+
unsigned int format_eeprom(unsigned int start, unsigned int bytes)
{
unsigned int i;
// p = p + 1;
}
_CLS();
- _LOCATE(0,0);
+// _LOCATE(0,0);
return 0xffff; // Normal end
-}
\ No newline at end of file
+}