Picdude wrote: >Hi all, > >In a PIC16F627 application I recently developed, I am having a code-hang >problem. My best diagnosis so far, is that the code is getting stuck in the >EEPROM write routine [code posted at the end of this email] which is called >from a main code loop. Interrupt processing seems to be working fine still, >even though this main loop is locked up. > >In the write routine, I'm waiting on the EEIF flag to be set, indicating that >the write operation is complete, but I'm guessing that this is where it's >getting stuck. > >The EEPROM writes happen in groups of 5 (all calling this routine), and I'm >not verifying that the write operation was successful by checking the actual >value saved (at least, not yet). I'm also not using a watchdog timer yet. >The 2 other interrupts are TMR0 which updates the multiplexed display, and >TMR2 which checks for and processes an external signal. > >Any idea what could be going wrong here? > > Here's some working EE code on a '628. ;******************************************************************** ;* eeprom interrupt handler * ;******************************************************************** int_ee: ; bcf eeif ;clear the interrupt that called us bcf ee_busy ;clear our eeprom busy flag bank1 ;bank 1 bcf wren ;disable eeprom writes bank0 ;bank 0 goto exit_int ; ;******************************************************************** ;* 'ee_write' writes one byte. * ;* enter with eeprom address in w and eeprom data in ee_temp. * ;******************************************************************** ee_write: ; btfsc ee_busy ;is the eeprom busy from a previous write? goto ee_write ;yes, loop & wait bcf gie ;no, disable the global interupt bank1 ;bank 1 movwf eeadr ;set up eeprom address movf ee_temp,w ;get data for eeprom saved in calling routine movwf eedata ;set eeprom data bsf wren ;enable eeprom writing movlw h'55' ; movwf eecon2 ;eeprom write unlock sequence movlw h'aa' ; movwf eecon2 ;eeprom write unlock sequence bsf wr ;initiate data eeprom write bank0 ;bank 0 bsf ee_busy ;set flag to say eeprom is busy bsf gie ;re-enable the global interupt return ;exit ;******************************************************************** I do the first write, then exit back to the main loop right away to deal with other tasks. Checking the eeprom busy state at the start of the eeprom write is a more efficient way to do it. Clearing the write enable during writing *may* be causing your problem. I wait until the write is finished and that works. David... -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body