From 9f35b7a8ef84d7c96ce444e0081d9644f8da6c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 2 Aug 2014 16:10:04 -0700 Subject: [PATCH] dump codes when booting --- pic/MDR/MDR.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pic/MDR/MDR.c b/pic/MDR/MDR.c index dbbc75e..74c9b81 100644 --- a/pic/MDR/MDR.c +++ b/pic/MDR/MDR.c @@ -266,6 +266,45 @@ void clear_memory(void) } } +/* read all codes from memory */ +void dump_codes(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; + } + /* start reading */ + send_start(); + if (send_byte(0xa1)) { /* read eeprom at 0xA0/0x50 */ + send_stop(); + return; + } + /* go through memory */ + for (address=0; address<0x7FFF-2; address+=3) { + /* read stored code */ + stored[0] = read_byte(1); + stored[1] = read_byte(1); + stored[2] = read_byte(1); + if ((stored[0]&0x80)==0) { /* code always have the MSb to 1 */ + read_byte(0); /* send nack */ + send_stop(); /* end transaction */ + return; /* all codes have been read */ + } + } +} + /* funcion called on interrupts */ /* interrupt 0 is only one on PIC16 */ static void interrupt(void) __interrupt 0 @@ -308,6 +347,7 @@ void main (void) uint16_t new = 0; /* is the code new */ init(); /* configure micro-controller */ + dump_codes(); /* dump codes when powering up so a logic analyzer can get them */ while (1) { /* a microcontroller runs forever */ /* I can't go to sleep to safe power