From 1f05f5a8b8ab840c8ddd7de046ce9d3bd6b8bf26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 2 Aug 2014 15:07:35 -0700 Subject: [PATCH] implemented clear_memory() --- pic/MDR/MDR.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) 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 */