Jump to content

jevdsnny

EstablishedMember
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

0 Neutral

About jevdsnny

  • Rank
    Newbrie
  1. The timing in the "bad" code if different than in "god" code and this could make it fail 100% of the times. There may be something elso too but not likely related to the compiler. Regards, Pavel <{POST_SNAPBACK}> take a look at the code- its exactly the same...i would agree if the code were different, but its not. the contents of the two procedures are identical. the calls are identical. the only thing that differs is the order of the declaration of the procedures. there is no way the timing can be different. even so, timing doesnt have much to do with it. interrupts are disabled. the circuit is just an RC clock and reset tied to VDD. nothing else. all it does is write a byte, call the delay loop and then enter an infinite loop. it seems that you are concluding that the compiler is not at fault without tryintg to diagnose the problem, so i am not going to chase the issue any more. ive already spent 3 days debugging this thing and its not working so im just going back to mplab and assembly because i dont have any more time to spend on it.
  2. I dont see how it could be a timing issue- it is 100% repeatable; I've tested it at least 20 times over the past three days on each scenario- the "good" one always writes the byte and the "bad" one always doesn't- that would be a huge coincidence.
  3. Just like the post says- when you run the "good" program, it writes a byte to the EEPROM data, when you run the "bad" program, it doesnt write a byte to the EEPROM data, even though they are the exact same code with just the declarations switched.
  4. According to the debugger both work fine.
  5. The only different between the two programs is the declaration location of the two functions. In the "good" program, the order is: DebounceDelay SaveSettings Main In the "bad" program, the order is: SaveSettings DebounceDelay Main There are no other differences in the code. The code in each of the programs is identical except for the order of declaring the functions.
  6. Two programs, both with the exact same functions and variables, just one declaration moved between the two. One works, one doesn't...100% repeatable...try it for yourself! Target is a 16F84A with JDM and IC-Prog. The one that works writes a byte to the EEPROM, the one that doesnt, doesnt. I'm gonna wade thru the hex code to see if I can figure it out, but that doesn't help much... ==========good program========== #include <system.h> char i; char j; char a; void DebounceDelay() { for ( j = 0; j < 100; j ++ ) for ( i = 0; i < 100; i++ ) a = 0; } char Addr; char Data; //save the current setting to EEPROM void SaveSetting () { char WriteInProgress; //wait for any prior writes to complete //very unlikely in this particular application WriteInProgress = eecon1; while (WriteInProgress & WR) WriteInProgress = eecon1; eeadr = Addr; eedata = Data; set_bit ( eecon1, WREN ); //enable writes clear_bit (intcon, GIE); //disable any interrupts eecon2 = 0x55; //magic sequence for writing eecon2 = 0xAA; set_bit ( eecon1, WR ); //do the write clear_bit ( eecon1, WREN ); //disable writes } void main() { Addr = 0; Data = 10; SaveSetting ( ); DebounceDelay(); } ============================= ==========bad program========== #include <system.h> char Addr; char Data; //save the current setting to EEPROM void SaveSetting () { char WriteInProgress; //wait for any prior writes to complete //very unlikely in this particular application WriteInProgress = eecon1; while (WriteInProgress & WR) WriteInProgress = eecon1; eeadr = Addr; eedata = Data; set_bit ( eecon1, WREN ); //enable writes clear_bit (intcon, GIE); //disable any interrupts eecon2 = 0x55; //magic sequence for writing eecon2 = 0xAA; set_bit ( eecon1, WR ); //do the write clear_bit ( eecon1, WREN ); //disable writes } char i; char j; char a; void DebounceDelay() { for ( j = 0; j < 100; j ++ ) for ( i = 0; i < 100; i++ ) a = 0; } void main() { Addr = 0; Data = 10; SaveSetting ( ); DebounceDelay(); } ============================
×
×
  • Create New...