On Tue, 23 Nov 1999 10:57:46 -0800, Darren King wrote: >The PIC16F87x can reprogram itself... Ok, is this the lower power >programming option? >Can you give me an example of how it would be done cause that sounds like an >interesting idea. > ;Sure ... You can modify it to erase all memory, but you'll have to disable ;any interrupts before running this, otherwise when the interrupt occurs ;it will get stuck vectoring to erased program memory. ;If erasing all memory, the test at the end will not be needed because ;it will stop when it erases itself. Also, if you are erasing the ;whole memory, you will want your start address to be the first address ;after this routine. Oh, BTW, this is for a 16F877... ; ; Erase EEPROM area used for debug data from 1000h to 1FFFh BCF STATUS,RP0 ; BSF STATUS,RP1 ; Bank 2 MOVLW 0x10 ; start address MSB MOVWF EEADRH CLRF EEADR ; start address LSB CLRF EEDATA CLRF EEDATH BSF STATUS,RP0 ; Bank 3 BSF EECON1,EEPGD ; Point to PROGRAM memory LOOP: CLRWDT BSF STATUS,RP0 ; Bank 3 BSF EECON1,WREN ; Enable writes BCF INTCON,GIE ; Disable Interrupts MOVLW 0x55 ; Required Sequence MOVWF EECON2 ; Write 55h MOVLW 0xAA ; MOVWF EECON2 ; Write AAh BSF EECON1,WR ; Set WR bit to begin write ; ; ** For Rev B ES parts, replace these two NOP S with 16 lines of DATA 0x3fff NOP ; Instructions here are ignored by the ; microcontroller NOP ; Microcontroller will halt operation and wai ; a write complete. After the write ; the microcontroller continues with 3rd inst BSF INTCON,GIE ; Enable Interrupts BCF EECON1,WREN ; Disable writes BCF STATUS,RP0 ; Bank 2 INCF EEADR,F BTFSC STATUS,Z INCF EEADRH,F BTFSC EEADRH,4 GOTO LOOP BCF STATUS,RP1 ; Bank 0