[Opps! I forgot to put the [PIC]: at the start of the subject line when I first sent this. Sorry!] I am having trouble writing to the EEPROM in a on 16F873. Using the "RomZAP Bootloader III" I put in the following code to read a value from an analog input, then display the value on some LEDs and store the value in EEPROM. The program does all this except it only does it once - ie it doesn't go around the LOOP. It seems to hang on the last instruction before "goto LOOP". NOTE: if I remove all the code from EWRITE onwards the LOOP works perfectly. NOTE2: the code after EWRITE routine is more or less straight out of the 16F87x datasheet, except I have modified it so it just writes the value which is in W to EEPROM address 0x00. Also, I have not enable interrupts so I have commented out the relevant bits as required. (I will more EWRITE out to be a subroutine, but I have put it in the main loop for now in order to just get it going...) Any suggestions greatly appreciated! John org 0x0003 bsf STATUS,RP0 ; select register bank 1 bcf STATUS,RP1 ; movlw H'00' movwf TRISC ; set PORTC [7-0] all outputs clrf ADCON1 ; set PORTA [7-0) all analogue inputs bcf STATUS, RP0 ; select register bank 0 movlw B'01000001' ; bits [7-6] = select Fosc/8; bits [5-3] select analogue input from RA0/AN0 movwf ADCON0 ; bit [0] = activate A2D converter LOOP bsf ADCON0,GO ; start A2D conversion Adwait nop ; wait for conversion to complete btfsc ADCON0,GO ; goto Adwait ; movf ADRESH,W MOVWF PORTC EWRITE bsf STATUS, RP1 bsf STATUS, RP0 ; select register bank 3 Ewait btfsc EECON1, WR ; wait for any previous write_ goto $-1 ; to finish bcf STATUS, RP0 ; select register bank 2 ; movf VALUE, W ; set EEDATA to value you want to write_ movwf EEDATA ; to EEPROM ; movf ADDR, W ; set EEADR to the EEPROM address_ movlw 0x00 movwf EEADR ; that you want to write to bsf STATUS, RP0 ; select register bank 3 bcf EECON1, EEPGD ; Point to data memory bsf EECON1, WREN ; Enable writes ; bcf INTCON, GIE ; Only disable interrupts if already enabled_ ; ; otherwise discard movlw 0x55 ; Write 55h to_ movwf EECON2 ; EECON2 movlw 0xAA ; Write AAh to_ movwf EECON2 ; EECON2 bsf EECON1, WR ; Start write operation ; bsf INTCON, GIE ; Only disable interrupts if already enabled_ ; ; otherwise discard bcf EECON1, WREN ; Disable writes goto LOOP _______________________________________________________________________ John Brown PhD (Clinical Psychology) candidate Email: john.brown@anu.edu.au School of Psychology Phone: (02) 6125-3827 Room 124, Building 39, Psychology Fax: (02) 6125-0499 The Australian National University Mobile: 0429 455 504 ACTON ACT 0200 Web: http://www.anu.edu.au/psychology/staff/BrownJ.htm -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu