/*------------------------------------------------ Function for memory write ------------------------------------------------*/ void EeWrite() { temp_prog = PROG_NO - 0X30; WMCON |= EEMEN_; WMCON |= EEMWE_; program[temp_prog].e_total_turns = prog.total_turns; program[temp_prog].e_stop1_turns = prog.stop1_turns; // same copying code here... for( i=0; i < 2500; i++ ) { if( WMCON & EERDY_ ) break; } WMCON &= ~EEMEN_; // EEMEN=1; WMCON &= ~EEMWE_; // EEMWE_=1; }
/*------------------------------------------------ Function for memory read ------------------------------------------------*/ void EeRead() { temp_prog = PROG_NO - 0X30 WMCON |= EEMEN_; // EEMEN=1; prog.total_turns = program[temp_prog].e_total_turns; prog.stop1_turns = program[temp_prog].e_stop1_turns; prog.trvs = program[temp_prog].e_trvs; prog.offset = program[temp_prog].e_offset; prog.index = program[temp_prog].e_index; prog.stop2_turns= program[temp_prog].e_stop2_turns; prog.dir = program[temp_prog].e_dir; WMCON &= ~EEMEN_; // EEMEN=1; }
This is one more observation that when I compile my code in Keil, it omits some of my Instructions It sounds strange, but is true. When after compiling I start debugging, it wont show the breakpoint at some positions. It won't execute that instruction too! The Keil compiler is an optimizing compiler. That means, it optimizes your program and may move stuff around and combine things that you didn't think about. This is how all optimizing compilers work. You should probably take a look at the following knowledgebase article: http://www.keil.com/support/docs/2467.htm. Jon
"Now what should be my approach? beacuse if I will go for byte by byte write then the code size will be too big." Use a pointer in a loop to copy the structure(s) byte by byte. You need to map in the EEPROM, wait for the ready bit, write a byte, wait for the ready bit etc. To read, all you need to do is map in the EEPROM, wait for the ready bit then do a structure assignment. This is based on being familiar with a similar but not identical Atmel part so check the datasheet for precise information.