diff --git a/pic/MDR/MDR.c b/pic/MDR/MDR.c index 3c04e30..d362e2c 100644 --- a/pic/MDR/MDR.c +++ b/pic/MDR/MDR.c @@ -233,27 +233,28 @@ void save_code() void clear_memory(void) { uint16_t address; - uint8_t stored[3]; - /* start at begining of the memory */ - send_start(); - if (send_byte(0xa0)) { /* write address to eeprom at 0xA0/0x50 */ - send_stop(); - return; - } - if (send_byte(0x00)) { /* go to address 0x0000 */ - send_stop(); - return; - } - if (send_byte(0x00)) { /* go to address 0x0000 */ - send_stop(); - return; - } /* go through memory */ for (address=0; address<0x7FFF; address++) { + if ((address%0x40)==0) { /* select page */ + send_start(); /* start transaction */ + if (send_byte(0xa0)) { /* write address to eeprom at 0xA0/0x50 */ + send_stop(); + return; + } + if (send_byte(address>>8)) { /* go to address */ + send_stop(); + return; + } + if (send_byte(address&0xff)) { /* go to address */ + send_stop(); + return; + } + } send_byte(0x00); /* clear byte */ + if ((address%0x40)==0x3f) { /* end of page */ + send_stop(); /* finish transaction */ + } } - send_stop(); /* finish transaction */ - } /* funcion called on interrupts */